
Should I Learn Python or Ruby? - mjhea0
https://github.com/mjhea0/python-ruby
======
bsder
Pick 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
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?

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
> 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? :)

~~~
fenollp
> Side note: dynamic hash tables just hit Erlang THIS MONTH. So, that's
> probably not a good reason anymore.

What? Erlang's hashtables are called `ETS` and `DETS` and have been there
since at least 1997.

What I believe you are referring to are `maps`, which while they have the
syntax of scripting languages' hashes, are nothing but trees. Access is far
from constant time. Then again Erlang had these a while ago. They are just
adding syntax sugar and pattern matching.

~~~
bsder
I'm not getting into the maps/records/ets/mnesia debate. Yes, you could do it
in Erlang, but it was clunky and verbose.

Maps are what people coming from other languages expect to see, and I wanted
to point out that now Erlang has them.

------
throwawaymsft
> 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
From 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
This 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
Ruby is quickly dying in the ops space.

I wouldn't use either Chef or Puppet today for a greenfield project.

~~~
roflc0ptic
Asking as someone who's trying to figure out continuous integration (and loves
python): what would you use?

~~~
Shish2k
for continuous integration as in build server, I'd use Jenkins; for network-
wide configuration management (which I think is what you were asking), Salt

------
ycmike
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
>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 $&?").

~~~
Freaky
> 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.

~~~
panzi
I 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.

~~~
Freaky
I much prefer it for the simpler cases over "if !x" and "if not x". Would be
nice if people used it more responsibly, but I can say that about a lot of
things.

------
tuke
That'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]

~~~
ioquatix
The 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
It's just one more line - wrapping the function with the memoization decorator
from the stdlib:

[http://docs.python.org/3/library/functools.html#functools.lr...](http://docs.python.org/3/library/functools.html#functools.lru_cache)

~~~
panzi
And it's much clearer on what it actually does.

------
jalan
> 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?

~~~
navyrain
Ruby is the lingua franca of devops; it is an entirely sensible choice for
that purpose.

~~~
pwang
That's kind of a stretch. Bash is the only lingua franca of devops. Perl might
be next, depending on the organization you're involved with. Then Python or
Ruby might be next... hard to even figure out how to objectively measure which
of the two is more popular in the "devops" space.

------
kashif
Importantly, Python has many more libraries and terrific support for
scientific, statistical, AI and math work. Also it has IPython :)

------
bobbyi_settv
> Should I Learn Python or Ruby?

Definitely!

------
hudibras
So I guess the answer is Python.

~~~
tlunter
Or at least, their answer is (which is pretty biased)

------
ZanderEarth32
It 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.

------
gt565k
I 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.

------
tuke
Jezis, 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.

------
amaks
Neither. Learn Go.

~~~
increment_i
Or even better, C.

Baptism by fire, baby.

~~~
ioquatix
X86 assembly is the real deal.

~~~
epsylon
Phew, in my time we used to program directly the magnetic memory cores in
machine code.

Now get out of my yard.

------
fredgrott
Nah why not go all the way, learn Perl

------
nwmcsween
IMO that is very unrubyish code.

~~~
tuke
Maybe, but the hash approach seems kind of silly.

~~~
nwmcsween
I don't think the author really knows ruby, like in you're example in this
thread lambda would work nicely.

------
alxndr
re: 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)

------
matt__rose
His fibonacci example in ruby is, well... I've never seen a ternary operation
in ruby.

------
kayman
Doesn't matter. Pick one and learn it. What you can do in python, you can do
in ruby.

~~~
panzi
The language choice as such does not matter much, but there are different
libraries available for both languages. So you should choose the language that
best suits your needs. E.g. statistic/scientific stuff: Python. Web: Ruby. (My
personal preference is Python.)

~~~
mjhea0
well said

------
gte910h
If you just want to do web dev, probably ruby.

Otherwise, python is probably more versatile

------
cabbeer
How does javascript compare as a first language (vs python/ ruby)?

