3 reasons you should start with Sinatra

As a junior developer, you pretty much learn Ruby through Rails. It’s the most popular framework, the community is fantastic, and businesses look for experience in it. And I pretty much agree, it’s awesome.

But if I had it to do over again, I would start with Sinatra. And here’s why.

1. It can actually make your code easier to understand

In the beginning, we need all the help we can get. I would often come back to code I had written in Rails after a few weeks and was a bit disoriented. But with Sinatra, your code must be more explicit.

A simple illustration:

# rails
def list_stats(data)
data.descriptive_statistics
end
puts list_stats(Player.weekly_stats).variance.round(2) => 7.72

Where are these methods coming from? And the Player model? Like a lot of things in Rails, it just works…sweet! However, it’s not so easy to understand what’s actually happening.

Now imagine this:

# sinatra
require 'descriptive_statistics'
require 'model/player'
def list_stats(data) 
data.descriptive_statistics
end
puts list_stats(Player.weekly_stats).variance.round(2) => 7.72

Sure, it’s a few extra lines of code, but we’ve removed all doubt on where things are coming from. And if I have any additional questions regarding those methods, I know exactly where to look.

2. It encourages design feedback

Most of us know how to follow a tutorial. For learning some of the more fundamental concepts, it works. But once we start expanding outside of that scope and building our own stuff, we need help writing good, clean code.

As a by-product of having to require our dependencies, as shown above, Sinatra can serve a useful purpose.

If I have a class with too many dependencies, Sinatra is letting us know that it’s taking on too much responsibility. Now I can begin to break up that class rather than adding to it.

3. It’s really all you need…for now

For the most part, we aren’t building large, full-scale applications. Rails is undoubtedly better suited for those kinds of projects. It comes fully loaded, and solves a lot of the common problems you would eventually have to solve yourself with Sinatra.

But for most projects, Sinatra can guide you through what some of those common problems are without sacrificing much time. It’s not going to do everything for you. But I think that’s the point.

Sinatra is an opportunity to remove the magic Rails provides, without feeling lost. You can dig under the hood, without being overwhelmed.

And eventually, you’ll realize there wasn’t that much to be afraid of to begin with.