home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!world!ora.com!minya!jc
- From: jc@minya.UUCP (John Chambers)
- Newsgroups: comp.lang.perl
- Subject: Re: Perl language formatting conventions?
- Summary: y
- Message-ID: <1361@minya.UUCP>
- Date: 11 Sep 92 19:05:02 GMT
- References: <1992Aug25.152315.20630@news.eng.convex.com> <1992Aug27.042932.3143@netlabs.com>
- Distribution: comp
- Lines: 95
-
-
- > I also use 4-space indent, in case you hadn't noticed. :-)
-
- It has always seemed to me that a single tab is the best indent. That
- way, the reader can choose his/her own favorite indent spacing, and
- everyone is happy. (In vi you type "se ts=4" to get 4-column tabs;
- most editors have a similar command.) It's also very fast to type.
-
- One of the silliest frustrations is all the programmers who like to
- use mixtures of tabs and spaces to get 4-column spacing with 8-col
- tabs. This forces readers to reset the tabs to 8 columns to make sense
- of the code; it is slow for the writer to type; it wastes disk space
- and network bandwidth. It's about as wrong a convention as one could
- come up with (so of course it's the most common one ;-).
-
-
- > This is evil. Any dangled statement longer than one line should be
- > enclosed in braces. One of the reasons I require braces in Perl...
-
- I'd argue that braces should always be used. I've written various
- programs to process C code, and the single most difficult problem is
- discovering the scope of if, for, and while constructs. Suppose, for
- example, that my program is trying to add a command as the first (or
- last) line of all if and if-else constructs. In perl, this is rather
- straightforward. In C, it is almost impossible, without doing a full
- parse of the entire language (including reading all header files and
- expanding all macros).
-
- The next most difficult problem, of course, is finding the boundary
- between declarations and statements in a function (so that something
- can be added there). What's frustrating here is that the original C
- compiler allowed declarations to be mixed with statements (as long as
- everything was declared before it was used), so the problem didn't
- exist. The modern "improvement" requiring that declarations come
- before statements made the job much more difficult, and for no
- apparent reason that I've ever heard. It certainly doesn't make the
- compiler's job any easier. (Yes, I *have* written compilers; I won't
- listen seriously to any claim that this affects the compiler-writer's
- job materially. ;-)
-
- Actually, my favorite bit of nonsense in C formatting is the growing
- practice of what I call "Chinese" coding. Recall that traditionally,
- Chinese was written vertically, with one or two character per line. We
- are now seeing a lot of C in a similar style:
-
- if (!initf)
- {
- win =
- XCreateSimpleWindow(
- display,
- RootWindow(display,screen),
- win_x,win_y,
- win_w,win_h,
- border_width,
- WhitePixel(display,screen),
- Pixel(display,screen)
- );
- initf = TRUE;
- }
- else
- {
- (void*)
- fprint(
- stderr,
- "%d *** %s can't create new window [%d=%s].\n"
- timestamp(),
- progname,
- errno,
- sys_errlist[errno]
- );
- }
-
- Sometimes
- I
- really get
- the feeling that
- C programmers
- are actively trying
- to make
- their code
- as difficult
- as possible
- to read;
- but then,
- at other times,
- I
- just feel
- that
- it's all
- silly.
- --
- All opinions Copyright (c) 1992 by John Chambers. Inquire for licensing at:
- 1-617-647-1813 ...!{bu.edu,harvard.edu,eddie.mit.edu,ruby.ora.com}!minya!jc
- --
- Pensu tutmonde; agu loke.
-