home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / forth / 3716 < prev    next >
Encoding:
Internet Message Format  |  1992-12-31  |  5.0 KB

  1. Path: sparky!uunet!noc.near.net!transfer.stratus.com!sw.stratus.com!nick
  2. From: nick@sw.stratus.com (Nicolas Tamburri)
  3. Newsgroups: comp.lang.forth
  4. Subject: Re: Documenting
  5. Date: 31 Dec 1992 15:54:41 GMT
  6. Organization: Stratus Computer, Inc.
  7. Lines: 110
  8. Distribution: world
  9. Message-ID: <1hv541INN82t@transfer.stratus.com>
  10. References: <C03sAB.MoB@starnine.com> <1992Dec31.112348.12448@sol.ctr.columbia.edu>
  11. NNTP-Posting-Host: osa.sw.stratus.com
  12.  
  13. In article <1992Dec31.112348.12448@sol.ctr.columbia.edu>, penev@venezia (Penio Penev) writes:
  14. > Mike Haas (mikeh@starnine.com) wrote:
  15. > : > From: MARK VANDITTA
  16. > : >
  17. > : > Is it my imagination, or do most Forth programmers lack formal
  18. > : > instruction in structured coding?
  19.  
  20. Unless you are using 'structured coding' in a matter with which I am not familiar,
  21. it is your imagination.  Forth is a very structured language where you have to go
  22. out of your way to be unstructured.  Most Forth programs I've read keep this
  23. philosophy.  The rest of the message leads me to believe that you mean coding
  24. style:
  25.  
  26. > : > Here's an example from
  27. > : > Frank Sargent's Pygmy:
  28. > : >
  29. > : > CODE 0branch HERE T0BR !
  30. > : >  AX LODS, DI BX CMP, 0=, IF, AX SI MOV, THEN, BX POP,
  31. > : >  NXT,   END-CODE
  32. > : >
  33. > : > Now I really like what Frank has done with Pygmy, but his coding
  34. > : > style leaves a lot to be desired.  I had to reformat his code to
  35. > : > be able to follow its structure.
  36. > : >
  37. > : > CODE 0branch
  38. > : >     HERE T0BR !
  39. > : >     AX LODS,
  40. > : >     DI BX CMP,
  41. > : >     0=, IF,
  42. > : >         AX SI MOV,
  43. > : >     THEN,
  44. > : >     BX POP,
  45. > : >     NXT,
  46. > : > END-CODE
  47. > : >
  48. > : > Granted, I used 10 lines instead of 3, but it is now clear to me
  49. > The same could de _indented_ this way:
  50. > CODE 0branch    HERE T0BR !
  51. >     AX LODS,   DI BX CMP,   0=, IF,  AX SI MOV,  THEN, 
  52. >     BX POP,   NXT,   END-CODE
  53. > There is really no need to have the commas  after the ASSEMBLER words
  54. > and NXT can be a macro, which does the END-CODE. With the definitions
  55.  
  56. I've always understood the comma as being a convention for those words which
  57. compile data into the dictionary and bump HERE, (if HERE still applies...)  In which
  58. case, the comma is not needed (as with all syntactic fluff,) but useful.
  59.  
  60. But you miss the point:  My first assembler allowed me to put multiple instructions
  61. on a single line.  If I had done that in product source,  my hands would have been
  62. cut off at the wrists :-)    This is not just a matter of putting multiple spaces
  63. between code phrases to enhance readability. The rest of the line is meant for
  64. COMMENTS.  This is especially true (and practically universal) for assembler code.
  65. The only argument to the contrary was put forth (NPI) by Brodie in "Thinking Forth"
  66. namely that lots of comments don't necessarily mean a good commenting style if
  67. they are of the "Put 1 in the AC..." variety. I agree, but I'm talking about
  68. useful comments in this discussion.
  69.  
  70. Mike is absolutely correct:  Screen vs. File wars not withstanding, this coding
  71. style IS a direct result of growing up with screens.  By the time you have indentation,
  72. the instruction, and tabbing to the comment column, you may get 32 chars of comments,
  73. unless you want to continue to the next line making things even uglier.  Why bother?
  74. In older systems where a screen was always 1K of storage, no matter how much text
  75. was in it, you didn't generally like to waste disk storing 1 definition per screen
  76. so you could do pretty indentation of each instruction.
  77.  
  78. It's about time we moved away from it, especially where CODE words are concerned.
  79. I wouldn't mind seeing this happen to some higher level definitions as well.
  80.  
  81. > [Sample code sections deleted.]
  82.  
  83. They were very clear to me,  but the original writer appeared to be a novice
  84. trying to learn the language.  Perhaps he can tell us how clear they were to him.
  85.  
  86. > You don't have to wory about about packing as much info in the screen
  87. > either. One screen can hold 5 to 12 words (subroutines). This is
  88. > enormous amount of info. The equivalent amount in C is more, that You
  89. > can fit even on today workstations' 17" screens. Consider the overhead
  90. > in C:
  91. > procname(args) { 
  92. >     variables declaration;
  93. >     body
  94. > }  
  95. > Empty line
  96. > You have four lines per entry, which cary basically no information.
  97.  
  98. Not to defend C for readability, but I consider the procedure name and
  99. variable declarations useful, if not vital, information when looking at a program.
  100. In any case, you can feel right at home with C by reformatting the above program to:
  101.  
  102. procname(args){  variables declaration;  body  }
  103.  
  104. (Note multiple spaces between significant program sections.)
  105.  
  106. For short routines, this should be perfectly acceptable.  Don't bother with the
  107. empty lines between definitions, if you want to stick to the convention in your
  108. sample screens.
  109.  
  110. [Lots of other screen justification and sample code deleted.]
  111.  
  112. I'm not denying screens are useful, and I definitely do not want to start yet
  113. another war.  But to deny what Mike said about the evolution of the coding style
  114. as it relates to screens is to deny the obvious, and that is really what this
  115. discussion is about.
  116.  
  117.                                 /nt
  118.