Const sucks

Regan Heath regan at netmail.co.nz
Tue Sep 11 10:50:03 PDT 2007


Janice Caron wrote:
>> Hmmmm... if I got that right, macros will definitely *not* be "pieces
>> of text", but abstract syntax trees.
> 
> Macros have their place. I'm not knocking them. But they're not the
> right mechanism for declaring constants. On the other hand,
> 
> const Type name = value;
> is.
> 
> (replace const with static if necessary - see earlier in thread).
> 
> Of course, it really should be
> invariant Type name = value;
> 
> with the current keywords, though if we switch from invariant/const to
> const/readonly that mistake will likely disappear.
> 
> 
>> So, if you'd do "macro x=5;" (or whatever the macro syntax will be),
>> and you try `char[] s="abc"~x;` you'll get a nice, clean type error.
> 
> Looks the same as C to me.
> 
> #define x 5
> strcat(s,"abc");
> strcat(s,x); /* compile error */
> 
> That doesn't count as strong typing.

You're jumping to conclusions here.  I doubt _very_ much that Walter 
plans to implement macro like #define in C.  Especially after all the 
trouble he went through to remove the preprocessor completely.

Regan



More information about the Digitalmars-d mailing list