5 ms·
I would say Ruby is closer to the dream than Python.
by gnclmorais 9y ago
I would say Ruby is closer to the dream than Python.
- glaberficken 9y agoCould you give an example code snippet that "reads more naturally" in Ruby than in Python? I'm an amateur programmer (Python, JS) and I have been wondering for a long time if there is a language more readable than python.
- santiagobasulto 9y agoI don't think that's true. Both Python and Ruby are readable enough. Both languages encourage good practices in different ways. I'm a 100% Python developer, but I like many ideas of Ruby; for example, the convention of using question marks to indicate that a method returns a boolean. When you're working in a large project with +10K LOC, the project structure and the quality of the code you write is much more important than the language itself.
- gnclmorais 9y agoIf we’re talking about Rails, even there Ruby is possibly better. Rails has been around for a long time and its community is very clear on readability and maintenance.
- unixhero 9y agoprint "yes".reverse -> sey Quite readable and fun. I've never loved a language like I do Ruby. Everytime I am stuck, and find a simple, fun and elegant solution I like it even more.
- aianus 9y ago1) Multi-line lambdas (no equivalent in python afaik): collection.map do |i| blah = something(i.something) blah.something_else end 2) Easily chainable object methods instead of weird global functions: a.length collection.map { |x| x^2 } vs len(a) map(lambda x: x^2, collection) 3) Closing braces instead of whitespace make it a lot easier to judge indentation level
- pvg 9y agoThe 'equivalent' for that sort of thing in Python these days is comprehensions. The other stuff is pretty subjective. There is a blurb in the FAQ about things like 'len' and it makes the argument it's more readable.
- pmontra 9y ago10.times do something end (1..10).each do |i| something_with i end
- joshuamorton 9y agofor _ in range(10): something for i in range(10): something_with(i) Can you explain why the Ruby reads more naturally? The major differences, as I see them are that ruby requires end blocks, and uses methods instead of global functions for things. In my opinion, python takes great pains to make things consistent, which is valuable. There's one function, range, instead of two methods, times and each. The syntax is unified: `for N in range`, which `_` being a convention if `N` is unused, as opposed to Ruby where you can define the looping variable, or not, depending on the method that was called (I guess?). Ruby does appear to read more like something you might say, although still with weirdish grammar, but on the other hand, replace ":" with "repeat" and be explicit about the elided 0 in range, and you get "for i in the range 0 to 10, repeat something with i" which is english, as opposed to Ruby which is "take the range 1-10 and for each do unto i something with i", which imo appears significantly less natural. This actually extend's to the stuff about "len" vs ".length", where you're asking which is more natural, to "do something to the length of X" or "do something to X's length". And that's very much a subjective question, but Python's answer establishes stronger consistency.
- pmontra 9y agoIMHO (1..10) is much more explicit than range(10). No questions about what it is. Where does range(10) starts from? -infinity, 0, 1? Or where does it ends at? Is 10 the starting point? Probably not but who knows. One should read the manual for that. BTW I hate Ruby's three dots (1...10) because it's (1..9) and I never remember which one is what when I find it in somebody's else code. Languages should not trick developers into mistakes. I only write the two dots. However: 1) if one comes from Ruby, then Python is a Ruby designed by someone with a weird mind 2) if one comes from Python, then Ruby is a Python designed by someone with a weird mind I'm coming from Ruby, a historical accident I can't change. No hard feelings.
- gnclmorais 9y agoAdding the the examples aianus posted here, Ruby needs no `__self__` or `self` being passed everywhere. You only use `self` when you really need it.