Philippe Lhoste wrote:
PS.: I also changed some "const int param" to "int param" in functions
definition parameters. Since these are not references, it doesn't seem
useful to declare them as const. Even if param is changed, it is only a
local change... But I can be wrong, of course.
(Neil said:)
I don't feel either way is greatly better. Using const allows some
more checking and sometimes makes it easier to reason about code,
which I like sometimes with variables that are about to be used in
some complex flow of control although that isn't the case with
parameters. I haven't modified these previously as code churn creates
bugs.
Well, in the above case, that's not complex flow, just two to five
lines, but I don't mind either way. The only thing annoying me is that
there is no real consistency from one lexer to the next, but I suppose
that's the drawback of open source...
I have been trying to consistently use "const" whenever possible for
some years now, because it has the advantages cited by Neil, as well
as enabling some [possible] compiler code-gen optimizations... but I
had never considered applying it to "value" parameters! :)
If we *are* talking about either
int f(int a)
OR
int f(const int a)
then "a" is definitely a value, and anything done to it can NOT change
any variable (or intermediate value) at the call site (because those
are the semantics of the language)... so yes, in a trivial function, I
will sometimes use a [non-const] value param as if it were a
conveniently initialized temp variable.
I suppose one *could* add a const qualifier to a formal parameter and
reap some of the same possible benefits as with a local var - but it
still looks weird to me. :)
On one of the OCaml (which is a "Functional Programming" language)
lists, it was recently pointed out that using const in C/C++ is an
"FP-like" coding style...
Robert Roessler
[EMAIL PROTECTED]
http://www.rftp.com
_______________________________________________
Scintilla-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scintilla-interest