'var' and 'volatile' as !const, with invariant-by-default

David B. Held dheld at codelogicconsulting.com
Mon Jun 25 21:19:25 PDT 2007


Russell Lewis wrote:
> [...]
> * Invarant-by-default.  That is, an unadorned variable (whether it is
>   a global variable, function local, or parameter) is always invariant.
> * Use the keyword 'var' to represent a variable which can be modified.
> * Use the keyword 'volatile' to indicate that there are aliases of the
>   variable, so it is not safe to cache the value of the variable in a
>   register.
> * 'volatile' is illegal on value-types.  (Only allowed on pointers,
>   arrays, class references, etc.)
> [...]

I think a *lot* of programmers would find it onerous to decorate all 
mutable identifiers.  I think pure value-style programming is best 
enabled by a fully supported functional environment, which D does not 
quite have.  It's still fairly awkward to define lambads and currying is 
not supported to the extent that it is in mainstream FP langs.  Part of 
D's elegance is that it is not overly verbose, like Java or Ada or other 
languages.  I also think that invariant-by-default would totally 
surprise people who were told that D is an "imperative" language that is 
"a lot like C++".  Remember that a language is as much a cultural 
phenomenon as a technical one.

Dave



More information about the Digitalmars-d mailing list