2018 Archives

Dependency Injection Containers vs Hard-coded Constants

— Tags: Ruby Pigeon, Ruby

Dependency injection (DI) is a somewhat contentious topic in the Ruby community. Some argue that DI containers are unnecessary complexity cargo-culted from Java. Some argue that DI is the path to cleaner, simpler, more-testable code.

In this article, I want to compare and contrast two approaches: hard-coded constants versus using a DI container. The difference might not be as big as you think!

Let’s start with a quick explanation of DI, and DI containers.

Testing Example Code In Your Jekyll Posts

— Tags: Ruby Pigeon, Ruby, Testing

Blocks of code in blog posts and articles often contain errors. I see it frequently, in other people’s writing and my own. Code examples are usually not tested, or even run through a compiler/interpreter, so errors are not surprising.

I’d like my code examples to be as good as the real code that I write. Ideally, all code examples would have tests, which are run before the site is deployed, as part of a CI build process.

And so, I created a Jekyll plugin to enable that workflow.