Sujet : Re: Official list of top C annoyances
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 09. Sep 2026, 23:13:08
Autres entêtes
Organisation : None to speak of
Message-ID : <117sllk$1g635$2@kst.eternal-september.org>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Gnus/5.13 (Gnus v5.13)
Lane W <
cactus_DAC@yahoo.com> writes:
David Brown wrote:
[...]
C's include system works well when used in a sensible and
disciplined manner, but unfortunately not all C programmers are
sensible and disciplined.
Agreed. Plus some C programmers use the switch keyword, which we all
agree is BAD BAD BAD, right Janis and Keith?
No, of course not.
David Brown already covered most of the points I was going to make,
and I agree with what he wrote in this subthread.
I initially ignored your code because it was in a thread I wasn't
particularly interested in. I later decided to review it because
it was brought to my attention.
If you think I dislike the switch statement, you've reached a
completely incorrect and unjustified conclusion.
I dislike the particular code snippet that you posted, code
that happened to use a switch statement (inappropriately IMHO).
There are plenty of valid uses for switch statements, and I don't
hesitate to use it when it's appropriate. It seemed to me that you
artificially added a layer of complexity so you could use a switch
statement rather than an if/else chain -- and to set that up, you
used a sequence of if statements (with no "else" for some reason).
My criticism of your code has nothing to do with the fact that you
wrote it. To be blunt, I don't care enough about you personally to
go out of my way to nitpick your code. I would have had similar
criticisms if the code had been posted by the late Dennis Ritchie
or by Brian Kernighan, though I would have been more reticent in
expressing my opinions.
The idea behind your code is not necessarily a bad one.
You transformed a floating-point input value partitioned into
ranges into a discrete value, with one discrete value corresponding
to each range. That can be a useful technique. For one thing,
it's an opportunity to give a meaningful name to each input range
(but you just used 1, 2, 3). In some cases, it might allow fewer
floating-point operations to be performed before making a decision,
which could be significant in performance-critical code.
But your specific code in this specific case was not good.
Leaving out the extra transformation step would, in this case,
make the code clearer and more efficient.
In fact at work, I'm regularly known as __The Evil One__ because of my
propensity to use the switch construct.
>
Every company brochure shows my position as Sauron in the company
fables, with my signature golden ring. Pure evil, I guarantee it.
Dude, get over yourself. Pretending to be persecuted because someone
criticized your code is not a good look.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal