3 ms·
The 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 sn
by henning 19y ago
The 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 extension methods; Sum is an extension method.)
- raganwald 19y agoThe article does not claim that this is a good thing! It claims that the line of code says a lot about Ruby the language.
- henning 19y agoThat it's obsessed with obfuscatory, slow language constructs?
- raganwald 19y agoLet me ask you a question: you arrived at the top of the article with a preconceived idea about Ruby. Did reading the article give you any insight, did you learn something about Ruby or about yourself by reading the post? If not, please downmod it, I have failed.
- mynameishere 19y agoor about yourself At the risk of getting even more downmods for saying true things here, can I just point out that it's a little arrogant to pretend that a blog post about Ruby is going to move someone towards self-actualization? Anyway, have you failed? No. You wanted to show us your favorite line of Ruby code, and you did. As for me, I don't really have a favorite "one line" of code, but I fondly remember when I was a kid typing in Nibble Magazine's "one and two-liner" programs. Actually, the "lines" were lines as defined by the Apple II's command line buffer limit. Here's an example: http://www.apple2.org.za/mirrors/ground.icaen.uiowa.edu/apple8/Pgms/rotatecube.bas http://www.apple2.org.za/mirrors/ground.icaen.uiowa.edu/appl... Maybe I'm not a sufficiently abstract person. My favorite two lines of code was an honest-to-god graphical car driving program in two lines of APPLESOFT BASIC [1]. Two lines of code in a language so crappy it's basically a joke. And yet...a full-on-graphical-car-racing program. I'm strongly tempted to think that APPLESOFT BASIC is superior to Ruby, based on the evidence I've seen. Point is: The next time you show a feature of a langauge, maybe make it solve a problem, or create something real, rather than just showing how few characters it takes to do something banal. Adding numbers together? Seriously, it's a solved problem. [1] Sorry for the capital letters, but I'm in Apple mode now: http://www.apple2.org/images/Literature/a2/BlueBook.JPEG http://www.apple2.org/images/Literature/a2/BlueBook.JPEG
- raganwald 19y ago"have you failed? No. You wanted to show us your favorite line of Ruby code, and you did." Actually, I wanted to discuss how Ruby's open classes promote language innovation from the fringe, not to try to impress you with how clever that line of code is. "The next time you show a feature of a langauge, maybe make it solve a problem, or create something real, rather than just showing how few characters it takes to do something banal." And there you have why my article failed you: you think it is about how useful that line of code is, or how clever it is, or what problem it solves, when I think it is an example of how Ruby is different from centrally planned language. Is it great code? Of course not. Symbol#to_proc may even be an evolutionary dead end, AFAICT it's just a way to make OO code pretend that it's functional code. Your criticisms point out that I need to work harder on establishing and communicating my theses, thank you.
- Darmani 19y agoReplace + in the Ruby with multiplication, or division, or boolean and, or even exponentiation, and show me the VB equivalent. A digital-typewriter user will laugh at a PC user if all he sees the PC user doing is word processing.
- ken 19y agoIf you don't understand the difference between "a function that sums a list of integers" and "a function that accepts a function", then Joel has a pretty decent introduction you should read: http://www.joelonsoftware.com/items/2006/08/01.html http://www.joelonsoftware.com/items/2006/08/01.html