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

code style: guideline for const parameters #161

Merged
merged 2 commits into from
Aug 28, 2018

Conversation

justinmk
Copy link
Member

@justinmk justinmk commented Aug 4, 2018

Clarify project guideline on use of const for non-pointer parameters.

ref: neovim/neovim#8684 (comment)
ref: neovim/neovim#8142 (comment)

@justinmk
Copy link
Member Author

justinmk commented Aug 4, 2018

cc @bfredl @janlazo @aktau @ZyX-I

@bfredl
Copy link
Member

bfredl commented Aug 4, 2018

I agree, non-target const just trivially repeats local information, unlike const target which actually changes the invariants between the caller and the callee.

@bfredl
Copy link
Member

bfredl commented Aug 4, 2018

Perhaps include a bad example of const pointer to non-const target as well (int *const ptr)

@janlazo
Copy link

janlazo commented Aug 5, 2018

What's the alternative? Create a new local variable at the top of the function to avoid modifying the parameter even if Vim source doesn't have this variable? If it's about the API (ie. src/nvim/api/) and its doxygen documentation, then it's preferable to avoid changes to the function signature.

Is the issue on parameter style on function declaration? I don't like the second style; either the function declaration fits in one line or each parameter gets its own line, making it easier to add/remove const.

int foo(const int a, const int b,
        const int c)

@justinmk
Copy link
Member Author

justinmk commented Aug 5, 2018

The link is https://neovim.io/develop/style-guide.xml#Use_of_const .

If it's about the API (ie. src/nvim/api/) and its doxygen documentation, then it's preferable to avoid changes to the function signature.

The main goals of this recommendation are to avoid verbosity/clutter where it isn't serving a strong purpose. aktau's comment in neovim/neovim#8142 (comment) may help.

@justinmk justinmk merged commit 7be857e into neovim:master Aug 28, 2018
@justinmk justinmk deleted the style-const-param branch August 28, 2018 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants