Const sucks

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue Sep 11 07:17:03 PDT 2007


Daniel Keep wrote:
>> Janice Caron wrote:
>>>
>>>     It's simple, but - I would argue - the wrong choice. A better choice
>>>     (in my humble opinion) would be
>>>
>>>     const = constant
>>>     readonly = read-only
>>>
> 
> The problem is that, broadly speaking, all these words mean the same
> thing.  Once you get down to splitting hairs over exactly how
> constant/invariant/immutable/readonly/final something is, you're always
> going to find some (possibly obscure) argument against the way you want
> it to work.
> 
> Aren't natural languages fun?!

They are. The meaning of words is very domain dependent is often based 
on convention rather than anything else.

I am sorry, but I can't pass this chance to present my side of the 
argument once more. :)

To an electrical engineer, "read-only" will surely give an association 
of memory that is "hard to change quickly or easily" (wikipedia), or 
maybe read-only pins, or read-only registers.

To a mathematician, "constant" is a fixed value, the opposite of a 
"variable".

In computer science, read-only could have a number of meanings. The top 
search results on citeseer for read-only yields the following terms:

* read-only transactions
* read-only memory
* read-only file system
* read-only query
* read-only fields
* read-only methods
* read-only replication
* read-only access
* read-only parameters
* read-only actions
* read-only state
* read-only optimizations
* read-only file

of which "read-only memor(y|ies)" corresponds to a mere 3.7 % of the 
papers, while "read-only transaction(|s)" corresponds to 29 %.

The prevailing meaning of read-only in CS seems to be that in regard to 
access. Using read-only in the meaning of access will also not conflict 
with existing uses (even for an electrical engineer). On the other hand, 
using "const"(ant) in the meaning of something that may change, or is 
only access protected does conflict with the mathematical definition.

It is therefore, in my view, obvious that substituting the words 
(readonly,const) for todays (const,invariant) would result in a much 
better match between the semantics of D and that of established and 
natural languages.

The crucial separation here is:
* read-only -> access
* constant -> data

Does the following conversation make sense?

A: "I have a function that requires a read-only reference to some data"
B: "Fine, I can use it for both my variable and my constant data"

-- 
Oskar



More information about the Digitalmars-d mailing list