Extended Type Design.

Derek Parnell derek at nomail.afraid.org
Sun Mar 18 22:01:04 PDT 2007


On Sun, 18 Mar 2007 20:46:58 -0700, James Dennett wrote:

Walter says 
>> "'const' and 'invariant' apply to the type"

> It's just saying that "T" and "const T" are different types
> (unless T was already const); they have different permitted
> operations.

Oh?! Is that all. That is easy to understand, but it does not help me
understand how Walter sees it or 'invariant' being used.

So "int", "const int" and "invariant int" are all different types and as
such have in-built rules concerning implicit conversions etc...That's fine.
I can understand that. But what then are the built-rules? Are the rules
different for POD, Objects, and Arrays? 

> I'd have to say that I find Walter's ideas on const/final
> to be rather... distinctive... and we've debated terminology
> at some length but with no resolution.  It's his language,
> he can use terms as he wishes.  It may impede communication.

I'm fine with that too. Sure, its Walter (and Andrei's) language and that
can make up syntax and keywords as they see fit. I only hope that they get
some good documentation experts to help people like me understand it.

> This may be a case of "final" being a thing that Walter likes
> to think of as a storage class rather than a type modifier
> (though in a more general sense storage classes are just a
> special/restricted case of type modifiers).
> 
> "final", I think, is a workaround for handling types
> that are accessed through automatically-dereferenced
> GC'd pointers in D.  The auto-deref property hides the
> actual type of those pointers from us, so we can't const-
> qualify them; we just end up adding const to the type to
> which they point.  C++ doesn't work this way, and so
> const does everything that final does and more in C++.
> It's just different.  If you want indirection via a
> reference/pointer, C++ makes you say so, but gives you
> the chance to apply type modifiers to that pointer.  D
> does it invisibly, but then requires extra syntax to be
> able to stop the name being rebindable.

Interesting ... but what does all that sound like in English <G>

I don't really know C++ all that well so I don't quite get the comparisons.
Can anyone explain this without referring to other programming languages,
please? Just common everyday English would be nice - oh, but with example
<G>.

But let's see if I can translate it first ...

"storage class" means how something's value is stored in RAM. Which could
be in the data space or as immediate literals in the code space. Thus
'final' is a description of how the compiler sees the value stored in the
program. One rule is that it is impossible for any code to alter the value
associated (bound) a 'final' symbol. For all practical purposes, from the
compiler's point of view, the symbol *is* the value. When applied to
reference types, the symbol's value is the reference and not that which is
being referenced.


-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
19/03/2007 3:24:59 PM



More information about the Digitalmars-d mailing list