:: Re: [DNG] Icerbergs aren't small ju…
Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: karl
Ημερομηνία:  
Προς: dng
Αντικείμενο: Re: [DNG] Icerbergs aren't small just because they're mostly underwater
Didier Kryn:
> Le 25/01/2016 13:23, Rainer Weikusat a écrit :
> >      while (*r) if (*r++ == '/') n = r;

>
>      Does it mean

>
>      while (*r)
>        {
>          if (*r == '/')
>     {
>             n = r;
>             r++;
>          }
>        }

>
> or
>
>      while (*r)
>        {
>          if (*r == '/')
>     {
>             r++;
>             n = r;
>          }
>        }

>
>
>      I think the second answer is the good one. It is more readable and 
> less error-prone than your example and the compiler will produce exactly 
> the same instructions. You don't need to do the work of the compiler; it 
> does it better. Better concentrate on writing programs easier to read 
> and less error-prone. These pre-increment and post-increment 
> instructions should be deprecated - I already advocated that on this 
> list, although it is not the place :-)

>
>      The reason why seasonned programmers prefer the kind of expression 
> you wrote, with post-increment, is a perfect example of a style dictated 
> by pure aesthetics. This an error I used to make when I was younger, 
> but, with age and learning, I have found true reasons to do otherwise.


Uhh. I do prefer the short version, it should be perfectly
understandable to anyone versed in c. I do prefer code to not to spread
out onto mult. lines as your example does, since the shorter version
make it easier to see the whole surronding function, and that aids the
understanding.

Inserting pairs of {}'s makes things less prone to questions about what
goes where, but there is no need to state the obvious, and inserting
more whitespace than necessary does not help.

Putting things that are closely related close and as in this case in
one line, makes it easier to mentally think "basename" and move on.

///

I have written a similar thing myself

    cmdline_pgm = strrchr(argv[0], '/');
    if (cmdline_pgm == NULL) cmdline_pgm = argv[0];
    else cmdline_pgm++;


It worked and I moved on. Should I do it again, I'd consider Rainers
code.

///

As for Rainers original question, his code is pretty understandable
for me except for the "&= 0x20", which forced me to think.

Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57