[M3devel] A question for our language lawyers
Rodney M. Bates
rodney_bates at lcwb.coop
Fri Jul 6 20:27:28 CEST 2012
On 07/06/2012 04:23 AM, Dirk Muysers wrote:
> The report says (2.6.9)
> "The values in the array will be arbitrary values of their type."
> Now, ParseParams in its "init" method allocates an array of BOOLEANs
> and relies on the fact that it is supposedly initialised with FALSE values.
> At the other hand the report says (2.2.4)
> "The constant |default| is a default value used when a record is constructed or allocated"
> If I allocate an array of records, which statement is stronger:
> - the array contains arbitray record values ?
> - the array record fields will be initialised to their default values?
Admittedly unclearly if not misleadingly worded. Better wording might be
to say each element is initialized as it would if it were a scalar variable
of its type.
I think the way to interpret this is that the array itself does not impose
any initialization, but this fact will not eliminate initialization
imposed by other rules, specifically, the type of the array's elements.
This is a language quirk that I have always been deeply ambivalent about.
The type safety would go down the drain if variables were not initialized
to a bit pattern that represents some value of the type, so we have to pay
the performance penalty of executing initialization code. So why not define
which value of the type is initialized-to and get behavioral predictability
for free? And further save redundant initialization in the likely event
that the compiler's chosen arbitrary value happens to match what the
programmer wants?
(OK, a smart enough optimizer might figure this out, but we could have
had it even with a naive compiler.)
The contrary case is a type whose compiler-chosen representation happens
to use every bit pattern in the allocated space for a value of the type.
Here, no compiler-generated runtime initialization is needed.
Also, the rule we have might sometimes encourage programmers to at least give a
millisecond's thought to whether they need to do some explicit initialization.
> The ParseParams "init" method is obviously erroneous and works only
> by virtue of a happy combination of circumstances.
> But how is the report to be interpreted in the second case?
More information about the M3devel
mailing list