[Swan-dev] Add -std=c99 to the compiler flags?
D. Hugh Redelmeier
hugh at mimosa.com
Thu Feb 5 21:46:55 EET 2015
| From: Lennart Sorensen <lsorense at csclub.uwaterloo.ca>
| On Thu, Feb 05, 2015 at 01:13:49AM -0500, D. Hugh Redelmeier wrote:
| > Really? Seems like a no-brainer if you accept the goal of minimizing
| > undefined variable errors.
| I agree, but I have heard people argue that all variables should be
| declared first. Probably just old fashioned C coders.
Readability is very important. The reader and the writer of code have to
follow conventions: "all that's legal" C can be very hard to read
There is no single obviously best style (except for mine). Following
any single OK style is a win.
At the moment, Pluto has (almost) all its block scope
declarations at the start of the block, segregated from statements by
a blank line. That makes it fairly easy to find a declaration: look
to the start of each enclosing block.
Using this "new" capability of mixing declarations and statements can
make this search a little more difficult.
On the other hand, understanding the data-flow and control flow
involving a variable is improved if the scope is shrunk and also if
there is no point in which the variable is uninitialized.
- an initializing declaration is preferred to a non-initializing one
(but don't initialize to a value that will never be used)
- put the declarations in such a way as to minimize scope
- if the lifetime of a variable can be partitioned in such a way that
the value doesn't carry between partitions, break that into multiple
variables, one per partition
Declaring the index variable within the for statement looks like a
very good application of these principles
I wonder if there are good ways of making declarations visually stand
out. Perhaps it is a non-problem, but surely it is the point of the
other side of this argument.
| I love when the compiler spots errors at compile time.
Unfortunately it sometimes takes a guru to understand what a C
compiler is complaining about with type mismatches. Still, I think
that is learning curve worth climbing.
I guess it takes even more expertise (and good taste) to create these
types. Of course that's part of what I find rewarding about
programming: the quest for elegance.
More information about the Swan-dev