Sitemap
// The Commented Section

An Exploration of Programming Opinions

Differences between Ruby and Python

2 min readApr 12, 2015

--

Often, people talk about Ruby and Python being similar. This isn’t true.

While at first glance, they look similar — puts “Hello, World” for Ruby and print “Hello, World” for Python, but there are quite a few differences.

Python’s Whitespace Requirement

In Ruby, whitespace is by no means required. Tabbing should be done, of course, but nothing’s there to stop you from writing code that isn’t indented. In Python, things are different. You must indent every statement by four spaces — no more, no less. Four shall be the number that-

Get trajing’s stories in your inbox

Join Medium for free to get updates from this writer.

Wait. This is a coding language, not the Holy Hand Grenade.

Ruby’s Philosophy

Technically, it’s the Perl philosophy. For those that don’t know, the Perl philosophy is that there should be many ways to solve a problem. Python defaults to the opposite extreme. This is by no means bad, just different.

Blocks

I present you with my favorite feature of Ruby — blocks.

['hello', 'world', '~NL', 'this', 'is', 'a', 'ruby', 'block'].each do |str|
if str == '~NL'
print '\n'
else
print "#{str} "
end
end

Wait, what?

If you’re new to Ruby — and you very well might be, this is a block. As opposed to looping over the array via for or something else, it’s just a convenient little method that executes a block of code with a variable given to it. Very nice.

Conclusion

While there’s probably a bunch more, I’ve covered enough differences for now. Keep in mind that most standards are standards for a reason — they’re different, not better. While some standards keep at it long past when they should’ve stopped *cough*Java*cough*, don’t suggest that someone who has learned language x to switch over to language y, which has similar syntax. Coding languages are like snowflakes — no two are quite alike. And if you find an exact duplicate of a snowflake, it’s probably a pointer.

--

--

trajing
trajing

Written by trajing

Member of the Phoenix Team. Rubyist. Likes science. This bio is way too serious and I can't think of a funny joke.