Ruby and Python, them and the differences

George - Apr 10 '19 - - Dev Community

Ruby and Python are recognised as two of the most used and popular languages out there with continuous growth each day. Both updated regularly and if you name it then there's likely a library, API or something made for your usage. But as Ruby grows so does it's user count, will Ruby become more popular than Python?

Quick disclosure: I'll look at some of the major aspects of each language, but will not be looking at APIs, libraries etc unless it's specific to that topic.

History

Before comparing anything I believe it's always important to look at history. Python invented in 1991 by Guido Van Rossum and Ruby invented in 1995 by Yukihiro Matsumoto are now two of the top 10 languages in the world. Ruby is intensively used in some of your favourite websites, Twitter, Github, Airbnb and even Dev.to. Python as well used in Google, YouTube and Dropbox. There's no doubt about it that since their inceptions they have changed the development industry.

Syntax

We all know that the syntax of a language is essential to a programmer, some people like Java syntax, some like Python heck some people like Brainfuck.

Ruby is designed to be a flexible and empowering language however the flexibility can cause some problems. The magic that makes Ruby when you never expect it can also make it a pain to track down bugs resulting in hours and combing through code while combing through your hair.

Example of Ruby's syntax

def hello_world()
    puts 'Hello world'
    name = gets.chomp
    puts = "Hi #{name}"
end
Enter fullscreen mode Exit fullscreen mode

Python, on the other hand, is designed to be a more simpler approach with indentation instead of curly brackets or keywords. The goal is to make everything visible to the developer and in some sense, it sacrifices some of the elegance that Ruby has to give.

Example of Python's syntax

def hello_world()
    print('Hello world')
    name = input('Enter your name')
    print(f'Hello {name}')
Enter fullscreen mode Exit fullscreen mode

Web development

Seeing as there are a lot of web developers here at Dev.to it'd be stupid not to talk about web development. There are two main frameworks for both languages. For Ruby rails is by far the most popular, with Python there are two depending on what the end goal is which are Django and Flask. For this, I'll be using Django as the comparison. Lets look at the pros and cons...this was hard to determine in some area.

Rails pros

  1. Faster to spin up new projects
  2. Less code to make everything happen
  3. Larger rails community
  4. Easier migration
  5. Incredibly easy to deploy

Rails cons

  1. Can become bloated - Rails is bundled with a bit of unnecessary code, less senior developers may not understand it
  2. If you need to bundle data analysis, big data functionality then Ruby wouldn't be the place to go
  3. Less code conventions to follow, sometimes code works and it's hard to know why

Django pros

  1. Tighter syntax
  2. Ships with comprehensive portal premade on setup
  3. Strong middleware layers
  4. Djangos REST framework is one of the best out there
  5. Scalable caching system

Django cons

  1. Isn't asynchronous by default
  2. Really overkill for smaller projects
  3. Everything gets deployed together

I won't comment on which is better as I'm newer to Rails/Ruby than Django/Python however from researching both they clearly have their merits and cons. If you're looking for something to use for a website then either of these will work perfectly for your website, but always dependant on the needs of the site.

Community

Both Ruby and Python have substantial communities behind them all over the place, forums, slack groups, discord servers etc wherever you look you will find an active community that is here to help and guide you. Each of the communities are influenced by the direction of the language and the software built behind it.

Python has a much broader community than Ruby does. Both languages have a ton of academic use cases in both math, science, programming etc. But this doesn't mean Rubys community is at a stand still, it's a language that continues to grow each day.

Ruby's popularity really kicked off when Rails came along in 2005, the community fell in love with and has been incredibly focused on web development. In addition it's diversity is still growing at a rapid pase.

Cybersecurity/Pen testing

Both Python and Ruby are highly used for cybersecurity, sec ops and pen testing with humungous communities behind them. Wherever you look on this topic you'll find what you're looking for, for example Ruby has Metasploit developed by Rapid7 one of the most used tools in pen testing with Python having Nmap and Scapy. Both developed and used on a daily basis.

Python pros

  1. High performance
  2. Extensive support
  3. Wherever you look you'll find what you need
  4. User-friendly data structuring

Python cons

  1. Bundling the libraries and tools together can be a pain in the ass
  2. Some of the libraries/tools are paid
  3. Often Python version specific

Ruby pros

  1. Nicer syntax
  2. A lot of what's required is built into its standard lib and language (mutable strings, fragmentation etc)
  3. Highly scalable

Ruby cons

  1. Smaller community
  2. Some of the libraries/APIs required are no longer maintained
  3. Some companies don't use it so if you're going in as the only one good luck.

Package management

Both Python and Ruby have incredible package managers. Neither of them can be faulted with Rubys RubyGem and Bundlr and for Python having Pip(3) and Anaconda both of them do an incredible job of installing, maintaining and finding packages that are required. Whichever language you look at you won't be disappointed with them.

Personal opinions

Both are exceptional languages, which like every other language have their pros and cons. As someone who has written Python a lot more than Ruby and is now learning Ruby extensively I can say with a slight margin I'm starting to like Ruby more than Python. The syntax, flexibility and capabilities are beyond my beliefs, it has turned out to be a fantastic language and now really starting to see why people love Ruby so much.

Conclusion

Will Ruby kill Python? In my opinion no. It's always going to be dependant on the end use case and the developer some people will always prefer X over Y because of personal preference but the way I see it is that Ruby will continue to grow alongside Python but Ruby will be more looked at for web development using Rails over Django/Flask, we can't predict the future but both of them are already incredible languages and will continue to grow as they go on.

What do you think?

EDIT: Changed the title

. . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player