bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"const" scalars


From: Jim Meyering
Subject: "const" scalars
Date: Mon, 12 Apr 2010 09:00:02 +0200

Paul Eggert wrote:
> I agree with Bruno on this point.  It's hard enough to read C code
> without having to wade through all those 'const's on local variables.

Hi Paul,

By "local variables" you must mean "local scalar variables".
You wouldn't argue for dropping "const" as a pointer attribute.

> The tiny extra benefit that they provide is not worth the overhead on
> people trying to read the code.  What's next?  Should we also add
> 'const' to parameter declarations?  (And if not, why not?)
>
> All other things being equal, we should be encouraging a functional
> style in which most local variables and parameters are never modified
> once set.  Requiring or encouraging programmers to add these 'const's
> works against this goal, and makes code harder to read and maintain.

I'm not in the habit of using "const" on scalars.
Inserting the "const" on each line before the "bool"
in that example did make me think twice: putting it
before the type makes the type name less apparent,
and putting it after the name cannot be justified
like it can for a pointer.  It wasn't terribly fulfilling,
but that function is so small I'm not convinced it's
even worth the trouble of reverting the change.

In any case, don't worry: I'm not about to add "const"
to all scalar declarations.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]