Re: Official list of top C annoyances

Liste des GroupesRevenir à l c 
Sujet : Re: Official list of top C annoyances
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 09. Sep 2026, 23:30:28
Autres entêtes
Organisation : None to speak of
Message-ID : <117smm4$1g635$3@kst.eternal-september.org>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
User-Agent : Gnus/5.13 (Gnus v5.13)
Lane W <cactus_DAC@yahoo.com> writes:
[...]
enum Dodges {
    NEAT : 1
    FLAWED : 2
    BARELY : 3
    UNSUCCESS : 4
};

I strongly suggest you try compiling any code that you're going to post
here.  This is not the correct syntax for an enum type.  I presume
you're trying to specify values for NEAT, FLAWED, et al, but I see no
reason not to just rely on the default values of 0, 1, ....

Unlike your initial code snippet, you're giving names to the cases
rather than just using constants 1, 2, 3, which is an improvement.

enum Dodges d = UNSUCCESS;
>
if (dodge < 1)
    d = BARELY;
if (dodge < 0.9)
    d = FLAWED;
if (dodge < 0.5)
    d = NEAT;

As I recall (I might be mistaken), your original code ignored
the possibility that dodge could be >= 1.  (For consistency, I'd
definitely write 1.0 rather than 1 here).

If dodge < 0.5, you test its value 3 times and update the value of d
3 times.  The performance impact is trivial, but it's conceptually
more complex than it needs to be.  I'd put the (dodge < 0.5) test
first and use an else-if chain.  (The fact that this forces the
order of the tests is mildly annoying, I suppose.)

switch (d)
{
    case NEAT:
        slog("%s easily dodged attack...",  being[k].name);
        return 1;
    case FLAWED:
        slog("%s hardly dodged attack...",  being[k].name);
        return 1;
    case BARELY:
        slog("%s dodged  attack...",  being[k].name);
        return 1;
    default:
        return -1; // not dodged.
}

The association between NEAT and "easily", FLAWED and "hardly", and
BARELY and nothing, seems arbitrary.  I'd probably give the enumeration
constants names that match the string.

WHERE IS THIS DUPLICATION?
>
WHERE ARE THESE SYNTAX ERRORS YOU NEVER EXPLICITLY STATE?

I don't know whether there were syntax errors in your previous code.
If the syntax errors in your new code were corrected, this might
be a decent demonstration of a useful technique: transforming a
range of floating-point values into discrete values so they can be
operated on more easily.  In this particular case, I wouldn't bother.
There are only 3 normal and 1 exceptional cases being considered, and
I personally would prefer to test the floating-point value directly.
If I want to assign names to the ranges, the strings passed to slog()
express that clearly enough, or I might add comments.

if (dodge < 0.5) {
    slog("%s dodged  attack...",  being[k].name);
}
else if (dodge < 0.9) {
    slog("%s hardly dodged attack...",  being[k].name);
}
else if // ...

In a more complicated case, setting up the enum values could be a
good idea, particularly if those values are going to be used later
in the code.  If this is a simple example meant to demonstrate the
technique, that's fine.  There's a big difference between writing
code to demonstrate a concept (which often needs to be simplified)
and writing real-world code.

Am I cleared for Heaven now?
>
Can we get ten more people to hop on the bandwagon and RUDELY tell me
how bad it is?
>
I gauged that RUDENESS is something you try to avoid here.

