Eliminate assert and lazy from D?

Jeremie Pelletier jeremiep at gmail.com
Mon Oct 12 23:41:42 PDT 2009


Andrei Alexandrescu wrote:
> Right now, the language has enough power to express assert as a library 
> function, as opposed to a primitive construct. (See e.g. enforce.) I 
> think it would be good to relegate assert to object.d.
> 
> This also brings up "lazy", which seems to be quite botched. Are there 
> suggestions on how to replicate its functionality in a different way? I 
> even seem to recall lazy was discussed as a disadvantage in the recent 
> dialog on reddit, see
> 
> http://www.reddit.com/r/programming/comments/9qf8i/i_wrote_some_d_today_and_its_completely_blowing/ 
> 
> 
> I personally believe it's useful to be able to pass an unevaluated 
> expression into a function, for example assert and enforce themselves 
> use that.
> 
> But let's open this for discussion: should assert and/or lazy be 
> removed? If not, why not? It yes, why? How can we replicate their 
> functionality?
> 
> 
> Andrei

lazy is a great feature of D, although you need some sort of usage 
convention to not get confused with it.

For example, there is no way to tell a parameter is lazy from a function 
call, you need to look at the prototype. But the same can be said with 
ref and out too so if you remove lazy you also need to rethink these two.

I therefore made myself a simple convention on how I use lazy: if the 
value is evaluated only once I use lazy, otherwise I use a delegate. 
This makes it clear from the call context what I'm doing.

Sometimes I use lazy for values evaluated multiple times (I did it in 
the json module i posted to D.announce) when the method is private 
because I'm too lazy (pun intended) to write a full delegate.

Jeremie



More information about the Digitalmars-d mailing list