home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!paladin.american.edu!darwin.sura.net!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!ulogic!hartman
- From: hartman@ulogic.UUCP (Richard M. Hartman)
- Newsgroups: comp.lang.c
- Subject: Re: readable code
- Message-ID: <800@ulogic.UUCP>
- Date: 31 Dec 92 18:37:00 GMT
- References: <1992Dec31.020953.12265@netcom.com>
- Organization: negligable
- Lines: 106
-
- In article <1992Dec31.020953.12265@netcom.com> pdh@netcom.com (Phil Howard ) writes:
- >
- >BTW, I've had a couple people who I know are fully experienced C programmers
- >tell me that they find array subscripting like:
- >
- > array [ n ]
- >
- >harder to read, and insist on something like:
- >
- > array[n]
- >
- >Personally I find the former easier to read, PROVIDED IT FITS. There is
- >not that much difference that I would not squish it to get certain things
- >on one line where those things would read better that way. But I do feel
- >I should space things out when it makes it easier to read... it it usually
- >does so for *ME*.
-
- To continue in this vein you would probably be writing:
-
- func ( arg )
-
- and:
-
- if ( cond )
-
- Is "if" a function or a keyword?
-
- I tend to use spacing as an aid to comprehension. If a symbol
- is alone, I tend to think of it as a variable or keyword, if
- followed by a '(', it should be a function, if followed by a
- '[' then an array. so I would write:
-
- func(arg)
-
- although I would accept:
-
- func( arg )
-
- if forced to. I *do* like spaces after my commas for "readability",
- so:
-
- func(arg1, arg2)
-
- would be typical for my style.
-
- Otoh I would never write:
-
- if(cond)
-
- again, that creates a "visual ambiguity" about whether "if" is
- a function. It would be:
-
- if (cond)
-
- in my code.
-
-
- Similarly I would write my array references as:
-
- array[index]
-
- Instead of tossing in spaces. In general I tend to try to
- use spacing conventions as they are used in english. That is,
- spaces after commas, but not before; spaces before parenthesis
- but not after; etc. I guess my preference for NOT putting the
- space before the paren of a function comes from notations from
- scientific & mathematical functions, and functions from other
- languages used before I used C (and I still appreciate the
- extra clue it gives that the symbol is a function and not
- a variable...).
-
- Spaces should separate things that should be separated, and not
- separate things that shouldn't. (how's that for a solopsism! :)
-
- Your code example (sorry I deleted it before deciding to
- refer to it) where you select the array with ?: and then
- index it (something like:
-
- ((a < b) ? array1 : array2) [idx] += inc;
-
- wasn't it?) I would consider "comprehensible", but not "readable".
- To differentiate: conprehensible is something I can understand
- after reading it, readable is something I don't have to think
- about as I'm scanning over the code. (maybe what I'm after
- should be called "scannable"?)
-
- I unfortunately have to sometimes read code that is precicely
- the opposite of mine:
-
- if( cond )
-
- sheesh! Imagine trying to read a comment( a parenthetical
- comment embedded in another sentance )that used spacing
- conventions like that!
-
- disclaimer: All of the above is, of course, IMHO. And
- does not represent the opinion of anyone other than myself
- and all other rational programmers. ;)
-
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- And the men who hold high places |
- must be the ones who start | -Richard Hartman
- to mold a new reality | hartman@uLogic.COM
- closer to the heart! |
-
-