*yawn*

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
6 Sep 26 * Official list of top C annoyances396fir
6 Sep 26 +- Re: Official list of top C annoyances1fir
6 Sep 26 +* Re: Official list of top C annoyances368bart
6 Sep 26 i+* Re: Official list of top C annoyances366Janis Papanagnou
7 Sep 26 ii+* Re: Official list of top C annoyances362fir
7 Sep 26 iii`* Re: Official list of top C annoyances361bart
7 Sep 26 iii +* Re: Official list of top C annoyances359David Brown
7 Sep 26 iii i`* Re: Official list of top C annoyances358bart
7 Sep 26 iii i +- Re: Official list of top C annoyances1fir
7 Sep 26 iii i `* Re: Official list of top C annoyances356David Brown
7 Sep 26 iii i  +* Re: Official list of top C annoyances354bart
7 Sep 26 iii i  i+* Re: Official list of top C annoyances65Janis Papanagnou
8 Sep 26 iii i  ii+* Re: Official list of top C annoyances24bart
8 Sep 26 iii i  iii+* Re: Official list of top C annoyances6Lane W
8 Sep 26 iii i  iiii`* Re: Official list of top C annoyances5Keith Thompson
9 Sep 26 iii i  iiii `* Re: Official list of top C annoyances4fir
9 Sep 26 iii i  iiii  `* Re: Official list of top C annoyances3fir
9 Sep 26 iii i  iiii   `* Re: Official list of top C annoyances2fir
18 Sep08:38 iii i  iiii    `- Re: Official list of top C annoyances1fir
8 Sep 26 iii i  iii+- Re: Official list of top C annoyances1Janis Papanagnou
8 Sep 26 iii i  iii`* Re: Official list of top C annoyances16bart
9 Sep 26 iii i  iii +- Re: Official list of top C annoyances1Janis Papanagnou
9 Sep 26 iii i  iii `* Re: Official list of top C annoyances14David Brown
9 Sep 26 iii i  iii  `* Re: Official list of top C annoyances13bart
9 Sep 26 iii i  iii   `* Re: Official list of top C annoyances12David Brown
9 Sep 26 iii i  iii    `* Re: Official list of top C annoyances11bart
9 Sep 26 iii i  iii     `* Re: Official list of top C annoyances10David Brown
9 Sep 26 iii i  iii      `* Re: Official list of top C annoyances9bart
9 Sep 26 iii i  iii       +- Re: Official list of top C annoyances1bart
9 Sep 26 iii i  iii       +* Re: Official list of top C annoyances3David Brown
9 Sep 26 iii i  iii       i`* Re: Official list of top C annoyances2bart
10 Sep 26 iii i  iii       i `- Re: Official list of top C annoyances1David Brown
9 Sep 26 iii i  iii       +* Re: Official list of top C annoyances2Janis Papanagnou
9 Sep 26 iii i  iii       i`- Re: Official list of top C annoyances1Janis Papanagnou
9 Sep 26 iii i  iii       `* Re: Official list of top C annoyances2Keith Thompson
9 Sep 26 iii i  iii        `- Re: Official list of top C annoyances1bart
8 Sep 26 iii i  ii`* Re: Official list of top C annoyances40David Brown
9 Sep 26 iii i  ii `* Re: Official list of top C annoyances39Janis Papanagnou
9 Sep 26 iii i  ii  `* Re: Official list of top C annoyances38David Brown
9 Sep 26 iii i  ii   +* Re: Official list of top C annoyances7Janis Papanagnou
9 Sep 26 iii i  ii   i`* Re: Official list of top C annoyances6David Brown
10 Sep 26 iii i  ii   i `* Re: Official list of top C annoyances5Chris M. Thomasson
10 Sep 26 iii i  ii   i  +- Re: Official list of top C annoyances1Chris M. Thomasson
11 Sep 26 iii i  ii   i  +- Re: Official list of top C annoyances1David Brown
14 Sep 26 iii i  ii   i  `* Re: Official list of top C annoyances2Kaz Kylheku
18 Sep16:29 iii i  ii   i   `- Re: Official list of top C annoyances1Tim Rentsch
9 Sep 26 iii i  ii   `* Re: Official list of top C annoyances30Keith Thompson
9 Sep 26 iii i  ii    +* Re: Official list of top C annoyances26David Brown
9 Sep 26 iii i  ii    i`* Re: Official list of top C annoyances25Lane W
9 Sep 26 iii i  ii    i +* Re: Official list of top C annoyances23David Brown
9 Sep 26 iii i  ii    i i+* Re: Official list of top C annoyances8Lane W
9 Sep 26 iii i  ii    i ii+* Re: Official list of top C annoyances6fir
9 Sep 26 iii i  ii    i iii+* Re: Official list of top C annoyances3Lane W
9 Sep 26 iii i  ii    i iiii+- Re: Official list of top C annoyances1fir
10 Sep 26 iii i  ii    i iiii`- Re: Official list of top C annoyances1Keith Thompson
9 Sep 26 iii i  ii    i iii`* Re: Official list of top C annoyances2fir
9 Sep 26 iii i  ii    i iii `- Re: Official list of top C annoyances1fir
9 Sep 26 iii i  ii    i ii`- Re: Official list of top C annoyances1David Brown
9 Sep 26 iii i  ii    i i+* Re: Official list of top C annoyances13bart
9 Sep 26 iii i  ii    i ii`* Re: Official list of top C annoyances12Lane W
9 Sep 26 iii i  ii    i ii +* Re: Official list of top C annoyances9bart
9 Sep 26 iii i  ii    i ii i+* Re: Official list of top C annoyances6fir
9 Sep 26 iii i  ii    i ii ii+* Re: Official list of top C annoyances4fir
9 Sep 26 iii i  ii    i ii iii`* Re: Official list of top C annoyances3fir
9 Sep 26 iii i  ii    i ii iii `* Re: Official list of top C annoyances2fir
9 Sep 26 iii i  ii    i ii iii  `- Re: Official list of top C annoyances1fir
9 Sep 26 iii i  ii    i ii ii`- Re: Official list of top C annoyances1fir
9 Sep 26 iii i  ii    i ii i+- Re: Official list of top C annoyances1bart
10 Sep 26 iii i  ii    i ii i`- Re: Official list of top C annoyances1David Brown
9 Sep 26 iii i  ii    i ii +- Re: Official list of top C annoyances1David Brown
9 Sep 26 iii i  ii    i ii `- Re: Official list of top C annoyances1Keith Thompson
10 Sep 26 iii i  ii    i i`- Re: Official list of top C annoyances1Janis Papanagnou
9 Sep 26 iii i  ii    i `- Re: Official list of top C annoyances1Keith Thompson
9 Sep 26 iii i  ii    `* Re: Official list of top C annoyances3Richard Harnden
9 Sep 26 iii i  ii     +- Re: Official list of top C annoyances1Keith Thompson
10 Sep 26 iii i  ii     `- Re: Official list of top C annoyances1Janis Papanagnou
8 Sep 26 iii i  i`* Re: Official list of top C annoyances288Waldek Hebisch
8 Sep 26 iii i  i `* Re: Official list of top C annoyances287bart
9 Sep 26 iii i  i  +* Re: Official list of top C annoyances269Waldek Hebisch
9 Sep 26 iii i  i  i+- Re: Official list of top C annoyances1Janis Papanagnou
9 Sep 26 iii i  i  i`* Re: Official list of top C annoyances267bart
9 Sep 26 iii i  i  i +- Re: Official list of top C annoyances1tTh
9 Sep 26 iii i  i  i +* Re: Official list of top C annoyances3David Brown
9 Sep 26 iii i  i  i i`* Re: Official list of top C annoyances2bart
10 Sep 26 iii i  i  i i `- Re: Official list of top C annoyances1David Brown
9 Sep 26 iii i  i  i +* Re: Official list of top C annoyances121Janis Papanagnou
9 Sep 26 iii i  i  i i`* Re: Official list of top C annoyances120bart
10 Sep 26 iii i  i  i i +* Re: Official list of top C annoyances41Janis Papanagnou
10 Sep 26 iii i  i  i i i`* Re: Official list of top C annoyances40bart
10 Sep 26 iii i  i  i i i `* Re: Official list of top C annoyances39fir
10 Sep 26 iii i  i  i i i  +* Re: Official list of top C annoyances3fir
10 Sep 26 iii i  i  i i i  i`* Re: Official list of top C annoyances2fir
10 Sep 26 iii i  i  i i i  i `- Re: Official list of top C annoyances1fir
10 Sep 26 iii i  i  i i i  `* Re: Official list of top C annoyances35bart
10 Sep 26 iii i  i  i i i   +- Re: Official list of top C annoyances1fir
10 Sep 26 iii i  i  i i i   `* Re: Official list of top C annoyances33fir
10 Sep 26 iii i  i  i i i    +* Re: Official list of top C annoyances31bart
10 Sep 26 iii i  i  i i i    i+* Re: Official list of top C annoyances5fir
10 Sep 26 iii i  i  i i i    ii`* Re: Official list of top C annoyances4fir
10 Sep 26 iii i  i  i i i    ii `* Re: Official list of top C annoyances3bart
10 Sep 26 iii i  i  i i i    ii  `* Re: Official list of top C annoyances2fir
10 Sep 26 iii i  i  i i i    i`* Re: Official list of top C annoyances25fir
10 Sep 26 iii i  i  i i i    `- Re: Official list of top C annoyances1fir
10 Sep 26 iii i  i  i i `* Re: Official list of top C annoyances78David Brown
13 Sep 26 iii i  i  i `* Re: Official list of top C annoyances141Waldek Hebisch
9 Sep 26 iii i  i  `* Re: Official list of top C annoyances17Janis Papanagnou
8 Sep 26 iii i  `- Re: Official list of top C annoyances1Chris M. Thomasson
7 Sep 26 iii `- Re: Official list of top C annoyances1fir
7 Sep 26 ii`* Re: Official list of top C annoyances3David Brown
7 Sep 26 i`- Re: Official list of top C annoyances1Chris M. Thomasson
7 Sep 26 +- Re: Official list of top C annoyances1fir
8 Sep 26 `* Re: Official list of top C annoyances25fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal