Const sucks

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Sep 11 13:27:48 PDT 2007


Oskar Linde wrote:
> 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"
> 

I agree. (Damn, I always agree with you Oskar :P )

But I'll add: It's not just that the "read-only" meaning as in 
"read-only access/permissions" is the most popular one. It's also the 
meaning most congruent with the natural language term "read-only". That 
is, it's the most "meaningful".
ROM memory "is" read-only in the same sense that a dear is mammal. A 
deer is indeed a mammal, but it's more than a mammal, it's... a deer. :P
It's likely due to that that the alternative terminology wouldn't sound 
so strange for an electrical engineer, while the current one sounds 
strange for (most of) us CS programmers.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list