Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!mit-eddie!uw-beaver!tektronix!teklds!copper!stevesu From: stevesu@copper.TEK.COM (Steve Summit) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <1176@copper.TEK.COM> Date: Mon, 29-Jun-87 22:57:41 EDT Article-I.D.: copper.1176 Posted: Mon Jun 29 22:57:41 1987 Date-Received: Sat, 4-Jul-87 18:39:48 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <17193@cca.CCA.COM> Organization: Tektronix Inc., Beaverton, Or. Lines: 63 It has been pointed out that my original posting had a blatant error in it: (!p) and (p != NULL) are not at all equivalent, but in fact are exactly opposite. I was at first acutely embarrassed, but I am now flatly amazed that the statements have been argued so hotly, by some of the best minds on the network, without noting this crucial fact. The fact that this error is so easy to make (I spent several hours on the original posting, and I read through it countless times, and I still missed it) ends up illustrating the point very well: when coding, say what you _m_e_a_n. Since I started this, I might as well make my thinking process clear: we have a pointer variable, and it either holds or does not hold a single "out of band" nil value. The closest transliterations of those English statements into C are if(p == NULL) and if(p != NULL) (assuming a proper #definition of NULL). In my opinion, the _m_o_s_t _i_m_p_o_r_t_a_n_t _t_h_i_n_g is to keep that transliteration step simple. Everything else (compilation time, efficiency, source code character count) is secondary. The biggest problem in Software Engineering is not code size or efficiency but correctness: a program is supposed to do what you want it to do, but rarely does. The more I can make my C code "read" like an English description of what the code is supposed to do, the fewer transliteration errors I will make, and the easier my code will be for me, and others, to read. While I am back up on the soapbox, I will respond to one other point: > I take exception to those who, only understanding their own > viewpoint and approach, treat any other approach based on some other > viewpoint as being bad code. The person to whom I originally responded > supposed that "if (!p)" was a sloppy abomination used to save characters. > This is an intensely parochial view. That was only part of my supposition, and it may be parochial, but it's no more parochial than the supposition that "C is for experts" is elitist. "if(p == NULL)" is not only easier for me to understand, but I suspect that it is also easier for people who are not as experienced with C as I am. (Arguments of the form "but anyone who considers himself a C programmer _s_h_o_u_l_d understand" ignored. Face it, there are less experienced C programmers in the world, and one of them will have to maintain your programs some day. Why not make their job a bit easier?) > And I do not really see that one can claim to understand > C and also claim that 'if (!p)' is obscure. Apparently you do not understand me any better than you think I understand you. Steve Summit stevesu@copper.tek.com "I meant what I said and I said what I meant. An elephant's honest, one hundred percent." -- Dr. Suess, "Horton Hears a Who!"