[comp.lang.modula2] Layout of CASE Statements

COK2@MTS.DURHAM.AC.UK (03/31/89)

I like the structure of my programs to yell themselves at me.
Hence, the layout of a program is important to me.

Here is how I have laid out CASE statements up to now:
   CASE month OF
   |  jan, mar, may, jul, aug, oct, dec:
            len:= 31
   |  feb:
            IF (year MOD 4 = 0) AND (year MOD 100 <> 0)
               THEN
                  len:= 29
               ELSE
                  len:= 28
            END
   |  apr, jun, sep, nov:
            len:= 30
   END
Note the line of | lined up between the C of CASE and the E of END.
This line helps to show the extent of the CASE statement, and
clearly shows where each arm starts.

Note that the first bar is superfluous --- it is allowed by the 3rd (and
subsequent) edtions of Wirth's "Programming in Modula-2".   The first | is
there to re-inforce the line of | characters.

Recently, I have thought of a new layout for CASE statements.
Here a row of | characters are used to separate the arms of the CASE
statement:
   CASE month OF
   jan, mar, may, jul, aug, oct, dec:
      len:= 31
   |||||||||||||
   feb:
      IF (year MOD 4 = 0) AND (year MOD 100 <> 0)
         THEN
            len:= 29
         ELSE
            len:= 28
      END
   |||||||||||||
   apr, jun, sep, nov:
      len:= 30
   END
I currently have two problems with this:
(a) how long to make the row? --- the length of the line containing CASE?
    or the length of the longest line in the CASE statement?
(b) whether to include a row of | characters both before the first arm
    and after the last arm?
==
IMPORTANT: the following are new electronic mail addresses.
==
Barry Cornelius
==
Computer Science Group, School of Engineering and Applied Science,
University of Durham, Durham, DH1 3LE, England
              JANET:       Barry.Cornelius@uk.ac.durham
              Internet:    Barry.Cornelius%durham.ac.uk@cunyvm.cuny.edu
              UUCP:        ...ukc!cs.nott.ac.uk!bjc
              BITNET/EARN: Barry.Cornelius%DURHAM@AC.UK
Tel: Durham (091 or +44 91) 374 2638, Secretary: 374 2630, Fax: 374 3741

dick@ucsfccb..ucsf.edu (Dick Karpinski) (04/01/89)

In article <INFO-M2%89033108531194@UCF1VM> Modula2 List <INFO-M2%UCF1VM.bitnet@jade.berkeley.edu> writes:
>I like the structure of my programs to yell themselves at me.
OK, try this idea (and note correction for February)

    CASE month OF

    |||| (* long months *)
       jan, mar, may, jul, aug, oct, dec:
          len := 31

    |||| (* the variable length month *)
       feb:
          IF  (year MOD   4  = 0) AND 
	     ((year MOD 100 <> 0)  OR  (year MOD 400 = 0))
             THEN
                len := 29
             ELSE
                len := 28
          END (* IF (year ... *)

    |||| (* medium size months *)
       apr, jun, sep, nov:
          len := 30

    END (* CASE month OF *)

While this uses even more whitespace than I would, myself, it seems
to shout the structure adequately and provide ample opportunity to
add commentary.  I hate unmarked ENDs.  Each case is treated in
exactly the same way so nothing need be fixed up for a new first or
last case.  The additional indentation and blank lines emphasize
the separation of cases visually.  What more could you ask?

Dick

Dick Karpinski  Manager of Minicomputer Services, UCSF Computer Center
Domain: dick@cca.ucsf.edu                      (415) 476-4529 (11-7)
BITNET:  dick@ucsfcca or dick@ucsfvm           (415) 658-6803 (Home)
USPS:  U-76 UCSF, San Francisco, CA 94143-0704 (415) 658-3797 (ans)