Skip to content

Remove superfluous const parameters from function declarations #105

Closed

Description

@JuanDiegoMontoya

For non-reference, non-pointer function prototype parameters, const is superfluous and has no effect. It only serves to clutter the API and does not provide any guarantee to the caller. See this SO answer for more info.

Suggestion: remove const from non-reference, non-pointer-like parameters in function declarations, and keep them in function definitions to maintain const-correctness where it matters, for example:

class DearImGuiApplication final : public Application
{
public:
    ...
    void OnResize(
        int32_t width,
        int32_t height) override;
    ...
};

void DearImGuiApplication::OnResize(
    const int32_t width,
    const int32_t height)
{
    ...
}

The other place I have noticed this issue is with the std::string_view parameter of Application's (and its derivatives') constructor.

Activity

  1. deccer commented on Mar 29, 2022

    @deccer
    Contributor

    As discussed in discord.
    I would like to keep const in hpp/cpp to be consistent. Or does it absolutely not make sense at all (i am not really convinced by the attached SO, as in it shows intent, and doesnt really "pollute" anything)?

  2. locked and limited conversation to collaborators on Mar 29, 2022
  3. converted this issue into a discussion #106 on Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions