Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Which seems the most "readable"? I think the Ruby one might be.


I like the python version: it is the densest, and most similar to set notation. It is done similarly in Fortress.


How about this?

    myList collect(description) select(!="") join("\n")
http://www.iolanguage.com/scm/git/checkout/Io/docs/IoGuide.h...


I like the Ruby one most. But "readable" is matter of taste (or programmer's background: I consider

  while (*to++ = *from++); 
to be a readable C code (not that I'll recommend it)).

It is wrong to judge a language by tiniest code examples.


Using Symbol#to_proc, the old Ruby

  myList.collect { |f| f.description }.select { |d| d != "" }.join("\n")
becomes

  myList.map(&:description).reject(&:empty?).join("\n")
which is even more direct: take my list, map each element to its description, reject anything empty, and join with newlines.


I thought `Symbol#to_proc` is a Rails' extension.


I learned about it in 2005, when I read it on http://pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.... and it's such a good idea that they've folded it into 1.9 http://www.infoq.com/news/2008/02/to_proc-currying-ruby19




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: