Posts

Some People Say Ruby Is Too Complex for Beginners…

Is Ruby the right programming language for beginners?

One of the biggest criticisms I hear lobbed against learning Ruby as a beginner language is that Ruby has so many different ways of doing things. People say that these different ways of doing the same thing makes it hard for beginners to learn.

To be specific, here’s one example of this argument that I read on reddit recently in response to my earlier post, Why Beginners Should Learn Ruby on Rails:

“Ruby almost always has 100 ways of doing any problem, and frequently the user-submitted examples on Stack Overflow are meant to dazzle rather than instruct.”

or

“So much shorthand and so many options that when I’m trying to learn one particular function, I get 100 different users telling me to do the problem 100 different ways, none of which helps me understand the thing I’m trying to learn.”

This is true.

Ruby in particular has lots of instances where there are multiple, equally good (and sometimes not equally good), ways of solving the same problem. But rather than that being a weakness of Ruby, I actually think the flexibility of the language is an incredible strength, especially for beginners.

But rather than that being a weakness of Ruby, I actually think the flexibility of the language is an incredible strength, especially for beginners.”

You see, there’s no one way that you learn something, and whichever way sticks is usually the best for a beginner.

Here’s an example.

In Ruby, there’s the select method (in Ruby, functions are called “methods”), which lets you take a list of things and pull out a sub-set of that list.

It looks like this:

list_of_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
list_of_numbers.select { |number| number.even? }

Even if you’ve never coded in Ruby in your life, read that second line and take a guess at what you’re going to get. That’s right, you’re going to get the sub-set of even numbers: [2, 4, 6, 8, 10]

There’s a second way to do the same thing. It’s called the find_all method.

So instead, you could write:

list_of_numbers.find_all { |number| number.even? }

What do you think you’ll get here?

Right! It’s exactly the same result as the select method.

So why does Ruby have at least two ways of doing exactly the same thing?

It’s because the people who created Ruby were inspired by a few other programming languages — Perl, Smalltalk, and Lisp are a few — and they borrowed the different names for doing things from those languages. Also, it happens to be really easy to write a method once in Ruby and just point other methods to it. That’s not as easy to do in other languages.

So why is this an advantage?

Well, because you don’t have to remember both of these ways of doing things! You just have to remember the one that works for you. I almost always use select.

Doesn’t this get confusing? Maybe, if you’re looking at lots of different people’s code. But by that point you’ve already learned that select and find_all are the same, and it’s not so hard to figure out. Language is a lot like this. There are many ways to say the same thing in English:

Language is a lot like this. There are many ways to say the same thing in English, which enables creativity.

I’m happy, I’m cheerful, I’m pleased, I’m delighted, I’m jolly, I’m beatific, I’m glad, … do I needto keep going?

The flexibility actually opens up creativity, which I think is one of the coolest parts about a language like Ruby. Meanwhile, in most other languages when there’s only one way of doing something, if you don’t remember that way then you’re screwed.

Another clear example that people like to hate on all the time: parentheses.

In Ruby, parenthesis are optional in methods. So are brackets { } a lot of the times, and you can basically use either single quotes or double quotes interchangeably.

Take that same list from before:

list_of_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

What if you wanted to see if it included a particular number?

You could use the include? method:

list_of_numbers.include?(2)

But you could also leave out the parentheses in this case (and lots of Rubyists do) because it’s prettier and easier to read:

list_of_numbers.include? 2

Sure, there’s a few rules about this. You have to put a space beforehand instead of parenthesis (otherwise Ruby would think you were trying to run a method called include?2 which doesn’t exist).

The point is, you can try many different ways of getting at the same issue, and get an answer to your question in many ways. Rather than get stuck on needing to know the exact way to write something, you can solve your problem in more than one way.

The same is true for software applications, like AutoCAD. As a user, you can type into the command line, navigate towards a button, or use drop-down menus. In addition, you can choose to draw a line with at least eight different tools (line edit, polyline, arc, points, etc). One way isn’t better than the other — they’re just all different tools for drawing. Having many different ways to get shit done makes it easier for people to remember the technique that works best for them.

Flexibility! It’s a beautiful thing.

