Why Ruby?

so so at so.do
Sun Dec 12 08:22:39 PST 2010


> 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?

> 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.

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list