4 ms·
Very flexible. Once you learn what the sytnax means the implementation of blocks and iterators is one of the best parts of the language. 3.upto(6){ |x| put
by johnbender 17y ago
Very flexible. Once you learn what the sytnax means the implementation of blocks and iterators is one of the best parts of the language.
3.upto(6){ |x| puts x }
I don't think the uniqueness of a language is any reason not to learn it. To be honest that sounds lazy.
PS I'm not a Ruby zealot, and Python is a great language
- bretthoerner 17y agoSo I just saw 3 ways to print from 3 to 6... are those all used in the wild? Zen of Python: "There should be one-- and preferably only one --obvious way to do it." Sure, there are other ways to do it in Python, but it'd be frowned upon to use something like 3.upto(6) rather than a standard range() that everyone is used to. Readability matters.
- carbon8 17y agoI'd argue 3.upto(6) is much more readable and obvious than range(3, 7). Even just on a conceptual level, Python requires a degree of translation and its stop argument is not intuitive whereas even someone who has never programmed before can understand the Ruby.
- req2 17y agohttp://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831....
- skawaii 17y agoWhile I agree that readability matters _a lot_, the "Zen of Python" honestly bugs me. But maybe it's just the counter-culture ethos that dwells inside me. +) Note: I used Python daily at work and for open source projects. I also use Ruby for open source projects. I like them both.
- JoelPM 17y agoI like the Zen of Python myself, but the first thought that crossed my mind was that the Python example could use xrange and save the generation of a temporary list. So there are at least two ways of doing it in Python, both of which look very similar and differ only in the underlying implementation. This makes me curious how much more frequently range is used than xrange and in what situations it's preferable.
- pwang 17y agoThis is an acknowledge minor "wart". In Python 3.0, range() does the same thing as xrange().
- johnbender 17y agoI'm sorry, did you say there's only one way to deal with each integer in a set of numbers? Admittedly I don't know very much about python, but it seems that at the very least you could do this recursively.
- gaius 17y agoNeither Python nor Ruby AFAIK have tail-call optimization.