Learning Flask after Ruby on Rails
Why It’s Important to Learn Another Backend Framework as a Rails Developer
What is a framework and why use one?
A framework is a collection of code, tools, and utilities that give you a specific structure to work with when you’re writing software. The most common frameworks are Ruby on Rails (Ruby), Django (Python), Flask (Python), Spring (Java), Laravel (PHP), React (JS), Express (JS), and Angular (JS). Some of these are full-stack and others are frontend or backend frameworks. With a framework, your program becomes more structured. Because a lot of functionality comes built-in, your resources become freed up to focus on building out what makes your application unique. Developers hate doing work that has been done before. Frameworks take care of the parts of development that you and other developers would normally have to repeat in every application.
Why Ruby on Rails?
Ruby on Rails is one of the most common frameworks today. The creators of Rails subscribe to the “convention over configuration” paradigm. From the Ruby on Rails Doctrine:
One of the early productivity mottos of Rails went: “You’re not a beautiful and unique snowflake”. It postulated that by giving up vain individuality, you can leapfrog the toils of mundane decisions, and make faster progress in areas that really matter.
Rails handles the details of implementing database scaffolding, routing, testing, and so much more. With just a few lines of code, you are 90% of your way to building a website (and you have literally hundreds of files already built for you). Their idea is that by automating the repetitive and time-consuming tasks that all developers would need to spin up an application, they are allowing developers to spend their time on work that is truly innovative. “Optimize for programmer happiness” is the first pillar of the Rails Doctrine, and I can see why.
When you learn Rails it seems like magic. By design, Rails is one of the most comprehensive and rigid frameworks available. But once you learn it, it’s incredibly powerful. Many companies use Rails today, especially to build APIs.
However, the magic of Rails—and the word magic is key here—abstracts away a lot of the logic happening under the hood. As a new developer, you can ramp up to building relatively complex web apps extremely quickly with Rails, but this might be at the expense of learning the beauty of how every part of your program works and fits together.
Why learn something else?
I have built several full-stack and backend applications/APIs using Rails. While I understood the concepts of RESTful routing, MVC, and databases, when I started building an application in Flask, a lightweight and common Python framework, I realized that I had deeper work to do around understanding these concepts outside of the Rails framework.
Flask is actually called a “microframework,” meaning the creators of Flask aims to keep the core simple and lightweight but easily extensible. I would consider Flask to be on the other side of the spectrum of Rails in terms of robustness, rigidity, and the amount of code actually built out for you. When you spin up a Rails app, you get files on files generated for you, but with Flask, it’s on you to build out the application structure, and your program can be as simple as one Python file with a few lines of code.
As I built out my first Flask app, I discovered so many parallels to concepts in Rails:
- “views” to “templates”
- resource routing to “@app.route”
- going from generating migrations with a few words in the command line to writing my own schema and init_db.py seed file
There were definitely hurdles in reconciling my understanding of these concepts with a new framework and a new language, but I’m so glad I did. Pushing through those initial blockers and fuzziness to level up… this is what programming is all about.