
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tlug] Bleeding pragmata
On 17/02/06, Tod McQuillin <devin@example.com> wrote:
>>> The C99 standard allows variable declarations anywhere inside
>>> a block, not just at the top. This can be a useful technique
>>> for limiting the scope of variables to just the section of
>>> code where they are used.
Saves two characters: '{' and '}'. Big whup. ;-) Of course,
according to your coding style you may need to add a bunch of extra
whitespace, but for me this is usually balanced by the readability
advantage of demarcating the scope of the declaration, and the fact
that there's an explicit end-of-scope indicator (which is often more
important to me than the beginning-of-scope indicator).
>>>>> "Edward" == Edward Middleton <edward@example.com> writes:
Edward> Josh Glover wrote:
>> Thanks for pointing this out.
Edward> Well if you hadn't send the last email you might of got
Edward> away with something along the lies of
Edward> [1]It's a coding style issue. We put our variable
Edward> declarations where people can _find_ them, not in random
Edward> places in the code.
I'll second that. XEmacs still compiles with GCC 2.4 (although that's
an accident, we only *want* to support 2.95 :-). And there are vendor
compilers that don't support C99 yet, although they're getting quite
rare.
Edward> Putting variables in the middle of code only improves
Edward> readability when you have messy code.
IMO, there's an important exception. It also allows you to initialize
at the point of declaration. That can be a perceptible readability
improvement if your initialization depends on an intermediate result.
Granted, you might be even better off putting the block in a function
and letting the compiler inline it, but for inner loop code you might
not want to do that, especially if you need to support a lot of
compilers and don't know what their policies on inlining are (or know
that some compilers won't inline the code in question). Or the block
might use a lot of variables that you'd have to pass as arguments, or
something.
--
School of Systems and Information Engineering http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Ask not how you can "do" free software business;
ask what your business can "do for" free software.
Home |
Main Index |
Thread Index