Notes from Jared Carroll

Integrating 3rd-Party APIs: Listen to Your Tests

By on in Process, Web

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.

Continue reading …


Keeping Domain Models Cohesive with Collaborators

By on in Process, Web

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.

Continue reading …


Test-Driving the Design of MVC Based Apps

By on in Process

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.

Continue reading …


Test-Driven C with Ceedling

By on in Everything Else

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.

Continue reading …


Enumerator: Ruby’s Versatile Iterator

By on in Everything Else

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.

Continue reading …


Structural Typing: Compile Time Duck Typing

By on in Everything Else

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.

Continue reading …


Better Cohesion with the Type Class Pattern

By on in Everything Else

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.

Continue reading …


Partial Function Application in Haskell

By on in Everything Else

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.

Continue reading …