Category Archives: Viget

Say you’re a front-end developer who is building a great new website. As you plan out your platform and resources, you probably have some questions about how people are using the existing website so you can prioritize important features and make sure your new site works well for everyone. Data like common devices and screen sizes are very useful for this and can be collected by most analytics platforms, including Google Analytics. Data from Google Analytics is useful after launch, as well: with the proper setup, you can track data like page load times, JavaScript errors, and common input methods.

Ruby 2.0 added the ability to create custom enumerators and they are badass. I tend to group lazy evaluation with things like pattern matching and currying – super cool but not directly applicable to our day-to-day work. I recently had the chance to use a custom enumerator to clean up some hairy business logic, though, and I thought I’d share.

Some background: our client had originally requested the ability to select two related places to display at the bottom of a given place detail page, one of the primary pages in our app. Over time, they found that content editors were not always diligent about selecting these related places, often choosing only one or none. They requested that two related places always display, using the following logic:

But if a place does have two associated places, we don’t want to perform the expensive call to nearby_places, and similarly, if it has nearby places, we’d like to avoid calling recently_updated_places. We also don’t want to litter the method with conditional logic. This is a perfect opportunity to build a custom enumerator:

When you think about technology, what matters to you? Not to your company, or to the industry, and certainly not to the media. But to you, as an individual who works and builds on the web—what do you value?

In its current state, the web is overflowing with ideas. Everyone has a voice and the collective conversation is loud, noisy, and often conflicting. Filtering it, identifying the ideas worth believing, is the ultimate challenge. For me, doing so requires naming what I value and what I don't.