6 ms·
I think that one can take from a question like "should I learn Python or Ruby?" that the person asking is generally often new to programming in general. Because
by ycmike 13y ago
I think that one can take from a question like "should I learn Python or Ruby?" that the person asking is generally often new to programming in general. Because of this, I would highly suggest Ruby over python. While the learning curve may be higher, Ruby is more intuitive and reads often as like plain english.
Unless you are an engineer in school, diving straight into Python may not be the best option. Also, many people just learn Ruby to do Rails as well. This is shown with the infinite number of rails bootcamps popping up all across the country.
TL;DR
The majority of people asking this question are probably new in general to programming and looking to do some web programming so learn Ruby in view to Rails.
- meowface 13y ago>Because of this, I would highly suggest Ruby over python. While the learning curve may be higher, Ruby is more intuitive and reads often as like plain english. I disagree. Python generally reads much more like English than Ruby. Ruby: a && b # `and` is available but is generally not recommended due to operator precedence Python: a and b Ruby: a = b ? c : d Python: a = c if b else d Ruby: "abc" =~ /[a-z]{3}/ Python: re.match(r"[a-z]{3}", "abc") Ruby: [1,2,3].map { |n| n + 5 } Python: [n + 5 for n in [1,2,3]] Ruby also encourages operators and sigils that would be quite confusing to brand new beginners, like `||=`, `@`, `@@`, as well as Perl special variables ("what the hell are $/ $* and $&?").
- mitchty 13y agoFor contrived examples this is true but these are a bit contrived. For && vs and, by the time you hit the need to differentiate those in ruby, you'll likely be at the port of operator precedence being a thing that is understandable. The ternary operator shouldn't even come into play for a beginner in my not so humble opinion ruby/c/c++ or not. Instead of using the ternary, for ruby i'd be advocating more: a = if some_truthy_operation/variable c else d end Way more verbose sure, but then when they get the hang of that, they can start to learn when the ternary operator is useful, if even. Generally I avoid it. For the regexp match, I'd rather show them "abc"[/[a-z]{3}/]. That makes a short leap into the === operator and all its varied uses. But to be more close you could also do /[a-z]{3}/.match("abc"), this is admittedly half a dozen of one 6 of the other. I got nothing for the map bit, but I also know smalltalk so admittedly I'm going to be biased. :) That said both Python and Ruby have good uses. I'm converting a bunch of my own Ruby stuff to Python for work, and the rest to good old C. So I'm biased, but generally don't give a shit. :D I'd be looking for more information on the background of the person learning and what they want to achieve from programming. In the end, learning any language, I'll even begrudgingly include PHP in there (just picking on you guys) is a good thing.
- Freaky 13y ago> Ruby: a && b # `and` is available but is generally not recommended due to operator precedence They're low priority in both languages. I use and see others using `and` and `or` all the time. In 15 years I can't say I've blown my foot off yet. > Ruby: a = b ? c : d If I'm really wanting a oneliner I'll tend to write a = if b then c else d end You can of course spread it across a few lines: a = if b c else d end More typically it's constructs like: a ||= b a = b if c a = b unless c > Ruby: "abc" =~ /[a-z]{3}/ /[a-z]{3}/.match("abc") If you prefer.
- meowface 13y agoYou're right, but what I listed are generally considered the most idiomatic (the ternary one will be situational though). So when a beginner is trying to read someone else's code, they're likely to see those. But if they read some Python code that a seasoned veteran wrote, they're a lot less likely to see anything particularly confusing. I think Ruby does generally look more elegant, but if I was a beginner again I sure as hell would have a much easier time reading Python code compared to Ruby code.
- panzi 13y agoI find that "unless" adds some significant cognitive overhead for me, at least for more complex conditions. So I think this statement was a bad idea.
- msellout 13y agoFunny, I was going to say something similar but favor Python.