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

There are so many answers! Here are a few:

The article does not claim that (1..100).inject(&:+) is great. It claims that it is a totemic example of Ruby code.

There is nothing that technique X can do that technique Y cannot do given that X and Y are both Turing Equivalent. Of course you can write a library function to sum numbers. Do you also need a library function for the product of numbers?

If so, you now know of a salient difference between the two approaches. One needs a function for each thing you want to do, the other gives you some pieces you combine in different ways to do what you want. Is one better than the other? That's up to you to decide, you are the programmer. Ruby lets you write your program either way.

Now, Symbol#to_proc doesn't, in my opinion, add what I would call power. That's because you can always use a block or a lambda wherever you would use a symbol. But I may not have written the article well: the powerful and dangerous feature in Ruby is not Symbol#to_proc, it's Open Classes. Symbol#to_proc is an example of something you can do with an Open Class. Something else you can do with an Open Class is Hash#to_proc. Something else is Object#andand, a low-rent version of the Maybe Monad in Haskell.

I consider Open Classes to be powerful and dangerous. Am I advocating them? Of course not, it is up to you to decide whether they are a good idea or not. What I find interesting about them is that Rubyists are pushing the language in new directions with them, like Symbol#to_proc. The idea of a language growing from the fringe is also powerful and dangerous. The fringe is an uneducated, seething mass.



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

Search: