Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!orchid!rbutterworth From: rbutterworth@orchid.UUCP Newsgroups: comp.lang.c Subject: Re: *\"LDA\" ok? Message-ID: <10402@orchid.waterloo.edu> Date: Wed, 26-Aug-87 12:02:13 EDT Article-I.D.: orchid.10402 Posted: Wed Aug 26 12:02:13 1987 Date-Received: Fri, 28-Aug-87 02:45:48 EDT References: <8877@brl-adm.ARPA> <8088@mimsy.UUCP> <1623@tekchips.TEK.COM> <6332@brl-smoke.ARPA> Organization: U of Waterloo, Ontario Lines: 37 In article <6332@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: > Perhaps it would help if they were told that strcmp() does NOT test for > string equality; rather, it compare the lexical ordering of two strings. > This makes it useful sometimes for the function used with qsort(). The > test for exact match is simply a common special case. The biggest problem I've found with my and other's understanding of strcmp() is its name. Until you get used to it, "!strcmp()", "strmcp() != 0", and other such usages are quite non-obvious. In most cases the function is simply used as a true or false test, and it isn't obvious that a true comparison should mean that the strings are different. If it were named say strdif(), then something like "if (!strdif(a,b)) ..." or "if (strdif(a,b))" would be much more readable for the beginner. i.e. the truth indicates that the strings were different, something that even beginners should be able to understand, as opposed to the truth indicating that the strings were comparable, a concept that isn't all that obvious to me even after years of use. The word "compare" says what you want to do with the arguments, the word "difference" says what result you want. It's much easier to think of this particular function in terms of what it returns rather than in terms of what it does with its arguments. On the other hand, functions such as printf() are appropriately named according to what they do to their arguments, not the value they return, and so there is much less confusion. Of course there isn't much we can do about it now, but this is something that should be considered when making up names for new functions. We speak of "evolving" languages, but somehow I think that if Darwin had had to contend with the concept of "backward compatibility" he would have given up.