D as a prototyping language (for C/C++ projects)

Jacob Carlborg doob at me.com
Tue Feb 26 13:01:59 PST 2013


On 2013-02-26 20:52, H. S. Teoh wrote:

> Do you have any specific examples?

Return the date from two days ago:

Ruby on Rails:
2.days.ago
Date.today
Time.now

D:
Clock.currTime - 2.days
// Not sure how to do the other two in D

This is not that bad but it's a bit less intuitive. Here we also have 
shortening of "current" which just saves three characters, for no reason.

I think it's mostly std.algorithm that is the problem.

* reduce - The "reduce" function is really weird. It can't be used as a 
property. The signature is:

reduce!(fun)(seed, range)

When it should be:

reduce!(seed, fun)(range)

And:

reduce!(fun)(range, seed)

* No algorithm functions for associative arrays.

* tap - Ruby has a really nice function, "tap". In D it would look like:

T (func, T) (T t)
{
     func(t);
     return t;
}

You can do things like:

Foo foo ()
{
     return (new Foo).tap!((f) {
         f.x = 3;
	f.y = 3;
     });
}

This becomes a bit tricky because we want structs to be passed by ref, 
but preferably we don't want to be able to change the parameter in the 
delegate. In Ruby it's no problem since all types are reference types.

I probably can come up with more later.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list