Posts

Ruby vs. Python

Ruby vs. Python

Which is better, Ruby on Rails or Python and Django?

This is a question we get asked repeatedly. It’s an important question too. You’ll hear Ruby vs. Python compared all the time. If you’re unfamiliar with them, it’s an impossible question to answer. I’ve used them both quite a bit and can tell you that while they’re similar, they’re also different in some important ways.

To set the stage, I first learned web development through Python and Django. After spending four years building Django apps, I got a job doing Ruby on Rails and expected the transition to be really simple. That’s when it became clear to me that the two languages and frameworks are different.

So… How are they different?

The Language:

The Ruby on Rails web framework is built using the Ruby programming language while the Django web framework is built using the Python programming language.

This is where much of difference lies. The two languages are visually similar but are worlds apart in their approaches to solving problems.

Ruby is designed to be infinitely flexible and empowering for programmers. It allows Ruby on Rails to do lots of little tricks to make an elegant web framework. This can feel even magical at times but this flexibility can be good and bad at times. Sometimes code works when you didn’t expect it to and l5eaves you feeling really impressed. Other times the Ruby magic can make it very hard to track down bugs for hours.

Python takes a more direct approach to programming. It’s main goal is to make everything obvious to the programmer. This sacrifices some of the elegance that Ruby has but gives Python a big advantage when it comes to learning to code and debugging problems.

One great example showing the difference here is working with time in your application. Imagine you want to get the time one month from this very second. Here is how you would do that in both languages

Ruby

require8 'active_support/all'
new_time = 1.month.from_now

Python

from datetime import datetime
from dateutil.relativedelta import relativedelta
new_time = datetime.now() + relativedelta(months=1)

The Python version has you importing specific functionality from datetime and dateutil libraries. It’s a lot more explicit, but you can easily tell where everything comes from.

The Ruby version is a lot more magical. We import some active_support library and now all of a sudden all integers in Ruby now have these “.days” and “.from_now” methods. It reads well but it’s definitely not clear where this functionality came from inside of active_support. Plus, the idea of patching all integers in the language with new functionality is cool but it can also be abused and cause problems.

Neither approach is right or wrong, they just emphasize different things. Ruby showcases flexibility of the language while Python showcases directness and readability.

Web Frameworks

Django and Rails are both frameworks that help you to build web applications. They have similar performance because both Ruby and Python are scripting languages. Each framework provides you all the concepts from traditional MVC frameworks like models, views, controllers, and database migrations.

Each framework has differences in how you implement these features but at the core they are very similar. Python and Ruby also have lots of libraries you can use to add features to your web applications as well. Ruby has a repository called Rubygems that you can use and Python has a repository called the Package Index.

Community

Python and Ruby both have very large communities behind them. The community influences the direction of the language, updates, and the way software is built using them.

Python has a much more diverse community than Ruby does. There are a ton of academic use cases in both Math and Science that Python has thrived in. This gives it a lot of support in those areas and it continues to grow because of that momentum. Python is also installed on almost every Linux computer making it the perfect language for use on servers.

Ruby’s popularity really started when Rails came out in 2005. The community grew quickly around Rails and has since been incredibly focused on web development. As time goes on it the community around it has gotten much more diverse but2 it hasn’t seen the same diversity that Python has.

Usage

Who is using these languages? Quite a lot of companies. Both languages and web frameworks are pretty widespread in the tech world.

Python has been by companies including Google, Pinterest, Instagram, National Geographic, Mozilla Firefox, and the Washington Post.

Ruby has been used by companies like Apple, Twitter, Airbnb, Shopify, Github, and Groupon.

Conclusion

Anything you can do in Ruby on Rails you could also do in Python and Django. Which framework is better isn’t really a question of capability, it’s actually a question of what the support is like for you and your team.

My general rule of thumb is this:

If you plan on sticking with building web applications, then check out Ruby on Rails. There’s a very strong community built upon it and they are always on the bleeding edge.

