Mini-Reddit
Bloccit is a Reddit-style app that organizes posts into topics, which each post able to receive comments and up/down votes. It also has a User system that facilitates authorization, authentication, and an email alert system for favorited posts. It marked my first foray into the world of Rails, MVC, and relational database development.
Tools
Rails, Rspec, jQuery, AJAX, SendGrid Bootstrap, Atom, Ubuntu
Background
As the first project in Bloc’s Backend curriculum, the backbone of the project was largely laid out for me. Thus my task was less to build something from the ground up, but to understand how each piece fit together and acclimate myself to the coding paradigms of web development. As it turns out, there were a number of areas that were quite strange to me, coming from a more traditional CS background of C++ and Actionscript 3.0.
The Specs
My task was to create a Reddit clone using Rails to both render out the views and handle the database for my app. Users could log in to create Topics, with posts underneath each topic. Each post could itself have comments, be voted up or down, and be favorited. Users would recieve an email notification of comments posted to favorited topics. Posts and/or topics could be made private or public, to prevent non-logged-in users from seeing them. Finally, I created an API interface to allow for direct, server-side manipulation of the database.
The project itself was made up of many parts, but for the most part was not particularly difficult or unconventional. As such, instead of diving into every little piece, I will instead highlight the key areas that challenged me and expanded by knowledge of Rails and Web Development.
The Challenges
While implementation of individual features was fairly straightforward, there were a few concepts that I had to contend with that at first proved challenging to wrap my head around.
Ruby on Rails
Compared with something like C++, Ruby proved to have a much more lax syntax with a great deal of implied arguments and a lack of brackets or parentheses to delineate functions, objects, or attributes. This was initially a bit confusing when encountering new code, as I couldn’t always tell what was being passed. Combined with the “automagic” aspects of Rails, which do a lot of the heavy lifting for you, I felt a bit overwhelmed at times and less confident in my understanding.
This was particularly the case when working with Rails scopes, where it was initially unclear what was being passed into a rails scope.
This feeling passed soon enough, however, as I got used to not only the unique aspects of Ruby and Rails, but a new way of learning the language. It was less like math, where each concept built on each other, and more like learning a foreign language by being dropped into a new country and forced to interact with the locals. At first it is more intimidating that a slower, more methodical curriculum, but in the end it helps build both your research and language comprehension skills in parallel, which is an especially valuable skill for web dev.
Test-Driven Development (TDD)
Before trying my hand at web development, I was used to working in IDEs that handled a lot of the bug testing for you. For Rails, I had to manually write my own tests in RSpec, and more oddly, to write them before composing my actual code.
On one hand these seemed a bit odd, but as I engaged with it more it came to make more sense in the context of Rails development. Since it is conventional to keep comments to a minimum, it falls to RSpec tests to act as a form of documentation to parse out the functionality expected of various controller (and occasionally model) methods. It allows for more customized, granular control over testing and is especially useful conceptually when developing complex behavior.
That said, I still find myself falling into my old habit of writing code first and writing tests afterward. According to my mentor, this is not an uncommon tendency, as the compliance with TDD varies from one developer or organization to another. I can certainly see contexts where it is appropriate, but having only an introductory understanding of Rails at the time of this project, I found it a bit difficult to get a feel for it until I really had a handle on how the various MVC components came together.
ActiveRecord Associations
ActiveRecord Associations were an odd concept to deal with for me. On the surface, they seem fairly self-explanitory, with such relationships as topic has_many: :posts
. It was in the more complex relationships, such as has_many: through
that were more perplexing.
When setting up the functionality to assign labels to topics and posts, I was instructed to create a model for labels and labelings. The former simply stores the string used for the label, while the latter acts as a join table between labels and posts or topics. Where it got more complicated was the recommended code not only defined labelings as polymorphic, but also aliased them as labelable
through code like this:
The polymorphic part wasn’t difficult, as I had encountered the concept when I first encountered OOP in an introductory C++ course I took years ago. Even so, it took me a while to grasp that labelable
in this context is essentially a proxy for the object type passed into the label when it is created (in this case, either a Post or Topic object).
The Outcome
Whle I struggled with some of the association concepts, I feel like a lot of it really came down to get a feel for a new way of learning. Rather than needing to understand how every part of every piece worked, I essentially needed to learn what to delegate to Rails and to “trust” that it worked as described to me, even if I didn’t have a clear model of all its working parts in my head.
As a result, I over time came to develop a “feel” for Rails more naturally than what I was used to through a more traditional lecture format. It was a refreshing new way of learning for me, and one that I came to find quite useful in Wed Development more broadly. Since much of the documentation and guides for Web Dev frameworks, gems, and libraries are decentralized and open source, the process of learning is much less formalized than a traditional classroom setting.
Thus the resources at my disposal were less like rails to be followed in a linear fashion, but like a compass to guide the way. They provided my direction, but it still fell to me to walk the meandering path up the mountain.