On 2010-12-12 17:22, so wrote:
If we take a look at the very first code example from the talk it
looks like this:

account.people.each do |person|
puts person.name
end

You could translate this in two ways when translating into D.
First way:

foreach (person ; account.people)
writeln(person.name);

Am i alone thinking D one better here?

No, probably not. In this case I think the D syntax is just as good or better as the Ruby syntax but there are other cases than iteration that can use a better delegate syntax. Just look at Scala, one could use the delegate syntax to create, what it looks like, new control structures like "unless" (Ruby), "receive" (Scala), "loop" (Ruby, Scala) and so on.

If we have a look at the next code example from the talk there is no
clear and natural way to translate it into D, first the Ruby code:

class PeopleController < ActionController::Base
before_filter :authenticate

def index
@people = Person.where("age > 30").order("name DESC")

respond_to do |format|
format.html
format.xml { render :xml => @people.to_xml }
end
end
end

And then the translated D code:

class PeopleController : ActionController.Base
{
Person[] people;

mixin before_filter!(authenticate);

void index ()
{
people = Person.where("age > 30").order("name DESC");

respond_to((Format format) {
format.html;
format.xml({
render(["xml" : people.to_xml]);
});
});
}
}

class PeopleController : ActionController.Base
{
Person[] people;

mixin before_filter!(authenticate);

void index ()
{
people = Person.where("age > 30").order("name DESC");

respond_to(format) {
format.html;
format.xml {
render(["xml" : people.to_xml]);
}
}
}
}

D here could use some help at respond_to, but overall i still prefer D way.
Maybe it is just me, i like flexibility of C like languages, and D
examples here also adds beauty to it.



--
/Jacob Carlborg

Reply via email to