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

  1. Path: sparky!uunet!gatech!pitt.edu!pitt!willett!ForthNet
  2. From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie)
  3. Newsgroups: comp.lang.forth
  4. Subject: Documenting
  5. Message-ID: <4195.UUL1.3#5129@willett.pgh.pa.us>
  6. Date: 29 Dec 92 11:46:12 GMT
  7. Organization: EIEI-U
  8. Lines: 146
  9.  
  10. Category 3,  Topic 3
  11. Message 8         Mon Dec 28, 1992
  12. ELLIOTT.C                    at 12:26 EST
  13.  
  14.  ----via CRS Premium Bulletin Board -
  15.   USR Dual Standard 16.8K  (416) 629-7000
  16.  
  17.  Date: 12-19-92 (13:38)
  18.    To: ALL
  19.  From: MARK VANDITTA
  20.  Subj: FORTH CODING STYLE
  21.  
  22.  Is it my imagination, or do most Forth programmers lack formal
  23.  instruction in structured coding?  I have found that most Forth
  24.  programmers write code that is even more unlegible than that of C
  25.  programmers raised on DEC Writers.  Why do Forth programmers
  26.  insist on packing so many words on a single line at the sacrifice
  27.  of clarity?  I like Forth, but I cannot tolerate most Forth
  28.  programmer's coding styles. In other lanuages such as Algol,
  29.  PL/I, Pascal, Ada, and C, most formally trained programmers use
  30.  indentation to set off control structures.  I have yet to see any
  31.  non-trivial Forth program written using indentation to show flow
  32.  of control.  It has been proven that indentation leads to code
  33.  that is easier to read and maintain.  Here's an example from
  34.  Frank Sargent's Pygmy:
  35.  
  36.  CODE 0branch HERE T0BR !
  37.   AX LODS, DI BX CMP, 0=, IF, AX SI MOV, THEN, BX POP,
  38.   NXT,   END-CODE
  39.  
  40.  Now I really like what Frank has done with Pygmy, but his coding
  41.  style leaves a lot to be desired.  I had to reformat his code to
  42.  be able to follow its structure.
  43.  
  44.  CODE 0branch
  45.      HERE T0BR !
  46.      AX LODS,
  47.      DI BX CMP,
  48.      0=, IF,
  49.          AX SI MOV,
  50.      THEN,
  51.      BX POP,
  52.      NXT,
  53.  END-CODE
  54.  
  55.  Granted, I used 10 lines instead of 3, but it is now clear to me
  56.  where the definition starts and ends as well as that the
  57.  instruction "AX SI MOV," is executed only if DI = BX.  With the
  58.  cost of machines dropping and the cost of personnel rising, It
  59.  makes sense to me to trade disk space for ease of maintenance.  I
  60.  had the opportunity the other week to introduce Forth to a few C
  61.  bigot friends of mine.  They all thought it was a neat language,
  62.  but they likened it to APL.  They called it a write only language
  63.  because they thought it was easier to rewrite a Forth program
  64.  than it was to read and modify the existing one.
  65.  
  66.  NET/Mail : RCFB Golden, CO (303) 278-0364 VESTA & Denver FIG for
  67.  Forth! ---
  68.   * The GrapeVine/Ferret Face BBS * NLR,ARK * 501-753-8121 DS *
  69.   * PostLink(tm) v1.04  GRAPEVINE (#318) : RelayNet(tm) Hub
  70.  
  71.   BBS: CRS Premium Bulletin Board -
  72.  USR Dual Standard 16.8K  (416) 629-7000
  73.  Date: 12-20-92 (23:00)
  74.    To: MARK VANDITTA
  75.  From: STEVE WHEELER
  76.  Subj: FORTH CODING STYLE
  77.  
  78.  -> Is it my imagination, or do most Forth programmers lack formal
  79.  -> instruction in structured coding?  I have found that most
  80.  Forth -> programmers write code that is even more unlegible than
  81.  that of C -> programmers raised on DEC Writers.  Why do Forth
  82.  programmers insist -> on packing so many words on a single line
  83.  at the sacrifice of -> clarity?  I like Forth, but I cannot
  84.  tolerate most Forth programmer's -> coding styles. In other
  85.  lanuages such as Algol, PL/I, Pascal, Ada, -> and C, most
  86.  formally trained programmers use indentation to set off ->
  87.  control structures.  I have yet to see any non-trivial Forth
  88.  program -> written using indentation to show flow of control.  It
  89.  has been -> proven that indentation leads to code that is easier
  90.  to read and -> maintain.
  91.  
  92.  It's probably your imagination. Forth is an inherently structured
  93.  language. You're confusing code structure and code layout. There
  94.  is a difference. As to why Forth code often uses that particular
  95.  layout, it's an artifact of using "screens" containing 16 lines
  96.  of 64 characters for source code. Programmers who use text files
  97.  for source code tend to  use a more "vertical" style you would
  98.  probably find more appealing.
  99.  
  100.  There are tradeoffs involved in the choice of source code format.
  101.  I prefer text files, because I like to have the program flow
  102.  shown by indenting, and because text files allow me to use more
  103.  comments. However, I have to think more about what I'm doing to
  104.  avoid getting single Forth words which cover too many lines. When
  105.  you use screen files, you are to some extent forced by the format
  106.  to limit the size of your definitions. You also tend to produce a
  107.  "horizontal" format of code, because you want to use your screens
  108.  efficiently. Screen files also allow loading individual screens,
  109.  where text files usually require a total reload to finish
  110.  compiling after an error in the middle of the file.
  111.  
  112.  As to Forth being a write-only language, my personal feeling is
  113.  that no language (with the possible exceptions of APL and some
  114.  macro generators I've used) are inherently write-only. It's the
  115.  programmers who make it appear so.  I've seen C source code I
  116.  consider unreadable, assembly code which was crystal-clear
  117.  because of proper comments and beautiful use of macros, and Forth
  118.  code which was written by a BASIC programmer which looked like an
  119.  ancient BASIC (two-character names, 80-line definitions, no
  120.  useful comments). I've also seen some C code I consider properly
  121.  commented and with useful variable names, assembly code which was
  122.  total garbage as far as understandability, and Forth source which
  123.  reads like a good book.
  124.  
  125.  Anyone who judges a language solely on the appearance of code
  126.  written by others does that language an injustice. I personally
  127.  like the way the C code I write looks. I know other programmers
  128.  who would shudder at my code because it isn't "clean enough"
  129.  (read terse). Each language has a culture, with an unofficial but
  130.  widely-approved method of writing and laying out code. With
  131.  Forth, the problem is that the language is extensible, and
  132.  determining the names to give functions is a personal matter
  133.  affected by the programmer's experience, background, taste, and
  134.  predilections. C has the same problems, but not as severely since
  135.  it is not extensible. If it didn't have these problems, there
  136.  would be no need for C beautifiers. It's just a matter of what
  137.  you're used to.
  138.  
  139.  This has been a long message, and it's time for me to get down
  140.  off my high horse. I hope you find something useful here.
  141.  
  142.  - wheels
  143.  
  144.  NET/Mail : RCFB Golden, CO (303) 278-0364 VESTA & Denver FIG for
  145.  Forth! ---
  146.   * The GrapeVine/Ferret Face BBS * NLR,ARK * 501-753-8121 DS *
  147.   * PostLink(tm) v1.04  GRAPEVINE (#318) : RelayNet(tm) Hub
  148.  
  149.  
  150.  
  151. -----
  152. This message came from GEnie via willett.  You *cannot* reply to the author
  153. using e-mail.  Please post a follow-up article, or use any instructions
  154. the author may have included (USMail addresses, telephone #, etc.).
  155. Report problems to: dwp@willett.pgh.pa.us
  156.