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.
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.
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'.
Yep. Chef and Puppet (machine configuration tools) are written in Ruby.
* 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.
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.
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
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.
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.
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
You most likely didn't mean to, but your sentence implies that Python is not strongly typed.
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.
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?
[].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".
Now the only problem I have with whitespace, is when I switch to other languages and forget a semicolon at the end of lines.
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.
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.
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.
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``.
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.
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.
It seems machine learning is one thing, that is much better supported from Python, but anything else?
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.
Cython and PyPy get you pretty far.