Patterns: The If-Else Error Chain

In languages like Java, we have a standardized error-handling paradigm in the try-catch expression. Effectively, this hands all error-handling off to the computer, which monitors all code in the try loop for any and every kind of possible error. While we are able to restrict the range of errors in many cases, the fact

Patterns: Boundary Check

A wise quote: When it goes without saying, someone should probably say it. This is one of the better known patterns out there, but it still bears repeating. The boundaries for integers When you're working with a range of integers (for example, human age range could be between 0 and 135), we have two obvious boundary points

Patterns: Shielding Inputs with const

One of the key worries I have heard from those ill-informed OOP programmers is that C cannot protect inputs you pass into functions. They use private fields and retrieval functions to ensure that the stored value is protected from unwanted modification. However, this concern is addressed by C's const keyword. Taking a const value There are times

Patterns – Logical Unity

It's amazing how often programmers forget the simplest rule of programming: 1=1. This is the principle of logical unity (or modularity - they're largely synonymous). Unity of Function If we adhere to the principle of top-down modular design, all our functions should be relatively small. At the bottom of the tree, every function serves one purpose and

Patterns – Prototypes and Optimization

The hardest interview I ever had: someone told me to go up to a whiteboard and solve a programming problem, in code, optimally, on the first try. It's a basic fact of our field that we iterate toward the final product. Not unlike a sculptor bringing the David out of a piece of marble, we

Patterns: Initialize Everything

malloc(): memory corruption When you look at an error message like that, what could possibly lead you to believe that, a hundred lines up, you didn't properly initialize a size variable? After all, all we know is that this malloc() operation could not complete because the memory it should be able to touch is corrupted. Yes,

Working with Poor Documentation: Options are Limited…

If it hasn't happened to you yet, it will: You're working with library code - say, GNUTLS. You've dug around and installed all the prerequesites, and the libraries are all set up. You're all ready to get to work... But the documentation doesn't match the headers you have. It turns out that all the documentation matches

Patterns for Kids: The Little Red Hen

I write about programming patterns quite a bit, but there are many other places where patterns are important. For much of human history, these patterns have been presented in myths and fables, to instruct the young and the less-inquisitive in virtues and mental patterns that best serve and exemplify their society. We in the

Patterns for Kids: Clever Elsa

Most of us have at least heard of the Grimm Fairy Tales. The Brothers Grimm travelled through Germany compiling folk tales, which they published into an excellent collection of myths (pattern-conveying stories) that convey simple lessons to us at any age. Today, we'll look at the story of Clever Elsa. --------------------- Elsa was a serving girl who

Patterns for Kids: The Ant and the Grasshopper

Industriousness is difficult to describe and harder still to sell. At first blush, it might seem like it'd be easy to sell the simplest way to ensure happiness, wealth, and general success, but long-term thinking is not natural for a great many people. This is why Aesop fables are so significant - they can