www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: [OT] What should be in a programming language?

reply bearophile <bearophileHUGS lycos.com> writes:
Yigal Chripun:
 there should be no syntactic difference between an int and a user 
 defined type.
 for example I should be able to do:
 struct foo : int {}

With "alias this" D2 is able to do something like that, but it uses a nonstandard syntax... So here things may be improved in D2. Bye, bearophile
Oct 24 2009
parent reply Yigal Chripun <yigal100 gmail.com> writes:
On 25/10/2009 08:47, bearophile wrote:
 Yigal Chripun:
 there should be no syntactic difference between an int and a user
 defined type.
 for example I should be able to do:
 struct foo : int {}

With "alias this" D2 is able to do something like that, but it uses a nonstandard syntax... So here things may be improved in D2. Bye, bearophile

This is one aspect that D inherited from C which I really dislike. adding alias this to the mix is adding a sin to a crime (as the Hebrew saying goes). Scala shows how this can be properly designed. D has many (sometimes very powerful) hacks that could and should be replaced with a much better general solution. for instance there's special handling of void return types so it would be easier to work with in generic code. instead of this compiler hack a much simpler solution is to have a unit type and ditch C style void. the bottom type should also exist mainly for completeness and for a few stdlib functions like abort() and exit()
Oct 25 2009
parent bearophile <bearophileHUGS lycos.com> writes:
Yigal Chripun:

 D has many (sometimes very powerful) hacks that could and should be 
 replaced with a much better general solution.

Sometimes fully orthogonal designs aren't the best because they force the programmer to do too much "assembly required". A good language has to offer some handy pre-built/highlevel constructs for the most common operations, that can save lot of work. Sometimes general solutions produce slow programs, or they require a more complex/smarter/slower compiler (I need a new word there, "complexer"? Natural languages too need updates now and then). But I agree that in few parts D can enjoy a redesign. Andrei is doing some work on this, and quite more work can be done. The "alias this" looks like a little hack too me too. A safer or more "theoretically sound" solution may be found. Bye, bearophile
Oct 26 2009