home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5558 < prev    next >
Encoding:
Internet Message Format  |  1992-08-27  |  7.0 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!network.ucsd.edu!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: coding style (was Re: Perl language formatting conventions?)
  5. Message-ID: <1992Aug27.180029.19638@netlabs.com>
  6. Date: 27 Aug 92 18:00:29 GMT
  7. References: <DAVE.92Aug25141544@pipi.iis.u-tokyo.ac.jp> <1992Aug25.214800.10825@netlabs.com> <1992Aug27.072110.24646@news.Hawaii.Edu>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 170
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <1992Aug27.072110.24646@news.Hawaii.Edu> todd@uhunix.uhcc.Hawaii.Edu (Todd Ogasawara) writes:
  14. : In article <1992Aug25.214800.10825@netlabs.com> lwall@netlabs.com (Larry Wall) writes:
  15. : >In article <DAVE.92Aug25141544@pipi.iis.u-tokyo.ac.jp> dave@pipi.iis.u-tokyo.ac.jp (David Wuertele) writes:
  16. : >: What do youse all think?
  17. : >That's a religious issue.
  18. : >There's only one sure-fire way to be happy.  Do what you know is right,
  19. : >and don't expect everyone to like it.
  20. : >Larry
  21. : I agree with Larry's 2nd statement but am not sure I agree with the first
  22. : totally. I admit that "style," by its very nature, has some degree of
  23. : individualism. However, I suspect that there might be some way to quantify
  24. : some (though not all) aspects of coding style to help programmers make
  25. : source code easier for other people to read and interpret (or, for that
  26. : matter, for the programmer him/herself at some time in the future).
  27.  
  28. Well, okay.  I can see that my first statement was misleading.  People
  29. often use the statement as a copout to mean there is no right or
  30. wrong.  But those who know me well know that I have some very definite
  31. ideas about right and wrong.  I was merely trying to say that such
  32. discussions tend to be non-productive, because people are generally
  33. more interested in maintaining their cultural continuity than in
  34. improving their lives.
  35.  
  36. : There were a few journal articles a number of years back trying to
  37. : determine how varying indentation size affects code readability (I think
  38. : the conclusion was that 4 spaces on a "standard" sized screen was optimal
  39. : though I still prefer 8 spaces :-).
  40.  
  41. Ah, is that cultural continuity or mere laziness?  I would consider it false
  42. laziness because for a small mental investment you can generally make your
  43. favorite editor do 4 spaces as easily as 8 (or nearly as easily), and reap
  44. a Laziness Benefit every time you DON'T have to figure out where to
  45. split a line because your indentation no longer manifests an unhealthy
  46. affinity for the right margin.
  47.  
  48. Perceptually--yes, a dangerous word to address to someone in the Psych
  49. Dept.--perceptually, I think 4 spaces has all the benefits of 8.
  50. Anything less than that and I have trouble lining things up on the
  51. screen.  But the half spacing for line continuations is easy to calculate
  52. (2), and easy to see because such lines are right next to each other.
  53. (Not that I feel bound to use 2 spaces if some other spacing lines things
  54. up nicely.)
  55.  
  56. : There must also be some way to use some of the findings from vision
  57. : on processing simple (curved vs. angular) and complex (alphanumeric and
  58. : ideographic) images as a tie-in to things like parentheses placement.
  59.  
  60. Yes!!!!  That's why I did the quoting mechanisms the way I did!!!!
  61.  
  62.     s/foo/bar/
  63.  
  64. but
  65.  
  66.     s(/foo)(/bar)
  67.  
  68. I despise the overly minimalistic Unix cultural "ideal" of imitating a
  69. row of leaning toothpicks: s/\/X\/Y\(\*\)/\/Y\/X\1/.
  70.  
  71. Sure, s/// can typically turn into s### or whatever.  In Perl, so can
  72. m//, tr///, q//, qq// and qx//.
  73.  
  74. But there's something particularly special about m(), qx[], etc. and I think
  75. you've put your finger on it.
  76.  
  77. Visual distinction is why I like
  78.  
  79.     for (;;) {
  80.     }
  81.  
  82. and
  83.  
  84.     $_ = <FOOHANDLE>;
  85.  
  86. What people often don't realize is that Visual Distinction is an aid to
  87. Mental Laziness, which is a Virtue.  (LISPers take note.)
  88.  
  89. : One thing I've found over the past few years is that I and some other
  90. : people find placing a space after an openning paren and before a closed
  91. : paren sometimes adds to the readability of the code (this is not a 100%
  92. : rule, it is more like an "i before e except after c except in receive"
  93. : rule).
  94.  
  95. No, "receive" follows the rule.  It's "weird" that is weird.
  96.  
  97. : E.g., (from C)
  98. :     while ((c = getc(fpIn)) != EOF) {
  99. :         putc(c,fpOut);
  100. :     }
  101. : vs.
  102. :     while ( ( c = getc(fpIn) ) != EOF ) {
  103. :         putc(c, fpOut);
  104. :     }
  105. : Note that the "paren space" rule is not used 100% of the time in even a
  106. : short piece of code like the one shown above.
  107.  
  108. Yes, sometimes I do that, and sometimes not.  Though generally NOT on
  109. something like a condition, which already has spaces outside the parens.
  110. But I'll often say FROBNERZ( foobar + boofar ); and such.  It really
  111. depends on the degree of perceived clutter.
  112.  
  113. : I also think that the use of parens even when they aren't needed (like the
  114. : example above) aids readability. I.e., the code above is equivalent to
  115. :     while ( ( c = getc(fpIn) ) != EOF )
  116. :         putc(c, fpOut);
  117.  
  118. You meant curlies/braces?  I required curlies in Perl because people wrongly
  119. perceive this sort of thing:
  120.  
  121.      while ( ( c = getc(fpIn) ) != EOF )
  122.          putc(c, fpOut);
  123.         count++;
  124.     printf("%d\n", count);
  125.  
  126. This is also why I prefer outdenting the trailing curly.  If you say,
  127. as some do for reasons that they have recently admitted are related
  128. to cultural continuity,
  129.  
  130.      while ( ( c = getc(fpIn) ) != EOF ) {
  131.          putc(c, fpOut);
  132.         count++;
  133.         }
  134.     printf("%d\n", count);
  135.  
  136. then you're actually trying to ignore the existence of the trailing curly,
  137. and relying on the indentation for grouping.  Why else would you line
  138. it up except to make it more or less invisible?  You might as well go the
  139. typical LISP route and save a line of text:
  140.  
  141.      while ( ( c = getc(fpIn) ) != EOF ) {
  142.          putc(c, fpOut);
  143.         count++;}
  144.     printf("%d\n", count);
  145.  
  146. But if you say, as I would,
  147.  
  148.      while ( ( c = getc(fpIn) ) != EOF ) {
  149.         putc(c, fpOut);
  150.         count++;
  151.     }
  152.     printf("%d\n", count);
  153.  
  154. then the trailing curly Intrudes upon your consciousness, and says
  155. "I AM HEREBY TERMINATING THIS BLOCK ON MY SOLE AUTHORITY."  I like that.
  156. I like closed structures, and what Ada calls "comb" structures.  Then
  157. again, I like classical Greek, and they liked to construct sandwich
  158. sentences too.
  159.  
  160. : Well, as I said I agree with Larry's second point. I don't expect everyone
  161. : to agree with what I've said above. I would be interested to hear what
  162. : other people think about ways to apply style rules to make Perl and other
  163. : kinds of source code easier to read.
  164.  
  165. I find myself writing things like this lately:
  166.  
  167.     if    (/^h/)        { &help }
  168.     elsif (/^m/)        { &mod  }
  169.     elsif (/^u/)        { &up   }
  170.     elsif (/^d/)        { &down }
  171.     elsif (/^scope/)    { &scope }
  172.     elsif (/^s/)        { &sib  }
  173.     elsif (/^r/)        { $redraw = 1 }
  174.     elsif (/^trace/)    { &rc('on *_trace') }
  175.     elsif (/^q/)        { last  }
  176.     else                { print qq/I don't know how to "$_", boss!\n/ }
  177.  
  178. That probably just means I need to add a case statement to Perl.  But the
  179. minimalist in me rebels.  :-)
  180.  
  181. You want religion, I got religion...
  182.  
  183. Larry
  184.