Extended Type Design.
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Fri Mar 16 12:02:20 PDT 2007
Andrei Alexandrescu (See Website For Email) wrote:
> Benji Smith wrote:
>> I vote for "readonly" and "const". Anything else seems like a mistake.
>
> Which is which? How would you have people distinguish them without
> running to the manual? How would you explain C++ immigrants that const
> is actually readonly, and there is a const, but that const means
> something else than their const?
How would you have people distinguish char/wchar/dchar without running
to the Unicode standard to see which characters they can hold in a
single unit?
Or short/int/long or float/double/real without running to the standard
to look up the ranges and precision of those data types?
How would you explain to the average person from the
Netherlands/Estonia/Finland/Germany/Slovakia[1] 'auto' doesn't have
anything to do with transportation?
How would you explain to Dutchmen that 'long' doesn't have anything to
do with breathing air? (Hint for all you foreigners out here: the Dutch
word 'long' translates to 'lung' :P )
Some things are somewhat arbitrary conventions.
When you learn a new language, some words will mean different things,
with other words that have the meaning you're used to.
It happens ;).
[1]: See http://dictionary.reference.com/search?q=car , specifically the
first set of translations, roughly halfway down the page
Seriously though:
"readonly" would mean that you (meaning any code that can access the
symbol so declared) can only read data referenced through it, but
someone else _may_ be able to write to it[2].
"const" would mean it's just that: constant. *Nobody* can write to it.
Seems pretty easy to explain to me.
The only caveat I see is that "readonly" would mean the object itself
can still be modified, as opposed to final. I don't see how calling it
"const" would fix that, though.
[2]: Or of course that same code may be able to write to it, if for
whatever reason it also has access to a mutable reference to the same data.
More information about the Digitalmars-d
mailing list