First Make a Bicycle
Right now, in my software engineering course, we’re creating our second project. This project deals with Sinatra and Active Record to create a dynamic website. Sinatra is a lightweight web framework which makes it easy to create websites. Essentially, it takes the headache out of website development. Active Record is the fantastic friend that takes objects that we create in our application and persists them as data to tables in a database, and also helps us to pull data from tables and create objects and behaviors with that data.
Being that both Sinatra and Active Record are both so helpful and accommodating, I had ambitious (for my beginner skills) plans for my project. Four models, each with their own controller, a way to share data between users so that you could see what other people were doing. But what occurred was that I tried to do a lot of big things before I tried to do one small thing. I realized in my confusion and exhaustion a week into my project, that what I should have done was start at the most basic form of my idea, then build up from there.
With an MVC (model-view-controller) setup, there are so many building blocks to keep up with. You have to create all of the necessary routes in your controllers, then make sure they’re either rendering the correct view or redirecting to the correct route, and you have to make sure the the models are persisting the information to the database. It is a difficult thing to wrap your head around at first, especially if you’re trying to piece together many controllers, views, and models at first. If I could go back in time to tell myself something at the beginning of this project, it would be to take my big idea and keep it, but break it down into smaller pieces, and start with just one piece. About a week in I heard someone say, start by building a bicycle, then a motorcycle, then a car. It is a simple and profound thing to say, but it changed my whole way of viewing this project. I started feeling daunted and I wasted probably a lot more time than I needed to, but once I thought of it in those terms- bicycle, motorcycle, car- I went and changed my project to be the simplest version that I imagined, and I was able to build more onto that.
Beyond that realization, I would say one of the more interesting fields in this project was the creation of RESTful routes and their corresponding CRUD (create, read, update, delete) actions. This is truly the heart of a website because every request and response goes through here. The intermediary of the website, the controllers, take in information from the views and pass it on to the models so that it may be added to tables in the database. Then, when a user makes a request, the controller again communicates this and has to get the correct information and put it back into the view for the user. I was a waiter for many years, so I may feel a certain affinity for the controller’s role in the application. They are the go-between, the part with the most responsibility in the whole scheme of things, and also the part that I most enjoyed creating.
My first experience with creating a website was fun, frustrating, and at times, totally confusing, but working with the MVC structure made things much more organized. For this project I ended up keeping things pretty simple, but I’m very interested to learn how to accomplish nested routes and use many models and controllers in the future!