Hacker News new | ask | show | jobs
Ask HN: As a Python developer, what am I missing for not using Ruby?
33 points by 15DCFA8F 3634 days ago
Over the last couple of years I have been programming in Python almost exclusively (and some JavaScript, Bash and Go for some specific tasks, easily chosen for the task at hand instead of Python).

What I found with Python is that it is a great platform for doing my things, like web services, data transformation, general Linux automating, infrastructure monitoring, and so on.

As it is good enough for 90% of my needs, I settled down on it and now I feel that I am missing opportunities of being more productive and getting more knowledge from other languages.

I looked at Ruby and found some interesting aspects (as a former Perl programmer), with its expressiveness. I learned a bit of Ruby, but I keep doubting myself if Ruby language and platform would bring me more value or that would only bring fragmentation on my projects.

I do not look to replace Python, but want to know if there would be some clear decisions points to take when choosing between Python and Ruby for my next projects, or both are more or the less a tool to solve the same problems.

If any of you worked or work with both languages, sharing your experiences would be greatly appreciated.

16 comments

I'm a mostly Python / occasionally Ruby web developer.

There isn't much you're missing. About the only use-case I can think of where Ruby has a clear advantage is in creating a DSL.

Other than that, there are differences in what already exists in the two ecosystems, but (at least for web development) generally there are equivalents available (eg. Nokogiri vs. BeautifulSoup). The Rails and Django frameworks are roughly comparable, for example, with Rails being more 'magical' vs. Django being more explicit. Which one is better for you may just come down to your personal tastes.

Now, outside of web development, Python has a clear advantage in areas such as scientific computing, game development, machine learning, and many other areas in which Ruby doesn't really have much of a presence. This isn't due to any inherent quality of the two languages, just historical contingency, as Ruby's emergence from obscurity was a result of Rails taking off, whereas Python grew a large and eclectic user community (of which web development was a small part) more slowly, but starting years earlier.

> There isn't much you're missing. About the only use-case I can think of where Ruby has a clear advantage is in creating a DSL.

But whether or not creating a DSL is a good idea or not is a whole nuther question. I find that there is a cost to all the Ruby features that make DSLs easy.

If I may make some sweeping and possibly trite generalisations between the Python and Ruby communities... Ruby fans value the happiness of the programmer writing new code, while Python fans value the happiness of the programmer having to read or debug someone elses code.

Typical Ruby projects often go to great lengths to provide an elegant API even if it makes the internal implementation more complex. Typical Python projects seem to prefer clearer simpler implementations at the expense of a slightly clunkier (compared to Ruby at least) API.

I don't know if Pythons "consenting adults" attitude about not hiding internal details contributes to this. eg private methods are a language feature in Ruby (and most other languages), but just a non functional naming convention in Python.

There's probably also something to do with Rails being a formative philosophy for a lot of Ruby coders. Ruby coders from outside the Rails world often seem value more explicit code with less desire for complex 'magic'.

Also, while ruby may be better at DSLs, python's not bad at them by any means. All the __magic_methods__ that enable stuff like operator overloading and intercepting "obj.attr" references, etc make it pretty easy to make a pretty reasonable looking DSL pretty quickly.
> About the only use-case I can think of where Ruby has a clear advantage is in creating a DSL

Yep. Chef and Puppet (machine configuration tools) are written in Ruby.

Ansible is written in Python and they didn't have to invent a DSL to make it work ;)
Ansible is written in anything that generates json
Ansible itself is written in Python, but yeah, the plugins can be written in pretty much anything.
As a python programmer for over 15 years, you will be better served by learning a PL from a different paradigm

* Erlang/Elixir -- concurrency

* OCaml/Haskell -- static typing etc.,

* Typescript/Elm/Purescript -- better Javascript

* You get the idea ...

more so than Ruby. Ruby lives in the same neighbourhood in the galaxy of programming languages. You are not missing much by ignoring Ruby.

If you're going to learn another language, learn something from a different programming paradigm, or one which is lower level.

Learning Ruby would be an absolute waste of time.

This isn't a hip or cool answer, but I'd suggest learning Java. It's one of the most popular languages by a large margin, and knowing it will help you speak the object-oriented lingua franca. If you only write Python, you're probably mostly writing procedural code. Learning OO is a good idea.

This is so wrong I don't even know what to say.

Python is a beautiful object oriented language. Very much so.

Java is not different at all, I'd say go for Haskell or similar to get something really truly dif

Python has all of the constituent parts of an OO language, save explicit types, but it is never written in an OO style.

Using classes != OO.

