problems/risks due to programming language, stories requested
Jim Miller
jamiller at hpcupt1.HP.COM
Thu Mar 15 04:52:22 AEST 1990
>>
>>See how I left out the breaks on purpose.
>
>Cross you heart, how often in practical programming do you
>write such code? And how often compared to normal switch
>statements where an easily elided break would introduce
>a simple bug? It might be that I never program in C, but I
>have never felt the need for a fall-through. Also, it seem more
I have often written such code, in several different languages.
I implement some sort of "continue" statement.
case (i) of begin
1: ...
2: ...
goto continue2;
3:
continue2: ...
4: ...
...
Now I don't frequently do this, and as compared to the normal "break"
case it is very small. However it IS a useful construct.
Here is my $.02 on the subject of: a few of my favorite C "flaws".
1) The here-to-for & often mentioned break in the switch statement.
A language that has "x++" so that a programmer will not make a mistake
writing "x=x+1" is inconsistent is having a situation where he/she/it
must have a separate statement for the normal coding practice.
IF I were to get into my time machine, I'd try to get C changed to
implement a switch "continue" construct instead of the switch's "break".
Right now I think it better be left alone, any fix that I can see would
intail an imposible and or ugly transition.
2) "==" for logical equal compare.
I don't like it because *I* make the mistake of "=" instead of
"==" often in "if" conditions. Also I find it difficult to find
such mistakes because I also intentionally use "=" in "if" conditions.
(One personal solution is to stop using "=" in conditions.)
I don't know what I'd replace it by because I haven't found
any alternative that I like -- and I've seen quite a few. The closest
to my personal liking is using ":=" instead of "=" for assignment. All
those opposed to typing two characters instead of one should agree with
my above "continue" position -- but I bet they won't.
"==" v.s. "=" is *my* greatest single typing error (as opposed to
logical or coding error) that I make which does not get caught by the
compiler and/or lint. Yes I know that | v.s. || and & v.s. && have the
same "problem". It's just that I personally don't have the same
problem. I think it is because "|" and "&" don't get used with the
frequency of "=". I double check my use of both the single and the
double usages whenever there is a hint of a problem. I also tend to
double check them when I first type them. But double checking each
"=" is not in me.
jim - it's only my opinion so of course it's TRUTH - miller
More information about the Comp.lang.c
mailing list