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

Re: not enough real programmers?



On Thu, 12 Aug 1999 23:36:49 GMT, in
<37b33ae8.15667869@news.pandora.be> lucvdv@null.net (Luc Van der
Veken) wrote:

[much snipped]

>>.  I would have done
>> 	if (src[i])
>> 		dest[j++] = src[i];
>> which would be *much* more informative.  Also note that indentation can help
>> you make your intent clear here.
>
>Superfluously breaking up lines (what you demonstrate here IMO)
>actually makes the code less readable.

I agree with Peter; I think you're wrong to call this a superfluous
break.

>It's exactly to avoid reading errors that I try never to split
>single conditional statements up over two lines.

I used to do that myself years ago, but I've come to the exact
opposite conclusion over time.

>  Indentation, in
>my sources, means either that it's a new code block (like the
>body of a loop or multiple statements in an 'if' body), or that
>it's a continuation of a long statement (if, and only if, it
>won't fit on one line - but as I said, I normally try keep my
>lines short).
>
>This whole thing is best described in words as a single "if it
>ain't zero, copy it" - so I deliberately try to keep it on a
>single line.

I'd say that's /two/ concepts: condition, action; and therefore makes
sense split into two lines.

Besides, it makes it a hell of a lot easier to debug, as few if any
source debuggers (certainly none that I've ever used) will let you put
a breakpoint in the middle of a line.

Of course, maybe your programs never have bugs, or maybe you do your
debugging at instruction level, but I find these two arguments pretty
convincing.

>See above for my feelings about mid-code declarations.
>IMO, only sloppy programmers (who forgot that they would need
>them when they were declaring variables, and are too lazy to move
>the cursor back up) use them.

There's a school of thought that says variables should not be declared
without initialisation, and that's often impossible to do in a single
group at the beginning of a block. 

>  A "for" statement is burdened
>enough with the elements it needs of its own - adding a
>declaration only makes it less readable.

Very often a loop index is of no significance outside the loop -
sometimes not even inside it! - and declaring it with outer scope is
IMO logically poorer design.

[Aside: one of the few things I've always felt would be a useful
extension to C/C++ is a statement 'for (count)', which would be the
functional equivalent of 'for (i =0; i < count; ++i)' but without an
explicit variable. Modern compilers can optimise out an unused loop
counter, but that wasn't necessarily the case some years back.]

>I often notice that a large part of my C++ code would compile on
>a C compiler (if it understands C++ style comments, like most do
>nowadays), but maybe that's only because I was already
>programming in C before C++ appeared on the scene.

Then you're not IMO taking full advantage of C++.

>Today I prefer to use C++ BTW, also when C would do nicely,
>mainly for its strict type checking - so that's what I was doing
>here too.

Of course, this is the main reason why C++ has become so popular -
that it can be used as no more than an enhanced C.


--
Steve Rencontre, Design Consultant
http://www.rsn-tech.demon.co.uk/  --  remember to despam return address