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

Usage of const variables #27

Open
marbre opened this issue Jul 26, 2018 · 2 comments
Open

Usage of const variables #27

marbre opened this issue Jul 26, 2018 · 2 comments

Comments

@marbre
Copy link
Contributor

marbre commented Jul 26, 2018

There are several functions, where variables are declared, assigned a few lines later and not reassigned later on. E.g. the variable eps_t in refine_roots_newton:

    REAL re_bound_val, im_bound_val, eps_t;
    UINT trunc_index;
    trunc_index = D;
    eps_t = (T[1] - T[0])/(D - 1);

Does it respect your style if refactored as follows?

    REAL re_bound_val, im_bound_val;
    UINT trunc_index;
    trunc_index = D;
    const REAL eps_t = (T[1] - T[0])/(D - 1);
@wahls
Copy link
Contributor

wahls commented Jul 26, 2018

Yes, const-correctness is considered good practice.

It is also fine if the variable is declared where it is needed (instead of in the beginning).

@marbre
Copy link
Contributor Author

marbre commented Aug 6, 2018

Yeah, that was actually the question if the assignment should either move up to where the variables are declared or if the declaration might move down (keeping the position of the assignment untouched). A PR will follow shortly if all tests pass on my machine.

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

No branches or pull requests

2 participants