Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize constructor parameter names #1427

Merged
merged 2 commits into from
Mar 12, 2024
Merged

Normalize constructor parameter names #1427

merged 2 commits into from
Mar 12, 2024

Commits on Mar 11, 2024

  1. Normalize constructor parameter names

    In order to avoid confusion between constructor parameter names and
    member variables, we either used alternate names for the parameters or
    prefixed the parameter names with an underscore. For example:
    
        class foo {
          public:
            foo(int _i, bool semaphore, short bar) : i(_i), flag(semaphore)
            {
                baz = bar;
            }
           private:
             int i;
             bool flag;
             short baz;
        };
    
    However, this is unnecessary. Constructor initializer lists are
    unambiguous, as the assigned item always refers to the class member, and
    the assigned value is always from the parameter (unless prefixed with
    "this->").
    
    Inside the constructor body, parameter names override member variables,
    and "this->" can be used to indicate the class member in the case of
    name collision.
    
    Thus, the above code can be rewritten as this:
    
        class foo {
          public:
            foo(int i, bool flag, short baz) : i(i), flag(flag)
            {
                this->baz = baz;
            }
           private:
             int i;
             bool flag;
             short baz;
        };
    
    I've taken advantage of this to clarify names used in constructors
    throughout the codebase. Mostly for constructor parameter names,
    sometimes for member variable names.
    hollasch committed Mar 11, 2024
    Configuration menu
    Copy the full SHA
    30f76aa View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    18973c5 View commit details
    Browse the repository at this point in the history