[Oberon] A first experience with obc
    Chris Burrows 
    chris at cfbsoftware.com
       
    Tue Dec  7 01:57:28 CET 2010
    
    
  
>-----Original Message-----
>From: Jan Verhoeven [mailto:jan at verhoeven272.nl] 
>Sent: Tuesday, 7 December 2010 10:29 AM
>To: Oberon List
>Subject: [Oberon] A first experience with obc
>
>Hi friends,
>
>Here http://fruttenboel.verhoeven272.nl/obc/triples.html is a 
>first experience with the obc compiler.
>It may also be used by people getting to know Oberon (like I 
>am doing right now).
>
Good work! A couple of programming style recommendations I would make are:
1. BOOLEAN expressions
----------------------
PROCEDURE IsDigit (chr	: CHAR) : BOOLEAN;
BEGIN
  IF  chr < '0'  THEN  RETURN FALSE  END;
  IF  chr > '9'  THEN  RETURN FALSE  END;
  RETURN TRUE
END IsDigit;
It is not a good idea to get into the habit of having multiple exits from a
procedure. In this case they are unnecessary as the recommended Pascal /
Modula-2 / Oberon programming style would result in:
PROCEDURE IsDigit(ch: CHAR): BOOLEAN;
BEGIN
  RETURN (ch >= '0') & (ch <= '9') 
END IsDigit;
This use of a BOOLEAN expression is a variation of an example given in the
original Jensen and Wirth "Pascal User Manual and Report":
-----------------------------------------
If "found" is a variable of type Boolean, another frequent abuse of the if
statement can be illustrated by:
  if a=b then found := true else found := false
A much simpler statement is:
  found := a=b
-----------------------------------------
2. Loop Statements
------------------
LOOP with its arbitary exit points should only be used for the
loop-and-a-half situations if and ONLY IF a WHILE, REPEAT and FOR loop is
unsuitable. e.g.
  LOOP
    IF  this = NIL  THEN  EXIT  END;
    ...
    ...
    this := this.next
  END;
should be written as:
  WHILE this # NIL DO
    ...
    ...
    this := this.next
  END;
Regards,
Chris
Chris Burrows
CFB Software
http://www.cfbsoftware.com
    
    
More information about the Oberon
mailing list