Generally, Python programmers treat objects as structs with associated methods, basically the Go model. Python programmers rarely encapsulate at all. At best, they use a bunch of accessors (which is not itself OO). Implementation details are rarely hidden.

That's because dynamically-typed languages, the interpreter, and the Python culture, lend themselves more to exploratory programming, rather than a UML-design, with objects that relate to real-world entities, that are implemented after careful planning.

If you can show me a Python program where objects are really encapsulated, and aren't chock-full of accessors, I'll stand happily corrected.

I've been a Ruby (not rails) developer for 10 years and use python when hacking together hardware projects.

Generally speaking Ruby has a better standard library, the major libraries (gems) seem to be better built with nicer APIs and unit tests.

I think the best example of Ruby at it's best is the Sinatra web framework.

Having said of this, I don't think that Ruby is the language of the future.

In my humble opinion the language combination of the future is going to be Python as my interpreted language of choice + Swift* (for when I want a more strongly typed / functional language or when I need things to be fast).

* Swift could be my only language if they had an interpreter.

Hi Marcus, have you ever taken a look at Nim? It's quite similar to Swift in several respects, but it has a primarily Python-like syntax (including indentation by blocks rather than braces) with bits of Ruby & others mixed in.

Useful links: http://nim-lang.org/ , http://nim-lang.org/docs/tut1.html , https://nim-by-example.github.io/ , http://nim-lang.org/docs/manual.html

At work, we use Python as our interpreted language & Nim as our fast, strongly-typed, compiled language. We created Nim-Pymod to enable Nim code to be compiled into Python modules: https://github.com/jboy/nim-pymod

There's also a web-framework in Nim called Jester, which describes itself as "a Sinatra-like web framework": https://github.com/dom96/jester

Embarrassing confession. I've looked at Nim before and don't want to use it because I think the crown is a ridiculous logo. Not being big on authority and not being big on people that think too highly of themselves, I'm suspicious of the entire project simply because of that poorly drawn crown.
> At work, we use Python as our interpreted language & Nim as our fast, strongly-typed, compiled language.

You most likely didn't mean to, but your sentence implies that Python is not strongly typed.

Just in case anyone else is tired and drew a blank and needs to google that, the confusion was that of strong vs weak not dynamic vs static. Strong vs weak applies to explict vs implicit type changes. Dynamic vs static applies to run time or compile time type assignment.

http://stackoverflow.com/questions/11328920/is-python-strong...

Ah yes, good catch. I meant "statically-typed".
Thanks for the tip, I'll have to check it out!
I like what a friend of mine who went from Ruby to Python said... "Python is easier to understand, harder to love."

For me personally:

* I like Rubygems & Bundler more than Pip

* I find the split between Python 2.x and 3.x to be obnoxious

* Python whitespace indentation bugs me a lot

TL;DR -- Python isn't much different than Ruby in terms of what it can and cannot do. Personally, my new favorite language is Elixir, which does a whole bunch of stuff neither Ruby or Python does particularly well.

I hate whitespace indentation on principle (and practice of copypasting code written in a different editor). But after spending too much time trying to parse endless )})})}}} in JavaScript, the Python approach seems like a much better way of doing it.

It seems like pure C programmers are pretty well behaved with their curly braces through.

Any radically different blocking paradigms besides indentation and parenthesis-like things?

The same indentation Python uses in lieu of closing curly braces, can help your issue, so instead of:

    [].map(function (foo) {baz(bar(foo))});

You could write:

    [].map(
        function (foo) {
            baz(
                bar(foo)
            )
        }
    );
Alternatively (or in addition to that), use a decent IDE, which will highlight matching parenthesis, curly braces, allow code folding, etc.

I've never heard a builder say "I don't like screws, nails are better because they work better with my hammer".

I disliked Pythons whitespace when I first started using it. Then after a while I went back to update a Perl script, moved some blocks of code around, then got the dreaded missing brace problem. Its worth it to eliminate that problem alone.

Now the only problem I have with whitespace, is when I switch to other languages and forget a semicolon at the end of lines.

Lua and Ruby use the keyword "end" to signal the end of a function or loop. I much prefer that.
From a practical point of view, I'd agree with others: you're only missing a checked box on your resume.

From a non-practical point of view, you're missing out on the pure joy of writing Ruby. Everyone should try it at least a couple of times to see just how expressive and fun programming can be. As someone who programs regularly in Python, Go, JavaScript, and Java, Ruby blows them away in FUN points.

As a side note, it would be awesome if someone wrote a Ruby -> Python compiler. I would love to be able to call NumPy from Ruby code. I would even be happy with a (generous) subset of the language. I think gluing together Python libs with Ruby would be a pleasure, and people could start using DSL magic to implement better APIs for existing libraries.

