home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5892 < prev    next >
Encoding:
Internet Message Format  |  1992-09-12  |  6.4 KB

  1. Path: sparky!uunet!spool.mu.edu!sol.ctr.columbia.edu!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Perl language formatting conventions?
  5. Message-ID: <1992Sep12.203752.13716@netlabs.com>
  6. Date: 12 Sep 92 20:37:52 GMT
  7. References: <1992Aug25.152315.20630@news.eng.convex.com> <1992Aug27.042932.3143@netlabs.com> <1361@minya.UUCP>
  8. Sender: news@netlabs.com
  9. Distribution: comp
  10. Organization: NetLabs, Inc.
  11. Lines: 156
  12. Nntp-Posting-Host: scalpel.netlabs.com
  13.  
  14. In article <1361@minya.UUCP> jc@minya.UUCP (John Chambers) writes:
  15. : > I also use 4-space indent, in case you hadn't noticed.  :-)
  16. : It has always seemed to me that a single tab is the best indent.  That
  17. : way,  the  reader  can choose his/her own favorite indent spacing, and
  18. : everyone is happy.  (In vi you type "se ts=4" to  get  4-column  tabs;
  19. : most editors have a similar command.) It's also very fast to type.
  20.  
  21. That's fine if nobody but you ever has to look at the file, and you
  22. never have to print it.  It's also fine if you editor translates to
  23. standard 8-space hard tabs for you on input and output.  But if your
  24. editor is going to do that, why not just disconnect the notion of soft
  25. tab stops from hard tab characters?  In vi you just set sw=4 and learn
  26. to use ^T instead of TAB.  (Mind you, I'd've made TAB work like ^T
  27. does, and DEL/BACKSPACE like ^D, just so people couldn't use the
  28. laziness argument to avoid ^T/^D.  Then make some way to insert a hard
  29. tab if you want one.  One could almost do it with a keyboard mapping.)
  30.  
  31. : One of the silliest frustrations is all the programmers  who  like  to
  32. : use  mixtures  of  tabs  and spaces to get 4-column spacing with 8-col
  33. : tabs. This forces readers to reset the tabs to 8 columns to make sense
  34. : of  the  code;
  35.  
  36. Eek.  Talk about cultural differences...
  37.  
  38. : it is slow for the writer to type;
  39.  
  40. No.  Not with sw=4 and ^T and autoindent.
  41.  
  42. : it wastes disk space and network bandwidth.
  43.  
  44. A somewhat valid point, but I sincerely doubt that most of your disk is
  45. taken up with source code.  And much long haul traffic nowadays is
  46. compressed such that the way you tab your lines doesn't matter.
  47.  
  48. : It's about as wrong a convention as one  could
  49. : come up with (so of course it's the most common one ;-).
  50.  
  51. That's the point.  Yes, it's just a convention to be broken, but civil
  52. disobedience always has a price.  What I balk at, of course, is when *I*
  53. have to pay the price for *your* civil disobedience.  Then it's no longer
  54. mere civil disobedience.  More like disturbing the peace, or maybe
  55. dictatorship of the proletariet.  :-)
  56.  
  57. I don't mind squabbling over mere cultural differences as long as we
  58. realize that's all we're doing.  Certainly, I've learned to deal with
  59. the other sort of file--look at the retab script in the book, after all.
  60. Note that the default is to translate 8 spacing to 4...  :-)
  61.  
  62. : The next most difficult problem, of course, is  finding  the  boundary
  63. : between  declarations  and statements in a function (so that something
  64. : can be added there).  What's frustrating here is that the  original  C
  65. : compiler  allowed declarations to be mixed with statements (as long as
  66. : everything was declared before it was used),  so  the  problem  didn't
  67. : exist.   The  modern  "improvement"  requiring  that declarations come
  68. : before statements made  the  job  much  more  difficult,  and  for  no
  69. : apparent  reason  that I've ever heard.  It certainly doesn't make the
  70. : compiler's job any easier.  (Yes, I *have* written compilers; I  won't
  71. : listen  seriously to any claim that this affects the compiler-writer's
  72. : job materially.  ;-)
  73.  
  74. Yes, and you'll note that the distinction disappears again in C++.  Almost
  75. enough reason to switch right there...  :-)
  76.  
  77. : Actually, my favorite bit of nonsense in C formatting is  the  growing
  78. : practice  of what I call "Chinese" coding.  Recall that traditionally,
  79. : Chinese was written vertically, with one or two character per line.
  80.  
  81. Well, I'm sure they think of the lines as vertical, not horizontal.
  82. More cultural differences.  It's just the column-major vs row-major
  83. fight all over again.  :-)
  84.  
  85. : We are now seeing a lot of C in a similar style:
  86. :     if (!initf)
  87. :     {
  88. :         win = 
  89. :         XCreateSimpleWindow(
  90. :             display,
  91. :             RootWindow(display,screen),
  92. :             win_x,win_y,
  93. :             win_w,win_h,
  94. :             border_width,
  95. :             WhitePixel(display,screen),
  96. :             Pixel(display,screen)
  97. :             );
  98. :         initf = TRUE;
  99. :     }
  100. :         else
  101. :     {
  102. :         (void*)
  103. :     fprint(
  104. :         stderr,
  105. :             "%d *** %s can't create new window [%d=%s].\n"
  106. :             timestamp(),
  107. :             progname,
  108. :             errno,
  109. :             sys_errlist[errno]
  110. :         );
  111. :     }
  112.  
  113. This is becoming an unfortunate necessity.  The only alternatives I see are
  114.  
  115.     1) Go back to simpler problem spaces and simpler solution spaces.
  116.     2) Use shorter, less mnemonic names and consequently suffer more
  117.         confusion and name collisions.
  118.     3) Put fewer but wider windows on the screen and blow off the
  119.         punchcard metaphor once and for all.
  120.  
  121. My basic policy is, of course, to use one line or maybe two, until it
  122. starts looking cluttered, and then switch to the vertical format.  (The
  123. vertical format actually works better in languages that have named
  124. parameters.  In Perl 5, I'm making => a synonym for comma, so you can
  125. say things like:
  126.  
  127.     $childmess = &Get(
  128.             OC           => $oc,
  129.             OI           => $oi,
  130.             SCOPE        => $scope1,
  131.             ATTR_ID_LIST => $no_attrs);
  132.  
  133. As someone pointed out earlier, all you do is stuff the list into an
  134. associative array, and then pull out the parameters in the order you
  135. like.  If you don't think this is a win, note that the actual
  136. &new_GetReq call has 14 arguments, but most of them have defaults or
  137. can be undefined:
  138.  
  139.     sub Get {
  140.     local(%arg) = @_;
  141.     &new_GetReq(
  142.         defined($arg{ID}) ? $arg{ID} : &new_id(),
  143.         $arg{DELETE_CB},
  144.         $arg{SOURCE} || *def_source,
  145.         $arg{DEST} || *def_dest,
  146.         $arg{QOS} || *def_qos,
  147.         $arg{MODE},
  148.         $arg{APP_CONTEXT},
  149.         $arg{OC},
  150.         $arg{OI},
  151.         $arg{ACCESS},
  152.         $arg{SYNC},
  153.         $arg{SCOPE} || *def_scope,
  154.         $arg{FILTER} || *def_filter,
  155.         $arg{ATTR_ID_LIST});
  156.     }
  157.  
  158. So, would you rather call &Get, or &new_GetReq?  And if you really
  159. detest vertical alignment, you often have a better chance to fit it
  160. onto one line with named parameters than with positional parameters:
  161.  
  162.     $childmess = &Get(OC=>$oc, OI=>$oi, SCOPE=>$scope1, ATTR_ID_LIST=>$no_attrs);
  163.  
  164. Shoot, almost made it...  :-)
  165.  
  166. Larry
  167.