8 ms·
Should I Learn Python or Ruby?
- amaks 13y agoNeither. Learn Go.
- tuke 13y agoNow you're talking.
- tuke 13y agoP.S. An interesting question is: Who's flocking to Go more, Rubyists or Pythonistas?
- increment_i 13y agoOr even better, C. Baptism by fire, baby.
- codygman 13y agoI think Haskell might actually work better for some. However Go is an upgrade from Ruby and Python in many areas they are used imo.
- throwawaymsft 13y ago> My advice: Try both languages. See which language you like better, then learn that one. After that, learn the other. Argh, I hate the "learn both" conclusion. It doesn't help anyone. If doing web programming? Ruby (+Rails). Desktop / scientific computing? Python As a general heuristic, just look at the types of projects you want to build and what they're built in. Then use that.
- rat87 13y agoFrom the page: > Usage > Python can be used for web development, sys admin, statistics, and scientific computation. Meanwhile, Ruby is used primarily for web development. Python has the upper hand here, but if you are looking to only do web development, Ruby is the way to go.
- navyrain 13y agoThis is where the article starts to show its bias. Of course ruby can do everything mentioned as well. Python has a leg up in scientific computing and stats. Ruby has a leg up in web and devops. Saying one "can do" everything, and the other "only does web" is misleading. As the grandparent said, it really depends on your goals.
- alrs 13y agoRuby is quickly dying in the ops space. I wouldn't use either Chef or Puppet today for a greenfield project.
- boon 13y agoWhat do you see as the new hotness that has replaced them?
- digisign 13y agoSalt, ansible, and pave (the fabric extension).
- easong 13y agoAs someone about to start architecting their first reasonably sized deployment automation project, what do you think one should be using instead? (Currently planning on Chef.)
- stonith 13y ago
- hudibras 13y agoSo I guess the answer is Python.
- tlunter 13y agoOr at least, their answer is (which is pretty biased)
- jalan 13y ago> Meanwhile, Ruby is used primarily for web development. What? I just started learning Ruby, and I intend to do some sys-admin tasks also. Am I going down the wrong path? I know Homebrew is using Ruby as base language, and doing pretty fine. Is this misleading or what?
- barbs 13y agoPrimarily != exclusively
- mjhea0 13y agoThanks! :)
- zem 13y agoyou're not, ruby is an excellent sysadmin language. python has the edge for scientific computing, though, due to the larger base of people using it for that. also pygame is great.
- erichurkman 13y agoRuby can be used for sys-admin stuff, absolutely. Look at Chef.
- zdw 13y agoPuppet uses Ruby too. Ansible and SaltStack both use Python. Older systems frequently use Perl (for example, ticketing systems like RT or OTRS), or even older systems use Tcl. Sysadmin tools are a tossup, driven mainly by whatever the rest of the ecosystem uses.
- Stubb 13y ago> What? I just started learning Ruby, and I intend to do some sys-admin tasks also. Am I going down the wrong path? I don't think so. Ruby has for me replaced bash scripting along with sed, awk, and Perl. It's nice to do all these things with one consistent syntax. And be sure to check out Pry (http://pryrepl.org/ http://pryrepl.org/)! I'll give Python another look once v3 catches on.
- tuke 13y agoThat's how you think a Rubyist would write Fibonacci? I think one might follow the Python "idea" but avoid defining a function . . . fib = lambda do |n| return n if n < 2 fib[n-1] + fib[n-2] end puts fib[8]
- nwmcsween 13y agoYes his examples are very very unrubyish, it looks like javaish ruby.
- bhrgunatha 13y agoThe biggest thing that jumps out at me is that the Ruby code is defining a Hash object (map or dict) and not a function. To say a Ruby programmer would create a Hash object that uses a block instead of write a function seems plain wrong, despite how the algorithm for generating items was implemented.
- ioquatix 13y agoThe ruby code [in the linked article] is complete rubbish. In addition, the Ruby implementation is memoized while the Python example isn't. Clearly that means there is a significant performance difference. I'd like to see the memoized Python implementation in one line.
- doctoboggan 13y agoIt's just one more line - wrapping the function with the memoization decorator from the stdlib: http://docs.python.org/3/library/functools.html#functools.lru_cache http://docs.python.org/3/library/functools.html#functools.lr...
- panzi 13y agoAnd it's much clearer on what it actually does.
- nwmcsween 13y agoIMO that is very unrubyish code.
- kashif 13y agoImportantly, Python has many more libraries and terrific support for scientific, statistical, AI and math work. Also it has IPython :)
- ycmike 13y agoI 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.
- gte910h 13y agoIf you just want to do web dev, probably ruby. Otherwise, python is probably more versatile
- tuke 13y agoJezis, now that I've read the article more closely: I can't speak to the Python, but that is Ruby with the left hand. Ew.
- bobbyi_settv 13y ago> Should I Learn Python or Ruby? Definitely!
- bsder 13y agoPick one, learn it, and don't worry about it. Seriously. They are relatively equivalent. I'm a Python person and ex-Perl and ex-Tcl refugee. If you're doing scientific stuff, use Python. It's got a great community around that. Web is probably a wash--Ruby/Rails is a canonical combination, but Python/Django somehow manages to impress me every time I touch it. However, if you're doing web stuff, I'd probably go for Javascript nowadays on both server and client side. I can handle a bunch of languages: Scheme, Erlang, Scala, Clojure, Lua, Javascript ... but when I just need to bang out code I tend to grab Python.
- qstyk 13y agoAt risk of going off-topic, was your migration from Perl to Python a simple factor of the projects you worked on or was there a deliberate effort to proactively switch? I learned Perl in the CGI days of the mid-90's and never even continued on to PHP. As a network consultant now, I find Perl to be immensely helpful, when it comes time to script some monitoring or automated activity. That said, a fellow networker had mentioned that many others had been switching. Most of my days are not spent programming, but I do occasionally bust out a project or two. Is it worth my time to make the switch?
- bsder 13y ago> At risk of going off-topic, was your migration from Perl to Python a simple factor of the projects you worked on or was there a deliberate effort to proactively switch? Deliberate. I'll put my story below my advice so as not to bore the masses. If you're good at Perl, it's probably not worth the time to make the switch until you have to. Python isn't sufficiently "better" to warrant the time investment required. The only caveat to that statement would be in two different cases: 1) your scripts have lifetimes longer than a few dozen months or 2) you have a a larger body of programmers who need to understand and modify your scripts. WARNING! HORRIBLY BIASED OPINION INCOMING! Perl 4/5 tended to create a weird problem in programmers in my experience. Everybody "learned" Perl, but everybody "learned" a different ... dialect, for want of a better word. So, when two Perl programmers got together to read a program, at least one of them was learning new corners of the language. Or one of them was remembering pieces that he had long forgotten. I was on all sides of that issue. It was so bad that eventually when I interviewed for VLSI jobs, I would bring along a nice piece of Perl code I had written, so that I would be discussing Perl on my terms instead of that of the interviewer. That cut short a lot of the "do you know Perl?" idiot questions. So, what I found after I made the Python switch (I won't claim that I was prescient enough to realize beforehand), was that 1) I could come back to my scripts after 2 years and still understand them and 2) all the Python programmers seemed to pretty much wind up programming sort of the same way. For me, that cemented that I would never go back to Perl. Even after not programming in Python for a few months, I could go right back to it. A few months off from programming in Perl and it would take a couple of weeks to get back up to speed. Python just seems to have a smaller mental model--Perl aficionados would cite that as an inferior mental model. Shrug. I'm not a genius so I'll stick with the smaller mental model, thanks. Back to why I switched. My reasons were both petty and selfish. :) I wrote a lot of Perl scripts as a VLSI designer. A lot of munging data from this format to that format. Check that thing over there. Merge it with this thing with undocumented formats. Consequently, my scripts tended to have 1) lots of subtle edge cases and 2) lifetimes often measured in years because the effort to do it right is both enormous and highly specialized. (I had someone email me about a script I wrote 14 years ago early this year that reads formats that are over 30 years old!) The problem was that I kept tripping over bugs--and nobody could explain to me what was going on. About 2/3 or the bugs were mine but required Perl near-gods to diagnose, 1/6 of the bugs were weird grammar edge cases in Perl, and 1/6 were actual bugs in Perl. This was in the 1994 to 1996 timeframe around the Perl 4 to Perl 5 transition (yeah, I've been doing this that long). The bug which finally convinced me it was time to leave (there were many, but this was the last straw) Perl was when I wrote a program to merge static timing analysis cards from 3 different sites (3 different formats, naturally). 99.9% of the time it worked, but sometimes it would just die. I finally tracked it down to a bug in Perl 4, the Regex engine would do weird things if you fed it a pattern with 512 characters exactly. 511 and it worked. 513 and it worked. I sighed. Pulled down Perl 5 instead knowing things had been pretty much completely rewritten. And tripped over a different bug in the regex engine. Started looking for a new scripting language that day. Pretty much the only options at that point were Tcl, Scheme, Lisp or Python at that point. I had abandoned Tcl (pretty much the standard for scripting in VLSI/EDA) for Perl originally because it was a similar disaster until the 8.0 rewrite. Scheme and Lisp were just starting to integrate the fact that Unix wasn't just a tiny blip until we got back to a real operating system so they had better start supporting operating system integration. So, that left Python. Horrible whitespace dependency and all. :) I'm kind of surprised that almost 20 years later I'm still using the same programming language. I really expected something significantly better to come along. Scala, Erlang, and Clojure all have made a good case--but they don't really bring anything to the table that warrants me switching completely in the general case. Scala was WAY too much mental model inload for me. Erlang didn't handle dynamic hash tables well enough for the amount of time you use them in programming (I tell my classes--70% of the time use a hash table; 30% of the time use a vector). Clojure was quite nice and probably made the best case, but it just wasn't better enough than Python for me to spend the time making it my primary language. Side note: dynamic hash tables just hit Erlang THIS MONTH. So, that's probably not a good reason anymore. Now, betcher sorry you asked that question, arn't cha? :)
- fredgrott 13y agoNah why not go all the way, learn Perl
- kayman 13y agoDoesn't matter. Pick one and learn it. What you can do in python, you can do in ruby.
- alxndr 13y agore: learning Ruby: at the SF Ruby conference in 2012, Steven! Ragnarök gave an interesting talk called "Sugar-Free Ruby" about an object-first approach to teaching/learning Ruby. Start with methods on objects, and introduce syntactic sugar like `a + b` later. video: http://www.youtube.com/watch?v=SNbBC2pSiVw http://www.youtube.com/watch?v=SNbBC2pSiVw slides: https://speakerdeck.com/nuclearsandwich/sugar-free-ruby https://speakerdeck.com/nuclearsandwich/sugar-free-ruby
- ZanderEarth32 13y agoIt seems far easier to learn Ruby just by the sheer support it has from all the online coding resources like Treehouse, One Month Rails, etc. I have yet to find a similar type of course or resource for Python. Anecdotally, it was far easier for me to get a simple web app up and running with rails than it was with django, but this has much more to do with the resources I had available to me (like the ones I mentioned earlier) that walked me through rails that I didn't have for django.
- cabbeer 13y agoHow does javascript compare as a first language (vs python/ ruby)?
- gt565k 13y agoI came from a Python background, due to some hardcore Django experience at a co-op job I got, and I found learning Ruby (Rails too) to be a breeze. Syntax and structure-wise, the two are pretty similar. I thought Python had some tricks up its sleeve, but man, the one-liners you can write in Ruby are killer. At the end of the day, programming logic is all the same. If you understand how an algorithm works and have a solid knowledge of at least one language, you're all set.
- matt__rose 13y agoHis fibonacci example in ruby is, well... I've never seen a ternary operation in ruby.