What to Know About Learning Python after Programming in Ruby

What to Know About Learning Python after Programming in RubyConnor FinneganBlockedUnblockFollowFollowingMar 6As I wrap up my 15-week experience at the Flatiron School, I’m both looking back on how much we covered in such a short span of time and thinking about what to learn next.

I’ve always been curious about Python, partially because of its continued rise in popularity.

According to HackerRank’s 2019 Developer Skills Report, Python was the fourth most popular among surveyed developers in 2018, with 57% of developers saying they know the language (up from 49% in 2017).

Python is one of the most rapidly growing languages in the programming worldRuby was the back-end language we learned at Flatiron School, and while the two object-oriented languages have a decent amount in common, I decided to look at a couple of the key high-level differences that would be good to know for someone trying to learn Python after programming in Ruby in a while.

Elegance vs.

ExplicitnessYukihiro Matsumoto, aka Matz, invented Ruby with the goal of it being pleasant for programmers to use, saying:“I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy.

That is the primary purpose of Ruby language.

” -MatzAs a result, Ruby has a lot of out features running under the hood that allow the programmer to write code with “syntactical sugar”.

This enables programmers to write code that looks very elegant, with the tradeoff that it may be a little harder to read and debug, especially for someone with less experience.

Python, on the other hand, seeks to be more explicit and prioritizes readability over elegance.

The first four guiding principles listed in the Zen of Python are instructive to illustrating this difference in philosophy:“Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

”- The Zen of PythonPython also prizes beauty in code, but it values clarity above all else.

If both are impossible, the language steers programmers to writing explicit, easy-to-understand code that sacrifices some elegance.

The ternary operator in the two languages offers a helpful illustration of this difference in philosophy.

Here’s the Ruby approach to testing if a number is positive or negative:result = x < 0?.'Negative' : 'Positive'Short and sweet with the taste of syntactical sugar.

Compare this to Python’s approach:x, y = 50, 25small = x if x < y else yIt’s a little more verbose, to be sure, but it’s also easier to understand if you’re new to the language, in a hurry, or have been jumping around between languages and projects.

Neither approach is necessarily “correct,” but it’s important to understand these underlying differences.

Flexibility vs.

ConventionThe other key difference between the two languages centers around the concept of flexibility.

From the Ruby docs:Ruby is seen as a flexible language, since it allows its users to freely alter its parts.

Essential parts of Ruby can be removed or redefined, at will.

Existing parts can be added upon.

Ruby tries not to restrict the coder.

 – About RubyThere is often more than one way to tackle a problem in Ruby.

This is seen as a feature, not a bug — the language is there to give the programmer to freedom to do whatever they please.

This is why it’s fairly easy to to redefine and add the methods that come built in to Ruby’s classes.

On the other hand, the Zen of Python feels differently…In the face of ambiguity, refuse the temptation to guess.

There should be one — and preferably only one — obvious way to do it.

-Zen of PythonThis is part of why Python is widely regarded as one of the best languages for someone completely new to programming to learn.

In addition to the emphasis on clear, readable code, this guiding belief that there should ideally be one clear solution to every problem is helpful for someone learning programming for the first time.

There are many more key differences between the two languages the further you drill down, as this Stack Overflow response thoroughly details.

Before you even dive in to writing code, though, these high-level differences are important to understand.

Resources:Ruby vs.

Python – One MonthRuby is designed to be infinitely flexible and empowering for programmers.

It allows Ruby on Rails to do lots of little…learn.

onemonth.

comThe 'ugliness' of Python | Wit.

io, by David JacobsThis is a look at functions and objects in my favorite languages.

In 2010 as a Ruby guy, I decided to learn Python.

I…wit.

ioSwitching from Python to Ruby: Learning the Language DifferencesPrior to starting Viking Code School a month ago, I was writing automated tests exclusively in Python.

I consider…medium.

com.. More details

Leave a Reply