I’ve never understood why people thought that having multiple ways of doing something was a bad thing. When you’re first learning, you have to grasp and understand whatever concepts you can, as a starting point.

Meanwhile, a language like JavaScript is a truly hard language for beginners to learn, because there are so many specifics that don’t come naturally to a beginner, and you have to do them that way. I’m not saying you can’t learn it, but the amount of times I’ve heard beginners so frustrated they were ready to give up because they’ve forgotten a “;” somewhere and have no idea where.

If you’re interested in reading more about why Ruby is a great language for beginners, check out Why’s (Poignant) Guide to Ruby. It’s one of the most beautifully and interestingly written pieces about programming, and is one of the biggest reasons I fell in love with Ruby in the first place.

And then, if you want to learn more about Rails, watch our free one-minute video or check out our Rails course to go build your first app.

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

The Perfect Follow Up To One Month Rails

Why should someone who already took One Month Rails take One Month Ruby?

Well, for one, you know very little about Ruby so far. Sure, we did some basic stuff like if… then. And we created a few variables. But Ruby is a wonderful language, and your ability to get stuff done in Rails is only like 20% of what it could be. There’s so much more still that you could do that you don’t even know about!

Have you wanted to expand the functionality of your Rails app? Take the Ruby course. If you want to be able to get a job as a developer, you HAVE to get a better understanding of Ruby.

When I was first learning how to code, I built my first Rails app and then I hunkered down and learned as much Ruby as possible.

I went through Codecademy’s Ruby tutorial. I went through other resources like Ruby Koans and Ruby Warrior. My favorite were two books: one called Practical Object Oriented Design with Ruby by Sandi Metz and one called Why’s (Poignant) Guide to Ruby.

That was when I first fell in love with Ruby. It’s an incredible language. It’s really powerful, so much fun to use, and it’s got an amazing community.

If you enjoyed One Month Rails, you really should take One Month Ruby.

For years Rails students have been asking me to create a Ruby course because they feel like they wanted a deeper understanding of the language that Rails is based on. So that’s what I’ve done.

Why else should Rails developers learn Ruby? Well, obviously Rails is built in Ruby. If you took Rails, then you can do it. But, if you want to understand it, you had better learn Ruby.

That’s probably the biggest most obvious reason.

There are things you can do in Rails that you can only do if you know Ruby. For example, writing web scrapers and interacting with APIs. All of that is outside the bounds of what Rails is meant to cover, so you’ll have to know it if you want to do anything more advanced. If you want to automate stuff. If you want to be a better coder. This is the next step.

10 Reasons Beginners Should Learn Ruby on Rails

If you’re new to programming, what language should you learn first?

I often get asked the question: “What programming language should I learn?”

If you’re totally new to programming I highly recommend Ruby on Rails. In this post I’m going to give 10 reasons why I think new programmers should start with Ruby on Rails.

1. Ruby on Rails is a web application framework.

It is NOT the same thing as Ruby. Ruby on Rails is basically a collection of shortcuts written in Ruby that lets you build web applications — basically websites — really quickly. The benefit to learning a web application framework (like Ruby on Rails) before learning a programming language itself (like Ruby) is that you’ll make quicker progress in the beginning, you’ll have a real site that you can share with friends, and you’ll see how the things you’re learning actually apply to the things you want to be able to do.

2. Some of the biggest websites in the world are built with Ruby on Rails.

Basecamp, Airbnb, Bleacher Report, Fab.com, Scribd, Groupon, Gumroad, Hulu, Kickstarter, Pitchfork, Sendgrid, Soundcloud, Square, Yammer, Crunchbase, Slideshare, Funny or Die, Zendesk, Github, Shopify.

Enough said.

3. Lots of startups are hiring for Ruby on Rails.

It’s not the most in-demand thing to learn for jobs in general — there are way more job openings out there for things like Java, PHP, even Python — but in terms of working at a startup, great Ruby on Rails developers are some of hardest people to find. This is mostly because…

4. Ruby on Rails is full-stack.

