Why I hate ruby.
Since I don't use ruby either...I tried a web based interpreter. >> (1..100).inject(&:+) TypeError: wrong argument type Symbol (expected Proc) from (irb):1 I also am not a fan of doing things a thousand different obscure ways. I like doing things one way, and having that way highly optimized. Typing 10 characters or 20 characters doesn't impact my programming speed, I spend far more time thinking about how to do thin…
(1..100).inject(&:+)
11–20 of 66 posts
Re: (1..100).inject(&:+)
#12Why I hate ruby.
Since I don't use ruby either...I tried a web based interpreter. >> (1..100).inject(&:+) TypeError: wrong argument type Symbol (expected Proc) from (irb):1 I also am not a fan of doing things a thousand different obscure ways. I like doing things one way, and having that way highly optimized. Typing 10 characters or 20 characters doesn't impact my programming speed, I spend far more time thinking about how to do thin…
Re: (1..100).inject(&:+)
#13Earlier quoted context omitted.
Since I don't use ruby either...I tried a web based interpreter. >> (1..100).inject(&:+) TypeError: wrong argument type Symbol (expected Proc) from (irb):1 I also am not a fan of doing things a thousand different obscure ways. I like doing things one way, and having that way highly optimized. Typing 10 characters or 20 characters doesn't impact my programming speed, I spend far more time thinking about how to do thin…
It won't work unless your web-based interpreter runs Ruby 1.9, or you also paste in his monkeypatch to the Symbol class.
Re: (1..100).inject(&:+)
#14In real life, the answer is to know some math and realize that 1 + ... + n = n(n+1)/2, so the entire thing is pointless anyway.
(And if you want to add methods to a given class ad-hoc, you can do it statically with extension methods; Sum is an extension method.)
Re: (1..100).inject(&:+)
#15Why I hate ruby.
Since I don't use ruby either...I tried a web based interpreter. >> (1..100).inject(&:+) TypeError: wrong argument type Symbol (expected Proc) from (irb):1 I also am not a fan of doing things a thousand different obscure ways. I like doing things one way, and having that way highly optimized. Typing 10 characters or 20 characters doesn't impact my programming speed, I spend far more time thinking about how to do thin…
Why what is a good thing? Why that line of code is a good thing? maybe it isn't, maybe arrays need a sum method, maybe you could just write:
(1..100).inject { |acc, n| acc + n }
...and get the same result. But the article has nothing to do with why that line of code is a good thing, it is about the fact that being able to modify the Symbol class in this manner is what makes a langauge like Ruby evolve from the bottom up.
So... do you think that is a good thing? Or a bad thing?
Re: (1..100).inject(&:+)
#16Anyone want to explain that code to someone who doesn't know Ruby?
Sums the first 100 integers. You are basically injecting a function (plus in this case) between each element and evaluating it (to describe in very non-technical sense).
+/!100
4950
Or if you insist on 1-indexing: +/1+!100
5050Re: (1..100).inject(&:+)
#17The VB.NET equivalent is Enumerable.Range(1, 100).Sum, which seems clearer to me. Why is this so impressive? If Visual Basic comes close to your beloved code snippet, it's probably not that big of a deal. In real life, the answer is to know some math and realize that 1 + ... + n = n(n+1)/2, so the entire thing is pointless anyway. (And if you want to add methods to a given class ad-hoc, you can do it statically with…
Re: (1..100).inject(&:+)
#18The VB.NET equivalent is Enumerable.Range(1, 100).Sum, which seems clearer to me. Why is this so impressive? If Visual Basic comes close to your beloved code snippet, it's probably not that big of a deal. In real life, the answer is to know some math and realize that 1 + ... + n = n(n+1)/2, so the entire thing is pointless anyway. (And if you want to add methods to a given class ad-hoc, you can do it statically with…
The article does not claim that this is a good thing! It claims that the line of code says a lot about Ruby the language.
Re: (1..100).inject(&:+)
#19Earlier quoted context omitted.
Since I don't use ruby either...I tried a web based interpreter. >> (1..100).inject(&:+) TypeError: wrong argument type Symbol (expected Proc) from (irb):1 I also am not a fan of doing things a thousand different obscure ways. I like doing things one way, and having that way highly optimized. Typing 10 characters or 20 characters doesn't impact my programming speed, I spend far more time thinking about how to do thin…
"I fail to see why this is a good thing." Why what is a good thing? Why that line of code is a good thing? maybe it isn't, maybe arrays need a sum method, maybe you could just write: (1..100).inject { |acc, n| acc + n } ...and get the same result. But the article has nothing to do with why that line of code is a good thing, it is about the fact that being able to modify the Symbol class in this manner is what makes a…
So I am wondering why the author thinks its so fantastic.
As for developing the language, I am usually for flexibility and allowing anything to be modified, however this type of change strikes me as not very useful.
Re: (1..100).inject(&:+)
#20Earlier quoted context omitted.
The article does not claim that this is a good thing! It claims that the line of code says a lot about Ruby the language.
That it's obsessed with obfuscatory, slow language constructs?
If not, please downmod it, I have failed.