Sometimes Less Is More.


While that would have been a clever title for a post about the CSS pre-processor, {less}, this post is about much more. It’s about the merits of low-level, modular frameworks like Sinatra and Express and told in a way that sounds mildly like a Sinatra love story. Sorry if I gush about it, I can’t help myself..

In the Ruby world, they say once you go Rails, you never go back. And while that may be the case for most Ruby programmers for its abudence of included libraries and a massive repository of gems (packages of code) to fill in the gaps, I was recently assigned a code challenge that didn’t seem to require Rails’ V12. At the Flatiron School I had built a few basic apps using Sinatra as preparation to the step up to Rails, but my understanding of it was more as a predecessor to Rails rather than a potential replacement. As I did some additional research on Sinatra I realized that it was exactly what I was looking for, a highly modular application that would be easy to understand and easy to scale by adding gems when necessary.

What I hadn’t realize when I made the decision to use Sinatra, was how much I would learn about Rails, RACK apps, and server-side frameworks in general by moving back down to a lower level framework that doesn’t abstract away details through relying on conventions. Sinatra let me see all the parts worked together and layer things on slowly as needed, and made debugging problems far easier. Sometimes with Rails I felt like I was pushing and praying, but with Sinatra I came to expect it to work. It just made sense.

As the project became more complex, I realized that I desperately needed a strong ORM like Rails’ Active Record to create and persist associations, and build methods to return related data sets easily. That’s whe nI realized that ActiveRecord was nothing but a Ruby gem that shipped with Rails, and that I could easily require it in my Sinatra app and be off to the races. Awesome. As my app’s resources continued to expand, I found myself grouping related files together in folders until I looked back and saw what began to look conspicuously like a Rails App funny enough.


Now you may be saying, hold up, what are you even doing for this project anyhow. Give me some context! For the project I am building two apps, one that handles all data and makes it available via an API to a Node/Express App which serves as its. I have some pretty awesome things planned and in development so I’ll share once it’s done!

For the Node app to present something compelling, I needed a large amount of data, to the tune of tens of thousands of records, and to test the code I need at least a few hundred records. In the past I had just built my own seed data manually.. but that clearly wasn’t going to cut it here. I had heard about Ruby’s FactoryGirl, and began trying to implement it without much success. It certainly could do what I wanted, but it also relied on a lot of conventions which made troubleshooting more difficult. I also realized that I only needed 5% of what it had to offer and decided it would be easier, and more flexible, to build my own factory. Because I’m clever.. I called it “MyFactory.” Briliant, right? I thought so. This turned out to be an incredible decision and it worked exactly as I hoped. Because I built it from scratch, it made writing RSPEC tests and fixing bugs quick and easy.

Once I got the API up and running, I moved on to building my Express app, which I learned was actually inspired by Sinatra! What more is that I also will be building a basic app with Python’s Pyrimid framework which is also based off of Sinatra’s highly modular design and focus on readability.


Case in point, droping back down to Sinatra was the best decision I’ve made this year. God that sounds nerdy… but it’s true. As Illionois’ House Rep, Aaron Schock, once said, “Hater’s gunna hate.” But then again he is under investigation for dozens of corruption charged and modeled his office after the red room in Downtown Abbey. Maybe he isn’t the best man to quote..


Now a recommendation completely unrelated to coding. If you don’t watch Last Week Tonight With John Oliver, I highly recommend it. #JEFFWECAN