Small Reviews and Sinatra: My Hobby, My Assignment and The Art of Good Looking Code
This blog was originally published on May 2nd, 2020 as part of my Sinatra project. In case you’re not familiar with Sinatra, is a Domain Specific tool to build web applications with Ruby. Though I don’t know how many companies use it, it’s good for learning RESTful APIs. Just take a close look at the code to see the request types (
I also speak about how to organize well the code. What would be a good practice to make it look readable and good.
Like always, is it as technical as it is a personal inspiring story. Hope you enjoy it.
When deciding the theme for my projects, I often think if it would be something I would use. For example, my CLI project was all about looking for breweries in a city. Cause that’s what I do, look for museums at day and breweries at night. I swear, I’ve probably seen more Claude Monet paintings than the total of IPA beers I ever had.
And also this one:
This time, I decided to take things further. Instead of something I would use. Why not do something I would DO for others? That’s when I decided to use my social media movie page as the theme for the Sinatra project. Small Reviews which translates to Spanish as reseñitas (a quirk in Puerto Rico is to use the diminutive word for everything), started as a way to show my love for movies and distract myself from depression and post Hurricane Maria PTSD. I
As far as the code goes, is a simple project. You’re all LiveJournal probably looks better, but it does everything we need to have a full CRUD functional website. Being a reviews website the Controllers are Application Controller, Users Controller, Sessions Controller, and Reviews Controller. The typical Session Controller looks like this:
What I would like to share is the reviews controller. Sinatra can look ugly, we can start with a conditional statement, then another statement, so on and so on to the point that hurts to watch. Thanks to a good friend in the cohort, we figure out how to make it better. Now, it looks like this:
Trust me, is way cleaner than it looked before. If you noticed I’m calling
auth_user, it is through Private methods. Private methods are used like Helper methods to simplify your code. I recall doing Private methods in the lab but never used it again. We need to treat our codes like an art form and get creative with them. Make it look presentable and beautiful.
Take your time, be creative. Then we can celebrate like a Renoir painting.