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

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!spool.mu.edu!uwm.edu!psuvax1!rutgers!micro-heart-of-gold.mit.edu!eddie.mit.edu!minya!jc
  2. From: jc@minya.UUCP (John Chambers)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Perl language formatting conventions?
  5. Message-ID: <1366@minya.UUCP>
  6. Date: 14 Sep 92 20:46:46 GMT
  7. References: <1992Aug25.152315.20630@news.eng.convex.com> <1992Sep12.203752.13716@netlabs.com>
  8. Distribution: comp
  9. Lines: 196
  10.  
  11. In article <1992Sep12.203752.13716@netlabs.com>, lwall@netlabs.com (Larry Wall) writes:
  12. > In article <1361@minya.UUCP> jc@minya.UUCP (John Chambers) writes:
  13. > : 
  14. > : It has always seemed to me that a single tab is the best indent.  That
  15. > : way,  the  reader  can choose his/her own favorite indent spacing, and
  16. > : everyone is happy.  (In vi you type "se ts=4" to  get  4-column  tabs;
  17. > : most editors have a similar command.) It's also very fast to type.
  18.  
  19. > That's fine if nobody but you ever has to look at the file, and you
  20. > never have to print it.  It's also fine if you editor translates to
  21. > standard 8-space hard tabs for you on input and output.  But if your
  22. > editor is going to do that, why not just disconnect the notion of soft
  23. > tab stops from hard tab characters?  In vi you just set sw=4 and learn
  24. > to use ^T instead of TAB.  (Mind you, I'd've made TAB work like ^T
  25. > does, and DEL/BACKSPACE like ^D, just so people couldn't use the
  26. > laziness argument to avoid ^T/^D.  Then make some way to insert a hard
  27. > tab if you want one.  One could almost do it with a keyboard mapping.)
  28.  
  29. My main reason for not doing this is  that  I  don't  understand  what
  30. you're talking about.  I tried it, and frankly, I can't make sense out
  31. of what vi is doing when I type ^T or ^D.  The first ^T seems to  move
  32. over  the  width  that  I  set sw to; subsequent uses of ^T seem to do
  33. nothing, except that sometimes they freeze the editor so I have to use
  34. ^C  to  get  it to accept any more commands.  ^D's behavior is totally
  35. incomprehensible to me; I can't even describe sensibly what  it  does.
  36. Do you perhaps have a different version of vi than I do?
  37.  
  38. On the other hand, ":se ts=4" is simple:  it sets  the  tab  stops  to
  39. every 4 columns, and the tab key moves over just like you'd expect. As
  40. for printing, pr has options to set the tab positions,  as  do  pretty
  41. much all formatters I've ever seen. (Now if only stty had a way to set
  42. tab stops on the (virtual) terminal, so my (rare) uses  of  cat  would
  43. work correctly.  ;-)
  44.  
  45. > : It's about as wrong a convention as one  could
  46. > : come up with (so of course it's the most common one ;-).
  47.  
  48. > That's the point.  Yes, it's just a convention to be broken, but civil
  49. > disobedience always has a price.  What I balk at, of course, is when *I*
  50. > have to pay the price for *your* civil disobedience.  Then it's no longer
  51. > mere civil disobedience.  More like disturbing the peace, or maybe
  52. > dictatorship of the proletariet.  :-)
  53.  
  54. Huh?  It seems to me that using tabls is the most  cooperative  method
  55. that  I  could use.  It makes it easy for any reader (who knows how to
  56. set tab stops on  the  output  device  ;-)  the  freedom  to  use  any
  57. indentation  that  he/she  pleases.  How could I be more sociable than
  58. that?  On the other hand, any method that uses spaces (whether or  not
  59. mixed  with  tabs)  forces the writer's conventions on the reader, and
  60. makes the output look garbled  to  a  lot  of  readers,  until  he/she
  61. figures out how you had your tabs set, and changes to match that.
  62.  
  63. > I don't mind squabbling over mere cultural differences as long as we
  64. > realize that's all we're doing.  Certainly, I've learned to deal with
  65. > the other sort of file--look at the retab script in the book, after all.
  66. > Note that the default is to translate 8 spacing to 4...  :-)
  67.  
  68. Yup; one of the most important functions of the net  is  to  encourage
  69. violent debate over trivia.  Ain't it fun?  Of course, my main fear is
  70. that I may have sinned by  mentioning  a  specific  editor,  and  thus
  71. invited the wrath (and followups) of partisans of those Other Editors.
  72.  
  73. > : The next most difficult problem, of course, is  finding  the  boundary
  74. > : between  declarations  and statements in a function (so that something
  75. > : can be added there).  ...
  76.  
  77. > Yes, and you'll note that the distinction disappears again in C++.  Almost
  78. > enough reason to switch right there...  :-)
  79.  
  80. Hey, I hadn't noticed that.  Good for them! Some of the changes  to  C
  81. have  had  the  effect  of making it much more difficult to generate C
  82. from a program. Perhaps C++ will be an improvement.  The relaxation of
  83. the  need for a final ';' in perl 4.0.35 is a good example of a bit of
  84. trivia that tremendously simplifies a lot of code-generating code. One
  85. of  the  real sillinesses in C is that final ',' is sometimes optional
  86. (in lists of initializers),  and  sometimes  forbidden  (in  parameter
  87. lists),  while  the final ';' is required.  They couldn't have made it
  88. much more difficult if they'd tried.
  89.  
  90. > : Actually, my favorite bit of nonsense in C formatting is  the  growing
  91. > : practice  of what I call "Chinese" coding.  Recall that traditionally,
  92. > : Chinese was written vertically, with one or two character per line.
  93.  
  94. > Well, I'm sure they think of the lines as vertical, not horizontal.
  95. > More cultural differences.  It's just the column-major vs row-major
  96. > fight all over again.  :-)
  97.  
  98. Yes; the idea is that much C  code  is  now  close  to  being  written
  99. vertically, although the programmers don't think of it that way.
  100.  
  101. Actually, the Chinese system  was  mixed.   The  lines  of  text  went
  102. vertically,  but agglutinated multi-character words went horizontally.
  103. Thus, the symbol for Beijing was always two side-by-side symbols  (the
  104. one  for  "north" and the one for "capital"), because this is a single
  105. name consisting of two characters.  In the  modern  horizontal  style,
  106. both go horizontally. This is not a win for readability, as it entails
  107. a loss of useful information.
  108.  
  109. > This is becoming an unfortunate necessity.  The only alternatives I see are
  110.  
  111. In some cases, perhaps.  But code fragments like:
  112.     }
  113.         else
  114.     }
  115. are pretty much inexcusable. The amount of text that I can examined at
  116. once  is pretty much limited to what I can fit into a window, and this
  117. sort of coding practice effectively minimizes what fits into a window.
  118. It  thus  cuts  down  on  the  amount of code that I can see (and thus
  119. understand) at any given time.   A  reader-friendly  programmer  would
  120. condense  these  three lines to one, and increase by two the number of
  121. lines that will fit in a window.
  122.  
  123. >     1) Go back to simpler problem spaces and simpler solution spaces.
  124.  
  125. In many cases, "divide and conquer" is still a useful approach.  As  I
  126. recall,  it  was  Al  Einstein who suggested that everything should be
  127. made as simple as possible, but no simpler.  (I wonder if this was his
  128. original concept, or if he got it from someone else.)
  129.  
  130. >     2) Use shorter, less mnemonic names and consequently suffer more
  131. >         confusion and name collisions.
  132.  
  133. This depends. Perhaps it's my math background speaking, but very often
  134. I  find  code  much  more  readable if the little local variables have
  135. names like "i", "j", or "n", rather than things like "loop_counter" or
  136. "current_line" or "number_of_items_left_to_do".
  137.  
  138. >     3) Put fewer but wider windows on the screen and blow off the
  139. >         punchcard metaphor once and for all.
  140.  
  141. Very good idea.  But current coding practice would encourage a lot  of
  142. tall,  skinny  windows.  You often need 50 or 60 lines to display what
  143. could more easily be understood with half as many horizontal lines.
  144.  
  145. > ...  In Perl 5, I'm making => a synonym for comma, so you can
  146. > say things like:
  147. >     $childmess = &Get(
  148. >             OC           => $oc,
  149. >             OI           => $oi,
  150. >             SCOPE        => $scope1,
  151. >             ATTR_ID_LIST => $no_attrs);
  152.  
  153. > As someone pointed out earlier, all you do is stuff the list into an
  154. > associative array, and then pull out the parameters in the order you
  155. > like.  If you don't think this is a win, note that the actual
  156. > &new_GetReq call has 14 arguments, but most of them have defaults or
  157. > can be undefined:
  158.  
  159. This doesn't look like => is a synonym for a comma; it looks like  you
  160. are using named (keyword) style parameters.  This strikes me as a Very
  161. Good Idea ...  How soon can we all get this release?
  162.  
  163. > So, would you rather call &Get, or &new_GetReq?
  164.  
  165. Well, while I understand the need  for  more  complicated  names,  the
  166. trouble  is  that  I  find it rather difficult to type things like the
  167. latter correctly.  The sequence "_G" is especially awkward on a qwerty
  168. keyboard.  And when writing X-Windows code, I often find that the only
  169. way to get the names spelled right are to  cut  and  paste,  which  is
  170. frustratingly  slow,  but faster than typing it wrong and not noticing
  171. until the thing I typed  comes  up  undefined,  and  looking  for  the
  172. undefined symbol but typing it wrong on the grep command ...
  173.  
  174. I don't think I'm the only one with this problem. I've looked over the
  175. shoulder  of various people writing X code, and I've noticed that most
  176. of them make heavy use of cut-and-paste to "type" the  names  of  many
  177. things.   Most  of them also use "man -k" a lot to find the names that
  178. they can't quite remember how to spell.  This is not a very  efficient
  179. use of human time.
  180.  
  181. > ... And if you really
  182. > detest vertical alignment, you often have a better chance to fit it
  183. > onto one line with named parameters than with positional parameters:
  184.  
  185. >     $childmess = &Get(OC=>$oc, OI=>$oi, SCOPE=>$scope1, ATTR_ID_LIST=>$no_attrs);
  186.  
  187. > Shoot, almost made it...  :-)
  188.  
  189. Sounds like a win to me. Actually, I think it'd be more readable, more
  190. mnemonic, and might even fit, if you used ':' instead of '=>'. Perhaps
  191. that's another bit of trivia that could be worth a violent argument or
  192. three.  Would this conflict with other uses of ':'?
  193.  
  194. So when will version 5 be released to the unsuspecting world? Should I
  195. not bother upgrading to 4.whatever.35?
  196.  
  197. --
  198. All opinions Copyright (c) 1992 by John Chambers. Inquire for licensing at:
  199. 1-617-647-1813 ...!{bu.edu,harvard.edu,eddie.mit.edu,ruby.ora.com}!minya!jc 
  200. --
  201. Pensu tutmonde; agu loke.
  202. -- 
  203. All opinions Copyright (c) 1992 by John Chambers. Inquire for licensing at:
  204. 1-617-647-1813 ...!{bu.edu,harvard.edu,eddie.mit.edu,ruby.ora.com}!minya!jc 
  205. --
  206. Pensu tutmonde; agu loke.
  207.