I;m working on a project using jcs/lobsters, a nice Hacker News clone. This is the first time I’ve ever forked a project and dug into somebody else’s codebase. I was a little apprehensive about having to read and understand a bunch of code and was tempted to build something from scratch to avoid it. I’m glad I didn’t because it’s proving to be an excellent chance to learn some new stuff.
For example, today while I was going through my app’s views, hunting down strings to add to my i18n YAML file, I can across this:
First off, I didn’t recognize the ternary operator and had to refresh my memory.
This, plus all of those strings stuffed into that hash had me confused for a moment. After looking further down the page, I found this bit of code iterates through the above links hash and creates an
<a href></a> for each key and value.
There’s also some other links that get merged into the hash in between but that’s enough to get the point. This is equivalent to what I usually do with a bunch of if else statements which check for the existence of a user id in the session or the current url.
This method used in the jcs/lobsters project is slick, and I can see how it saves lines when you need to check a bunch of conditions, but I’m not sure if it’s actually better. The ternary operator is less readable for me, especially when jammed into the middle of that hash, and at least a few people on Reddit seem to agree.
Regardless, I’m glad I decided to fork another project instead of building it myself. I can already tell I’m going to learn a lot from doing it this way. Not to mention I’ll be finished with what I was trying to make a lot quicker.