6 ms·
Python is arguably more "obviously readable", in a sense that when you see some construct, and you don't know what it is, but you have a guess, that guess is us
by int_19h 9y ago
Python is arguably more "obviously readable", in a sense that when you see some construct, and you don't know what it is, but you have a guess, that guess is usually correct. It makes the grammar more verbose than Ruby in many ways, and idiomatic Python is almost always more verbose than idiomatic Ruby, but for many people, ease of reading and understanding is preferable.
- ouid 9y agoI dunno man, I don't think the languages are properly comparable for readability. 5.times do print "s" end
- vectorpush 9y agoIt's a double-edged sword. The code's behavior is apparent in that simple example, but things get considerably more difficult to understand when you're dealing with monkey patched methods and dangerously clever method_missing magic in non standard library code.
- singingfish 9y agoYeah, I had to deal with a perl port from a ruby library that had kept most the rubyisms in. The really disturbing thing about it was the Frankenstein levels of autovivification involved. Fortunately someone (not me) is going to get paid deal with that soon.
- int_19h 9y agoYou can certainly find snippets that are simpler in Ruby than in Python; they're just not the majority. Consider a slightly more complicated case where you need to print out items in a range with some modification. Idiomatic Ruby: (0 ... 5).each do |x| print (x + 1) end Idiomatic Python: for x in range(0, 5): print (x + 1) To understand Ruby, you need to know what || does, and the overall sequencing of the words as you read that construct is somewhat unnatural for English. Python is comparatively easier to parse with no prior background. It is definitely possible to write Ruby in a way that's still highly readable. But from what I've seen of real world Ruby code, that's not the way it tends to be written - idiomatic Ruby values expressiveness and DRY, so you see blocks and various terse syntactic sugar used all over the place; lots of "clever" code in general. There's nothing wrong with that - I generally prefer expressiveness over readability myself - but many people do not.
- vickychijwani 9y agoI see your point. But I'll take the liberty to use part of your comment as my own response: "You can certainly find snippets that are simpler in Ruby than in Python, and vice-versa". Now that is something I 100% agree with (I added the part after the comma btw). Basically what I'm saying is that the differences are very minor compared to differences vs, for example, other languages (Java, Scala, C++, etc). So from that perspective there's not much to complain about. I just have a slight bias towards Ruby, I find it a little more readable (in a small way).
- nextlevelwizard 9y agoWhile it is true that with ruby you have to know more syntax, without previous knowledge of either language you caught on pretty fast. To me it is more expressive of my intent to say "0 to 5, for each, do something" than "for something in the 0 to 5 range do something" Also you happened upon what peeves me most about Python, you are not actually looping from 0 to 5 since range is inclusive at the start, but exclusive at the end. So while (0..5) gives you 0, 1, 2, 3, 4, and 5, range(0,5) will get you just 0, 1, 2, 3, and 4. Of course it's easier if you think that range() is rather "I want to take X steps", so if you just want to step 5 times range(5) does exactly what you need it to do.
- camel_Snake 9y agoI think this is mostly to keep in line with indexing, where you have that same sort of semi-inclusion. 'example string'[3:8] # gives you 5 characters.
- nextlevelwizard 9y agoBut wouldn't you rather just say: "hey, starting from the 3rd index, give me 5 letters" like 2.3.3 :001 > 'example string'[3, 5] => "mple " Instead of having to think before hand what indexes thous would be.
- int_19h 9y ago
- zeckalpha 9y agoOr: print("s\n" * 5) Which is more concise and valid in both.
- vickychijwani 9y agoCare to elaborate with an example? I use Python day-to-day and did quite a bit of Ruby a few years ago, but I fail to see significant differences in verbosity. What I do see is that Python is somewhat less consistent and readable (list comprehensions beyond the simplest ones are unreadable, Ruby's blocks allow cleaner DSLs, len(a) vs a.size, little things like "3.times", allowing "?" and "!" in identifiers). But Python has a bigger and more diverse ecosystem. So although I would prefer Ruby over Python, the ecosystem aspect makes the point moot.
- setpatchaddress 9y agoRuby is more concise whenever you have a need for case statements or regex. Really wish Ruby had won this war. It's much more pleasant to use.
- issaria 9y agoIt can not win when there are only three people working on it part timely. Check the new feature list of Python release every few months.
- Lordarminius 9y agoIt boils down to an issue of funding ?
- ksec 9y agoI cant , and could never understand why this is, and if it is a problem. Github, Basecamp, Twitch, Stripe, Square, AirBnB, Shopifly, Cookpad, and many more. All these are very successful site that are using Ruby ( Not necessarily Rails ) and most of them profitable. If each or them could fund a 20-33% Salary of an additional Core Dev you instantly have 3 - 4 people working on it Full time. So I have been thinking on this for sometime, It is because the Ruby community and the world as a whole does not want to donate? Or are we lacking someone to push this and ask for some help when needed?
- brazzledazzle 9y agoIt's one small thing but string interpolation annoys the crap out of me when using Python and while it might tick the understandable check box I wouldn't say it's easier to read. After using Ruby it's such a chore to read or write in my opinion (which admittedly doesn't mean much having so little experience with Python).
- cutler 9y agoHow is "#{fname} #{surname}" better than f'{fname} {surname}' ?
- iipin 9y agoBy the glare of it, none. But you have to understand that ruby has that `#{}` since ways before, and python has just added that `f` syntax recently. Also in ruby it's the only way of doing string interpolation, while in python you have % and other methods.
- herbst 9y agoRuby does have % too for quite a while. As in '%s won $%i' % ['herbst', 5000]
- int_19h 9y agoYou actually want both of these. The reason why explicitly indexed placeholder syntax is still important, even if you have interpolation, is because the order in which the arguments are referenced may change when the string is localized.
- klibertp 9y agoOTOH, f-strings were added to Python not long ago, and they are the third or fourth (depending on if you count `string.Template`) syntax for string interpolation in Python. Frankly, string formatting in Python is a bit of a mess right now.