[Oberon] Coding practice [Was: Re: Hennessy.Mod 64kB limit]

Frans-Pieter Vonck fp at vonck.nl
Thu Feb 20 16:27:28 CET 2020


I also find the multi-statement lines challenging to read.
My "human parsing" seems to be conditioned on reading from the the top 
down, with a maximum of 3? statements per line.
I feel comfortable when WHILE, FOR, REPEAT are positioned at the 
beginning of a sentence.

In the Oberon07 report you find that the initialization for a WHILE loop 
is done like this.
>   i := 0; WHILE s[i] # 0X DO INC(i) END;
i := 0;
WHILE s[i] # 0X DO INC(i) END;

> s := topscope; WHILE (s # NIL) & (s.name # “SYSTEM“) DO s := s.next 
> END;
s := topscope;
WHILE (s # NIL) & (s.name # “SYSTEM“) DO s := s.next END;

So de initialization before the loop is always on a single line , like 
you show here
> I write
>    i := 0; j := 345; quit := FALSE;
>    REPEAT


Jörg schreef op 2020-02-19 09:28:
> A word on why I use multi-statement lines:
> I mostly code along these two rules, if possible
> 1) to grasp the idea of a procedure it has to fit on a page. I mean
> you should not have to scroll to know whats going on.
> 2) Logical things should stay together
> There are always exceptions and I decide on a per case basis whether I
> start a new line or not.
> 
> To explain what I mean: before entering a loop you normally have to
> initialize things.
> If possible and not too complicated, I put all initializations on the 
> same line.
> 
> Instead of
>    i := 0;
>    j := 345;
>    quit := FALSE;
>    REPEAT
>     ...
> 
> I write
>    i := 0; j := 345; quit := FALSE;
>    REPEAT
>    ...
> 
> When I have a short loop (eg searching for an object) I put everything
> on one line
> Instead of
>   i := 0;
>   WHILE s[i] # 0X DO
>      i := i + 1
>    END;
> I write
>   i := 0; WHILE s[i] # 0X DO INC(i) END;
> or a little longer but (in my point of view) still readable.
>   s := topscope; WHILE (s # NIL) & (s.name # “SYSTEM“) DO s := s.next 
> END;
> Or
>   IF a[i] > a[i+1] THEN temp := a[i]; a[i] := a[i+1]; a[i+1] := temp 
> END;
> 
> For me, a line is more like a “logical block“ instead of “one 
> statement“.
> I don‘t force anybody to do it the same.
> 
> br
> Jörg
> 
>>> Am 18.02.2020 um 18:45 schrieb August Karlstrom 
>>> <fusionfile at gmail.com>:
>> 
>>> On 2020-02-18 17:26, Skulski, Wojciech wrote:
>>> I am not questioning the code. I am questioning the coding practice:
>>> avoiding any comments and writing bit masks explicitly in hex.
>> I'm also a bit curious about the practice of putting several statement 
>> on the same line. This is something I have not seen in other 
>> languages. Is this simply "the Swiss way" of saving lines? To me it 
>> makes the logic harder to follow.
>> 
>> -- August
>> --
>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related 
>> systems
>> https://lists.inf.ethz.ch/mailman/listinfo/oberon
> 
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related 
> systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon


More information about the Oberon mailing list