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

Joerg joerg.straube at iaeth.ch
Thu Feb 20 08:01:27 CET 2020


I don‘t think in levels I think in logical entities.

Instead of

IF a[i] > a[i+1] THEN temp := a[i]; a[i] := a[i+1]; a[i+1] := temp END;

you could have write

Swap(a[i], a[i+1]];

At runtime, the latter has the procedure call overhead that is too huge for only 2 to 3 statements. You could call my multi-statement line technique „inlining“ if you want.
But as I said I only use this technique, if the code is not too complex and you see immediately what is going on. There are a lot of programming patterns like this (swap, min/max, search loops, array initializations...)

If the code gets too complex, I either use more lines (if speed is important) or I create a procedure.

br
Jörg 

> Am 20.02.2020 um 01:24 schrieb Skulski, Wojciech <skulski at pas.rochester.edu>:
> 
> Joerg:
>> If possible and not too complicated, I put all initializations on the same line.
> 
> Example 1:
> 
>> Instead of
>   i := 0;
>   j := 345;
>   quit := FALSE;
>   REPEAT
>    ...
> 
>> I write
>   i := 0; j := 345; quit := FALSE;
>   REPEAT
>   ...
> 
> IMHO a good and reasonable example of writing a few instructions in one line.
> 
> Example 2:
> 
>> 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;
> 
> IMHO great examples why writing a few instructions in one line can be obfuscating the code and creating confusion.
> 
> The difference between Example 1 and Example 2 was that in #1 the statements were at the same level. Writing them in the same line was in agreement with this fact. Several instructions written at the same level is reflecting the fact that they logically ARE at the same level.
> 
> In Example 2 the statements are at different logical levels. Writing them in one line is obfuscating and hiding the fact that they are NOT at the same level. The content between the opening and closing instructions is one level deeper in fact, but at the same level of the text. This fact gets hidden.
> 
>> For me, a line is more like a “logical block“ instead of “one statement“.
>> I don‘t force anybody to do it the same.
> 
> There could (should?) be a difference between code written for own consumption, and the code released to the public. The latter could (should?) be kept to a more demanding standard than the former.
> 
> IMHO, Oberon System creators and supporters are in disagreement with this principle. The Oberon System code looks like it was written "for me" rather than "for others". 
> 
> I do not think that I am reinventing the wheel when I keep saying that coding standards are neither new nor widely contested, except maybe in this community. Otherwise they are well covered in textbooks, including those authored by NW.
> 
> 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.
> --
> 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