I was a Rails dev for a few years and have now moved to Python, but only because I now do more data analysis and little web dev.

You're not missing much...in terms of practical benefits, you're missing out on putting Rails on your resume. In terms of programming experience...you're missing out on the meta-programming and fun monkey-patching that Ruby's syntax invites. And multi-line lambdas.

As someone who loves Ruby, I could not argue that learning Ruby is an optimal use of time for the Python programmer...you'd be better off focusing on something lower level, like Rust, or highly differentiated in paradigm, such as Elixir. FWIW, a notable number of well-known Ruby devs have left the fertile life of Rails dev to pursue those two languages.

You basically have multi-line lambdas in Python, it's just not anonymous anymore -- you can define function bar inside of function foo and then pass it to another function or return it from foo. I've used this to make a function that builds functions for you.
I use Python whenever i can, but had some Jobs where i was doing mostly Ruby on Rails.

For me some of the differences are:

* gem > pip

* Ruby on Rails is much more mature than Django. The framework itself and the surrounding gem ecosystem... it's like its 3 years ahead of Django. Don't get me wrong, you can get anything done i either framework, but Rails just gets it right more often and is better suited for modern web development. You get a testing/dev/production setups, a asset pipeline and a lot of other stuff right out of the box, where as in Django you find yourself fidling with third-party packages of varying quality. * you can build very neat DSLs if you are into that

On the other hand:

* Outside of web development; Python seems to have a broader selection of high-quality libraries (especially in the analytics/datascience category)

At the end of the day, i think both are pretty much equal suited for most tasks.

IMO Ruby and Python are two sides of the same coin. They have their differences but whatever you can do in one you can usually do in the other. I'm a Python programmer myself and I find the "magic" of Ruby code I've seen slightly unsettling at times, explicit is better than implicit after all ;-).

One of the main disadvantages to Ruby, based off my limited knowledge of Ruby, is that if you are making a web app with Ruby you are making a Rails app. With Python Django is probably the most popular but it's far form the only one (Flask, Bottle, Falcon, Web2Py, CherryPy, Pyramid, Zope, etc.).

If you are interested in learning another language I would suggest Go. The syntax is easy to pick up if you are a Python dev and it can do a lot of really cool things with a pretty small amount of code.

DISCLAIMER: I have only done the most basic of Ruby tutorials but none of them have inspired me to learn more.I also hate ``end``.

Ruby can be used the same way as perl when building commandline tools that use repl and regex. ($~,$1,$2, etc.)

You can also add new methods to classes and you can override callbacks such as method_missing to respond to method calls at runtime.

You also have a choice between lazy and non-lazy versions of map/reduce/select.

You also have a rust interface to create gems that run native code.

You also get an extensible build tool called rake.

You also get RoR5 if you enjoy that kind of thing.

You can write Rust extensions to Python as well, though the higher-level interfaces aren't quite as far along in Python yet. There was a talk about it at PyCon last year.
Ah, I actually forgot about the rust-cpython package. The project is alive and it works with python3, too.

That brings me to another point I want to make. There is no community-breaking divide between ruby versions. People usually pretty easily port their 1.9 gems to newer 2.x APIs without breaking much.

Tokens insread of strings as keys. Ruby has :tokenname instead of “tokenname“ as option for key like parameters
Possibly the Ruby feature I miss most in Python.
There's on beautiful thing you're missing at the language level: method_missing. So much of ruby's power is derived from this one feature.
I'm in the reverse position of knowing Ruby but not knowing Python. What am I missing out on by not knowing Python?

It seems machine learning is one thing, that is much better supported from Python, but anything else?

There is a wide range of scientific computing libraries for Python. I'm fairly sure none of them have been ported over to Ruby.

If you're not interested in that not much.

I'd say the only thing that's different between the two languages is when you ask "How do I write fast Ruby" the people who work on the VM and libraries yell back "Here are N fixes that improved the speed of the runtime two fold."

When the same question is ask, but as "How do I write fast Python" there is a resounding "You write C/++, not Python."

I think that's, in my opinion, the biggest differences between the languages: their community's and their community's attitude to optimizations.

> When the same question is ask, but as "How do I write fast Python" there is a resounding "You write C/++, not Python."

Cython and PyPy get you pretty far.

"You write C/++, not Python." - That's present in ruby as well, there are a few ways to embed C code in ruby to get speedups.
The only thing I've ever felt I'm missing in Python, in comparison to Ruby, is the 'unless' keyword and much nicer metaprogramming.
I am on Win/.NET, am I missing something?
Thick rimmed glasses and a bushy beard.