[Oberon] Initial value of variables, where specified?

rochus.keller at bluewin.ch rochus.keller at bluewin.ch
Wed Feb 12 23:32:17 CET 2020


@ Chris Burrows

It's ok if a language doesn't require variables to be automatically initialized; e.g. in C/C++ I can write a constructor if I want a variable to have a default value, and the compiler issues warnings if a scalar variable is used before a value was assigned.

In Pascal it is implementation dependent; there are compilers which (optionally) generate initialization code, others don't. The ISO 7185 Pascal standard explicitly states that variables are undefined after activation as far as I remember.

In case of a garbage collected language like Oberon at least pointers must have an initial value of NIL otherwise the GC is going to crash. From my point of view this should be clearly specified in the language report (even if it takes another page).

Best
R.

_______________________________
From: Chris Burrows
Sent on: Wed, 12 Feb 2020 22:37:53 +0100
To: ETH Oberon and related systems
Cc: 
Subject: Re: [Oberon] Initial value of variables, where specified?

I have always had difficulty understanding this question of initialisation.
I don't see why initialising memory areas to zero is any better than no
initialisation. It might lead to more predictable behaviour but not
necessarily correct behaviour. In the worst case it can mask the fact that a
variable has not been sensibly initialised.

e.g. Zero might be OK for initialising strings but how can you tell if an
integer that is zero has been correctly initialised? 

e.g. if a variable represents a temperature in Fahrenheit does it make sense
to initialise it to zero?

e.g. Would it be better if REAL variables were initialised to NaN?

e.g. Would it be better to initialise INTEGER values to -MAXINT?
Consequential nonsense values in calculation results might help to flush out
uninitialised variables earlier ;-)

Unless my memory fails me, the CDC6000 version of Pascal that I used in the
1970s initialised variables to a specific value which represented
'undefined'. Any attempt to reference such a variable resulted in a
(hardware?) exception. That was very useful. (Data in the CDC system was
based on a word length of 60 bits).

It is good defensive-programming practice for an Oberon programmer to ensure
that all variables they are using are explicitly initialised correctly for
the specific application that they are implementing. They should not rely on
the underlying system to initialise for them - particularly if they are
intending their application to run on different systems.

Regards,
Chris Burrows
CFB Software
https://www.astrobe.com


More information about the Oberon mailing list