Unlike most languages — like (HTML/CSS, Javascript, Python, and SQL) — Ruby on Rails covers both the front-end and the back-end. That means one Ruby on Rails developer can build an entire web application, without having to rely on someone else to build the back-end or front-end for them. A nice side-effect of this is that if you learn Ruby on Rails, you’ll end up learning a bit of HTML/CSS, Javascript, and Ruby along the way. That’s not the case at all if you just start with any of those languages.

5. Ruby on Rails has a thriving community.

The Ruby on Rails community is one of the most active out there. There are tons of conferences you could go to, meetups going on in every major city on almost every day of the week, online forums like Stack Overflow, and you’re almost guaranteed to find Ruby on Rails developers at any hackathon you go to. That means it’s easy to reach out to someone if you ever need help.

6. The Ruby on Rails community is very beginner-friendly.

On top of being a thriving community, for some reason Ruby on Rails and Ruby developers are among the friendliest out there (this is purely anecdotal, I have no evidence for this). I suspect this has to do with how new the framework is, and so almost everyone remembers what it was like to be a beginner.

7. There are a lot of great online resources for learning Ruby on Rails and Ruby.

Literally dozens. Check out: the Ruby on Rails Tutorial, Rails for Zombies, One Month Rails (that’s me!), Treehouse, Lynda.com, Codecademy, Learn Ruby the Hard Way, Why’s (Poignant) Guide to Ruby, and many, many more.

8. Ruby itself is a forgiving language for beginners.

At the end of the day Ruby on Rails applications are mostly written in Ruby, so it helps that it has a few features that make it especially good for beginners to learn. Unlike Javascript and many other languages, you don’t need to remember to end your lines with a semicolon (;). Unlike Python and some other languages, whitespaces and tabbing doesn’t matter. A lot of the times, you can leave out things like parenthesis () and curly brackets {} and it doesn’t even matter! Ruby knows what you meant. On top of that, Ruby is very readable. Check this out:

5.times { print "Odelay!" }

This little example (courtesy of Why) does exactly what it says. Try reading it out loud. Five times print “Odelay!” Compare that to the same thing in Java:

for(int a = 1; a < 6; a++){
 System.out.print("Odelay!");
}

The second is much harder to read and understand as a beginner.

9. Ruby on Rails hides a lot of the stuff you don’t need to know.

You won’t need to know any SQL to use a database in your Ruby on Rails application. That is awesome. In most cases, Ruby on Rails will just make an assumption about how you want to do something unless you tell it otherwise. That makes it particularly easy for beginners who aren’t going to know or care about customizing every little thing about their application when they start.

Another example is the beautiful way that Ruby on Rails treats pulling in third-party code and keeping it up to date for you. Also it does a bunch of security stuff for you for free, like preventing SQL-injection in most cases, cross-site scripting, session hijacking, and much more. Other languages assume you know how to do that stuff on your own. It also comes with it’s own server for running locally.

10. Ruby on Rails teaches you development best practices.

Because Ruby on Rails makes a lot of assumptions about how you should do stuff, it forces you to do stuff the commonly accepted way, at least at first. This includes RESTful resources, MVC framework, testing (it includes a testing framework by default), and much more.

These are only a few of the reasons I could think of for why a beginner should learn Ruby on Rails. Honestly, if you don’t already know about programming, most of this stuff will go over your head. But the point of this article is to convince more experienced developers to stop telling beginners to start with stupid languages like PHP, and also to show beginners that there are significant, and well though-out reasons for a beginner to start with Ruby on Rails, even if you don’t understand what they are.

If you have any concerns or questions that I haven’t covered, please post them below and I’ll try to respond as quickly as possible!

What is Rails?

Key Takeaways

Ruby on Rails allows you to build websites with code — quickly.

Ruby on Rails is the back-end language. When you choose it, you’ll also be using HTML and CSS.

Here are three reasons why you should get started with Ruby on Rails:

  1. It’s easy for a beginner to learn.
  2. There are a lot of jobs for Ruby on Rails developers.
  3. Some of the biggest websites in the world use Ruby on Rails: Hulu, Twitter, Funny or Die, Shopify, Codecademy, and Kickstarter.

How to Learn Rails Today

Additional Resources to Keep You Learning