[Oberon] R: Should one automatically initalize local pointer or procedure variables (safety precaution)?

Skulski, Wojciech skulski at pas.rochester.edu
Tue Mar 5 15:32:00 CET 2019


Oliver:

> IMHO automatic pointer initialization is against the Oberon spirit not to have hidden features.

If the feature is declared in the language report, or in the compiler documentation, then it is not hidden. 

A usual compromise in other languages is to make a given feature optional. Compilers usually have "switches" and Oberon compiler is no exception. It has the "+" switch to switch on special compilation features for a module or a procedure. It also has the /s switch. In that sense the Oberon compiler is not innocent. On the other hand, it is not indecent. The boundary between innocence and indecency is a matter of taste, experience, and belief. I doubt it can be drawn to satisfy everybody.

> Not only against „hidden features“, but also against the strict declare-initialise-use paradigm emphasised by Niklaus Wirth ;) 

If one has NW discipline then one is going to write perfect code no matter what. But not everyone has such a discipline. 

> And also somewhat against „locality of code“, as you should „initialise your variables as late as possible (but not later)“, or in other words: initialisation should happen as close as possible to actual use (e.g. right before some loop).

Definitely the case with index variables. But here we are discussing pointers.  How often do you use a pointer to index a loop? It is not even possible. List traversal is a sort of the loop and Stefano's example is a good one. So one has to weigh a minor optimization (avoidance of automatic pointer initialization) versus improved safety. I heard more than once that safety should go first. 

So my taste, experience, and belief makes me vote for automatic pointer initialization, possibly optional and turned on/off with a switch.

Thank you,
Wojtek


More information about the Oberon mailing list