Manifest constants (was const again)
Bill Baxter
dnewsgroup at billbaxter.com
Fri Dec 7 16:19:36 PST 2007
Simen Kjaeraas wrote:
> Bill Baxter wrote:
>>> Because it breaks with the C/C++ heritage, methinks.
>>
>> I hate to point out the obvious, but there is no "alias" in C or C++.
>> Ok, yes there's typedef in C, but if you go and completely change the
>> keyword used, I think you are justified in changing the syntax.
>
> Thank you, I'm well aware of that. My point was typedef. Having typedef
> and alias (which do /similar/ things) have vastly different syntax would
> seem strange (and break existing code). Changing both to the 'op dst =
> src' syntax might have its advantages, though.
>
>>> Anyways, is there a reason why we can't use 'alias 3.14 pi;'?
>>
>> Things like
>> alias 3.14 + ctfe_func("two") / other_constant pi;
>>
>> make that much harder to read than
>>
>> alias pi = 3.14 + ctfe_func("two") / other_constant;
>>
>> But the same is true for the current type aliases. You can see it a
>> lot in templates. There its not uncommon to see things like
>>
>> alias some long thing that eventually figures out a type Foo;
>>
>> --bb
>
> I fully agree with that. Yet that is how things are at the moment, and
> at the very least we should strive to have a consistent syntax, so you
> don't define constants using 'alias a = 4' and types using 'alias src dst'.
I think it would be a good candidate for preservation of C-ish syntax as
an aid to porting and C refugees.
Just like in D we have float[] x as the improved syntax and float x[]
as legacy syntax, we could have both "alias Y=X" as new-and-improved
and "alias X Y" as an aid to porting. As for being confusing, doing it
the wrong way is going to be a compiler error, so I don't think it's a
big deal.
> Also, like some people like to point out (me often coding in notepad
> excludes me from that group), a good IDE might make it more obvious.
I think code should be as readable as possible without an IDE. If
you're going to design a language with the use of IDEs in mind then go
all the way and make it integral, like with Smalltalk.
--bb
More information about the Digitalmars-d
mailing list