[fpc-pascal] Default record fields

leledumbo leledumbo_cool at yahoo.co.id
Sat Jun 23 10:09:12 CEST 2018


> My thinking was that because variables can assign values at declaration it
would be reasonable to assume that record fields could have default values
which would be assigned at declaration. It sounds like a natural extension
of the syntax that already exists. 

Those are two different things actually: Declaration time initialization for
variables vs default record field values. The former doesn't cause confusion
because the value and the variable are in the same place, but the latter
does, as Sven said: "On the other hand to know whether the fields are
initialized or not you'd need to navigate to the type which means leaving
your current zone of development."

Now suppose you have that feature a record type T in unit A, then a code
somewhere that uses unit A has a variable V of type T declared. How could
you be sure what value that V holds? At best you have to initialize it right
there anyway, making the default value useless. Certainly don't imagine
you're the writer of unit A who knows that T has some default values. Other
languages POV are mostly simply ease of typing, they don't think the
consequences this far.



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/



More information about the fpc-pascal mailing list