Understanding Rails
29 Nov 2016
One of the main ideas of Rails is to favour convention over configuration. This makes it very easy to get started building things with the framework. For example, there is a video on Youtube where the creator of Rails creates a basic blog in 15 minutes. A lot of what is actually is happening gets hidden, and when applications get large enough, things can start getting a little confusing.
While working with Rails, I have found that this idea has made things a little more confusing at times.
For examples, with routing in Rails, based on
some of the code in config/routes.rb
, some helper functions get generated to return the path
names of what some of the routes correspond to. For someone creating an application from scratch, these
helpers will only get used if someone knows about them, so there won't be any surprises. Diving head first
into a Rails application and seeing one of these autogenerated functions, and not being able to find the
definition is very confusing.
To an extent, this is probably the case with many frameworks. When you are given a codebase in a language or framework in which you aren't super familiar, everything can look foreign. If you have to build an application from scratch in the same framework, you will have a better understanding of the code you are writing. (Since you actually have to write the code instead of just reading it.)
Of course, perhaps I should just get to know the framework better before diving into a codebase with it. :) Had I read enough of the documentation beforehand, I probably would have recognized the helper function name and known its purpose. A problem that not having a good grasp of how things actually work is things can break without you understanding why. For me, I find it can lead to me knowing where to go to fix a certain piece of code, but not necessarily understanding how we get there. This problem is exacerbated by Rails, where so much is already done for you. There is a higher chance of not knowing how something works, since it might just be handled by Rails so you never figured out how it worked in the first place.
Convention over configuration isn't necessarily a bad thing. It's great for getting started quickly with a project. Once you know the convention, you can work very fast. For people trying to work in a code base without knowing the conventions, they end up having a bad time.