If you are interested in building web applications but would like to learn a language that’s used more generally, check out Python and Django. You’ll get a diverse community and lots of influence and support from the various industries that it is used in.

Either way, you can’t go wrong. Almost everything you learn in Python can be translated to Ruby and vice versa. The same goes for Django and Rails. They both have supportive communities behind them. If you have friends doing one or the other, join them because you can always ask them for help along the way.


Ready to start learning? Check out these courses:
One Month Ruby | One Month Python

Ten Reasons Django Is Perfect For Startups

Should You Use Django for Your Startup?

Tech startups are so hot right now, and it’s never been easier or more fun to build a web application. Django has been rapidly gaining popularity for its ease of use and pragmatic design. Here are 10 reasons why you put Django in your startup’s tech stack.

1. Fully Featured Out Of The Box

A web application framework is basically a toolkit of components that all web applications need. The point of this is to let developers focus on the things that are new and unique about their project instead of implementing the same solutions over and over again. Django is even more fully featured than most other frameworks, coming with everything you need to build a web app right out-of-the-box.

2. Great Community

Django is an extremely widely used framework, and because it’s open source, it is built and kept updated by the developers who use it. The result of this is a framework that never lags behind and lots of available answers when you have questions.

3. Tons Of Coders Available

Python was one of the most popular programming languages of 2014, and is now the most popular language for those learning to code. This means that when your startup blows up on reddit and you need to hire 5 developers, like, yesterday, you’ll be able to find lots of high quality candidates.

4. Lots of Packages

Part of what makes Django so powerful is it’s ability to be extended with ‘app’ plugins. There are hundreds of these packages that make it easy to do things like add google maps, create complex permissions, or connect to stripe for payment processing.

5. D.R.Y.

The core philosophy of Django is DRY: Don’t Repeat Yourself. The framework places a premium on getting the absolute most out of very little code. This means less hours to get it working, less code to break, and less to change when you need to pivot.

6. Portability

Python runs on every platform, Mac, PC, Linux, heck, you can even run it on a toaster (almost), and Django can run wherever python works. As a result, all development and production environments can be supported. More interestingly, Django includes a layer between the developer and the database called an ORM (Object Relational Mapper) which makes it possible to move your whole project between most major databases by changing just 1 line of code.

7. Provider Support

Because Django is a big, well established web application framework, cloud providers go out of their way to ensure it is easy and fast to deploy Django apps to their platform. The best example of this is heroku, which, once set up, enables deployments with a single command from any authorized developer. Result: no bottlenecks on your project because ‘The Deployment Person’ is sick/asleep/on a hot date.

8. Good Documentation

Depending on whether you are a manager or a developer, this may or may not seem like a big deal, but trust me it is. Good documentation can mean the difference between hours of grueling trial and error or effortless implementation. Django provides well-organized documentation and example code tagged for every specific release. On top of that, the code is all publicly available on github for direct investigation.

9. Built-In Admin Panel

One of the things the framework comes with out-of-the-box is a fully featured web interface that gets automatically generated for every app you build. This admin panel lets non-developers create/update/delete users and any other database objects specific to your app. For a startup this means that developers and non-technical staff can instantly work together to manage content or manually try processes before investing time in coding them up.

10. Scalability

Sure Django is great for getting started, but how does it do when your startup hits scale? Surprisingly, still great. At its heart Django is a series of components that come wired up and ready-to-go by default, but because these components are decoupled (not dependent on each other), they can be unplugged and replaced as your startup needs more specific solutions. It’s a lot like starting with a car from the lot and swapping out the parts you want to supe up.

Django for Your Startup?

I used Django to prototype and scale my own startup, DecisionDesk. Recently I used it to build the API server for an android-powered data app for the Ministry of Health of Belize and the IADB. Startups like Eventbrite and Disqus are using it to build out apps that scale quickly.

Want to learn more about Django and Python? Check out One Month Python