Why Ruby?

Jacob Carlborg doob at me.com
Mon Dec 13 09:45:54 PST 2010


On 2010-12-12 15:24, Lutger Blijdestijn wrote:
> Jacob Carlborg wrote:
>
> I agree with lambda syntax, iirc the trailing delegate was introduced around
> the time lazy made it into the language. However, D has some features of its
> own that could make for a better translation.
>
> In rails associative array literals are used as a workaround for the lack of
> named parameters in ruby. You can take advantage of overloading and template
> specialization in D to reduce the need for such a feature, which looks very
> strange anyway in D code. Furthermore, the code block syntax is used in ruby
> everywhere, but in D we also have nested functions, alias template
> parameters and lazy parameters.
>
> I'm sure a skilled designer could make a much better api than literally
> translating RoR. Perhaps something like this is already better:
>
> class PeopleController
>      : ActionController!( before_filter!authenticate )
> {
>      People[] people;
>
>      void index ()
>      {
>          people = Person.where("age>  30").order("name DESC");
>
>          void respond(Format format)
>          {
>              format.html;
>              format.xml( render(people.toXml) );
>          }
>
>          doResponse(&respond );
>      }
> }
>
> One thing to consider is that a certain class of errors in D is caught by
> the type system. Even when you don't see static typing as an advantage
> perse, you can't ignore the fact that you have to write unittests for all
> these cases in a dynamic language whereas with static typing you save this
> need.

Yes, that's an other way to translate the Ruby code but I tried to stay 
as close to the Ruby code as possible. If you want to overload render 
(as I'm guessing you do in that example) on different types, toXml needs 
to return some kind of structure and not a string as it's returned in Ruby.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list