in reply to Idioms considered harmful


To learn a language you have to learn the idioms as well.

In The C Programming Language there is a discussion on how to write a strcpy() function. After several iterations the code is reduced to the following:

while (*s++ = *t++) ;
The comment that follows this is enlightening:
Although this may seem cryptic at first sight, the notational convenience is considerable, and the idiom should be mastered, because you will see it frequently in C programs.

Idioms in natural language and programming languages are just well known concise ways of saying something. Just because something is concise doesn't make it an idiom. For something to become idiomatic it must be useful enough to pass into common usage. As such it is unlikely that an idiom could be considered harmful.

I'd agree however, that Golf is best avoided in production code.

--
John.

Replies are listed 'Best First'.
Re: Re: Idioms considered harmful
by Anonymous Monk on Oct 16, 2002 at 11:02 UTC
    Ironically that book is full of lots of examples of how to not write C. Try that trick strings that might overlap and you can wipe out half your data. Even if you think that it is safe, is having to worry worthwhile?

      The standard library strcpy() doesn't handle the case where strings overlap either. Or at least it's behaviour is undefined.

      --
      John.