Notes from Jared Carroll

When integrating 3rd-party APIs, it’s important to listen to your tests. The most common design relies on tests that directly mock the 3rd-party API. These tests are brittle, but are often acceptable because, well, they work. A better approach is to take the time to design an app-specific interface to wrap the 3rd-party API. The resulting tests will be more resilient to change and more maintainable. Introducing an explicit interface for an implicit concept will also enrich your domain model. In this post, we’ll take a look at each of these approaches.

As an application matures, classes begin to take on more and more responsibilities. Eventually a class’s main responsibility starts to become obscured. You can prevent overwhelming your classes by introducing collaborators to help them fulfill their responsibilities. In this post, we’ll look at an example of using a collaborator to prevent non-domain responsibilities from creeping into a domain model.

Using tests to drive out the design of objects is an effective way to write code. By taking the perspective of a client, your objects will develop simple, and intuitive interfaces. In addition, the tests act as both documentation and an automated, regression test suite. In this post, we’ll outline a basic test-driven workflow for MVC based applications. Our testing won’t be too exhaustive, but the workflow can be extended with additional, finer-grained tests, as you become more comfortable with test-driving code.

The Active Record pattern combines data access and domain logic. Over time, an Active Record class can accumulate a large amount of query methods. Moving these methods into a separate object can result in smaller, more cohesive domain objects.

Recently, an Arduino project forced me to brush up on my C. Like many programmers of my generation, C was my first programming language; but it has been a while since I wrote anything in it. After a quick K&R refresher, I immediately began looking for a unit testing framework. I found several, but I had trouble setting them up. Finally, I came across Ceedling.

Ceedling is a Ruby gem that takes care of all the setup, building, and running of C unit tests. It comes with a simple testing framework, a mocking library, and uses Ruby’s Rake to build and run your C tests. Let’s take a look at how to install and use Ceedling.

The classic iterator pattern describes a way of accessing the elements of an aggregate object without exposing its implementation. This pattern comes in two flavors: external and internal. An external iterator is controlled by the client, while an internal iterator is controlled by the aggregate object.

In Ruby, internal iteration is the norm. Ruby’s Enumerable module adds several traversal, searching, and sorting algorithms to the main collection classes, Array and Hash. While working with Enumerable you may have come across Enumerator, Enumerable‘s close relative.

Enumerator is an Enumerable plus external iteration. In this post, we’ll take a look at the basics of Enumerators and some of the powerful functionality that they make possible.

Google’s Go programming language, a statically typed compiled language, has been called a modern, better C. It builds on C by adding features such as garbage collection, concurrency constructs, and user-defined class-like types. One missing feature is classical object-oriented inheritance. Instead, Go uses interfaces and structural typing. Structural typing is like compile time duck typing. It makes Go feel like a dynamic language, such
as Ruby or Python.

Structural typing isn’t a new concept. But by making it an integral part of the language, Go has popularized it. Let’s take a look at it in Go and a few other languages.

Encapsulation is often called the core of object-oriented programming. Data is bundled with the functions that operate on that data. However, too much behavior can lead to monolithic, incohesive classes.

The type class pattern preserves a class’s core behavior but defines orthogonal behaviors externally. Type classes allow you to “extend” both user-defined and native classes with new functionality long after they were originally designed, and without modifying their source code. This results in a design based on powerful, generic algorithms written in terms of type classes.

Although type classes originated in functional programming languages, they have made their way into several mainstream object-based languages. In this post, we’ll take a look at these latest implementations.

Partial function application refers to calling a multiple parameter function with less than its total number of parameters. This results in a new function taking the remaining number of parameters. Simple functions created from partial function application are very useful and often require much less syntax than an anonymous function equivalent. In Haskell, partial function application is the norm.

The rise in popularity of JavaScript, especially on the server-side, has introduced more and more developers to asynchronous programming. Asynchronous, event-driven programming also requires a change in testing. In this post, we’ll look at how three popular JavaScript testing frameworks support testing asynchronous code.

Carbon Five is a full service software consultancy that helps startups and established organizations design, build, and ship awesome products. If you have a project you’d like us to take a look at, or are interested in joining our team, please let us know.