From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie)
Newsgroups: comp.lang.forth
Subject: Documenting
Date: 29 Dec 92 11:46:12 GMT
Organization: EIEI-U

Category 3,  Topic 3
Message 8         Mon Dec 28, 1992
ELLIOTT.C                    at 12:26 EST
 
 ----via CRS Premium Bulletin Board -
  USR Dual Standard 16.8K  (416) 629-7000

 Date: 12-19-92 (13:38)
   To: ALL
 From: MARK VANDITTA
 Subj: FORTH CODING STYLE

 Is it my imagination, or do most Forth programmers lack formal
 instruction in structured coding?  I have found that most Forth
 programmers write code that is even more unlegible than that of C
 programmers raised on DEC Writers.  Why do Forth programmers
 insist on packing so many words on a single line at the sacrifice
 of clarity?  I like Forth, but I cannot tolerate most Forth
 programmer's coding styles. In other lanuages such as Algol,
 PL/I, Pascal, Ada, and C, most formally trained programmers use
 indentation to set off control structures.  I have yet to see any
 non-trivial Forth program written using indentation to show flow
 of control.  It has been proven that indentation leads to code
 that is easier to read and maintain.  Here's an example from
 Frank Sargent's Pygmy:

 CODE 0branch HERE T0BR !
  AX LODS, DI BX CMP, 0=, IF, AX SI MOV, THEN, BX POP,
  NXT,   END-CODE

 Now I really like what Frank has done with Pygmy, but his coding
 style leaves a lot to be desired.  I had to reformat his code to
 be able to follow its structure.

 CODE 0branch
     HERE T0BR !
     AX LODS,
     DI BX CMP,
     0=, IF,
         AX SI MOV,
     THEN,
     BX POP,
     NXT,
 END-CODE

 Granted, I used 10 lines instead of 3, but it is now clear to me
 where the definition starts and ends as well as that the
 instruction "AX SI MOV," is executed only if DI = BX.  With the
 cost of machines dropping and the cost of personnel rising, It
 makes sense to me to trade disk space for ease of maintenance.  I
 had the opportunity the other week to introduce Forth to a few C
 bigot friends of mine.  They all thought it was a neat language,
 but they likened it to APL.  They called it a write only language
 because they thought it was easier to rewrite a Forth program
 than it was to read and modify the existing one.

 NET/Mail : RCFB Golden, CO (303) 278-0364 VESTA & Denver FIG for
 Forth! ---
  * The GrapeVine/Ferret Face BBS * NLR,ARK * 501-753-8121 DS *
  * PostLink(tm) v1.04  GRAPEVINE (#318) : RelayNet(tm) Hub

  BBS: CRS Premium Bulletin Board -
 USR Dual Standard 16.8K  (416) 629-7000
 Date: 12-20-92 (23:00)
   To: MARK VANDITTA
 From: STEVE WHEELER
 Subj: FORTH CODING STYLE

 -> Is it my imagination, or do most Forth programmers lack formal
 -> instruction in structured coding?  I have found that most
 Forth -> programmers write code that is even more unlegible than
 that of C -> programmers raised on DEC Writers.  Why do Forth
 programmers insist -> on packing so many words on a single line
 at the sacrifice of -> clarity?  I like Forth, but I cannot
 tolerate most Forth programmer's -> coding styles. In other
 lanuages such as Algol, PL/I, Pascal, Ada, -> and C, most
 formally trained programmers use indentation to set off ->
 control structures.  I have yet to see any non-trivial Forth
 program -> written using indentation to show flow of control.  It
 has been -> proven that indentation leads to code that is easier
 to read and -> maintain.

 It's probably your imagination. Forth is an inherently structured
 language. You're confusing code structure and code layout. There
 is a difference. As to why Forth code often uses that particular
 layout, it's an artifact of using "screens" containing 16 lines
 of 64 characters for source code. Programmers who use text files
 for source code tend to  use a more "vertical" style you would
 probably find more appealing.

 There are tradeoffs involved in the choice of source code format.
 I prefer text files, because I like to have the program flow
 shown by indenting, and because text files allow me to use more
 comments. However, I have to think more about what I'm doing to
 avoid getting single Forth words which cover too many lines. When
 you use screen files, you are to some extent forced by the format
 to limit the size of your definitions. You also tend to produce a
 "horizontal" format of code, because you want to use your screens
 efficiently. Screen files also allow loading individual screens,
 where text files usually require a total reload to finish
 compiling after an error in the middle of the file.

 As to Forth being a write-only language, my personal feeling is
 that no language (with the possible exceptions of APL and some
 macro generators I've used) are inherently write-only. It's the
 programmers who make it appear so.  I've seen C source code I
 consider unreadable, assembly code which was crystal-clear
 because of proper comments and beautiful use of macros, and Forth
 code which was written by a BASIC programmer which looked like an
 ancient BASIC (two-character names, 80-line definitions, no
 useful comments). I've also seen some C code I consider properly
 commented and with useful variable names, assembly code which was
 total garbage as far as understandability, and Forth source which
 reads like a good book.

 Anyone who judges a language solely on the appearance of code
 written by others does that language an injustice. I personally
 like the way the C code I write looks. I know other programmers
 who would shudder at my code because it isn't "clean enough"
 (read terse). Each language has a culture, with an unofficial but
 widely-approved method of writing and laying out code. With
 Forth, the problem is that the language is extensible, and
 determining the names to give functions is a personal matter
 affected by the programmer's experience, background, taste, and
 predilections. C has the same problems, but not as severely since
 it is not extensible. If it didn't have these problems, there
 would be no need for C beautifiers. It's just a matter of what
 you're used to.

 This has been a long message, and it's time for me to get down
 off my high horse. I hope you find something useful here.

 - wheels

 NET/Mail : RCFB Golden, CO (303) 278-0364 VESTA & Denver FIG for
 Forth! ---
  * The GrapeVine/Ferret Face BBS * NLR,ARK * 501-753-8121 DS *
  * PostLink(tm) v1.04  GRAPEVINE (#318) : RelayNet(tm) Hub



-----
This message came from GEnie via willett.  You *cannot* reply to the author
using e-mail.  Please post a follow-up article, or use any instructions
the author may have included (USMail addresses, telephone #, etc.).
Report problems to: dwp@willett.pgh.pa.us