[Issue 1961] Allow "scoped const" contracts

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 1 07:15:28 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1961





------- Comment #5 from aarti at interia.pl  2008-04-01 09:15 -------
> And enum... you'll have to yank that out from my dead cold hands. Extending
> enum instead of adding yet another way of defining symbolic constants is The
> Right Thing to do. I am sure people would have realized how ridiculous the
> whole "manifest" thing is if we first proposed it. We just can't define one
> more way for each kind of snow there is.

While I agree completely with what you said about 'manifest' keyword, I quite
don't agree about choosing 'enum' as word for manifest constant. IMHO there is
much better keyword for this purpose: 'alias'.

Please notice that using 'alias' will be very consistent:
1. Alias defines new symbols. Literals (e.g true, false, [], "text")are in fact
also symbols as they don't have its address. They exists only inside compiler.
So both are of 'same kind'. Personally I think about them as "#define" from C.

2. It seems that there will be also alias syntax like below (as you suggested
in [1] comment #4):
alias TRUE = true;
So there will be no real difference between 'enum' and 'alias' as a way of
defining manifest constants. Two ways to define same think seems just one too
much.

3. Enum can retain its previous meaning as a way to define *collection*. Please
notice that not every set of manifest constant creates collection. Also there
can possibly be collections of different things than manifest constants e.g.
collections of variables. So there is many ways to extend meaning of enum to
make it more programmer friendly and useful. That said I think that enum should
only define subset of all manifest constant usages - manifest constants which
can be ordered into collection.

If alias will be extended to syntax 'alias TRUE=true;' (which seems to be right
thing) then there is no way to avoid completely duplication of functionality
between 'enum' and 'alias'. But IMHO better way is to specialize 'enum' to mean
collection (in specific case collection of manifest constant) and 'alias' to
mean definition of symbol.

Sorry for being a bit off topic. I can put it into new enhancement req. if you
wish.

[1] I suggested it already in enhancement request 1827# .
http://d.puremagic.com/issues/show_bug.cgi?id=1827


-- 



More information about the Digitalmars-d-bugs mailing list