Abandoning switch In Three (And A Bit) Steps

Everyone who’s worked in a C-derived language has seen a switch statement or two in their lives. There are a few well-known reasons not to use them, but somehow they crop up now and then anyways because they’re just so convenient — initially.

Switch is a holdover from lower-level languages (mostly, various assembly languages) where the destination of a jmp instruction could be computed or looked up in a table. In modern languages, there are usually more appropriate structures for determining which piece of code to jump to: that’s what virtual dispatch does, for example.

Unfortunately, it’s not always obvious how to “fix” code that makes heavy use of switch.

Read more »

God Money, I’ll do anything for you

The loop

1
2
3
4
5
<?php
while ($read < $n && (false !== ($buf = fread($this->sock, $n - $read)))) {
    /* ... */
}
?>

contains a subtle bug. Go ahead, read the relevant function documentation and see if you can spot it.

Read more »

Singling Out to Spring

Last time, I wrote about why Singletons get a bad rap, and I wrote some high-level advice for moving away from them sanely. I want to cover a practical (if somewhat idealistic) example using Java and Spring to move a Singleton creation dependency out of a class.
Read more »

Singled Out

One of my colleagues blindsided me the other day with a question about software architecture that I should’ve been able to answer on the spot: “Are singletons really all that bad?”
Read more »

Automatic Code Formatting and Merges

…or, how to give other developers screaming nightmares in 10 seconds flat.

The next time you think to reach for the “reformat source code” button in your IDE, think twice before you press it. Automatic reformatting is a great way to turn a small merge hazard contained to a single method into a huge merge hazard affecting an entire file. Merge tools are relatively stupid: in general, they’re not aware of the syntactic structure of a source file, just the text by lines; as a result, it’s very easy to fool them into thinking a one-line change and a reformat are a conflict covering the entire file.

If you’re using automatic formatting tools, please check with the other developers on your project and make sure that your code formatter settings agree with theirs. If you can’t make that happen, then don’t reformat code unless everyone’s nobody but you is touching those files.

Please, think of the merges.

Shameless Self-Promotion: LDAP Outside the Enterprise

Last week I set up LDAP as a central authentication/identity store for the Toronto Hacklab. I thought I’d share my notes. It went well enough that I’m going to repeat the process with the Grimoire: right now each part of the site (Wordpress, WebDAV for various repositories, JIRA, and Hudson) handles its own authentication, and it’s gotten unmanageable.

Yes, there is only one user. Yes, I still think it’s worthwhile.

Annotation Processing and the Pernicious // TODO

Raise your hand if you’ve ever put a // TODO comment in your source code. Or // FIXME, // XXX, or any of the thousands of other variants programmers have been using since before there was dirt to mark places that need further work.

Now raise your hand if your compiler or build tool can tell you about them.
Read more »

Nobody Cares About Your Makefile

GNU Make is a relatively modern version of one of the oldest build tools still in regular use. Make has existed since 1977 and is still the standard tool for building native software in Unix-derived environment. The pattern Make established, based on using a directed graph to automate builds, is still in use in more recent tools.
Read more »

Merging Structural Changes

Recently, a project I’m working on set out to reinvent their build process, migrating from a mass of poorly-written Ant scripts to Maven and reorganizing their source tree in the process. The development process is based on having a branch per client, so there is a lot of ongoing development on the original layout for clients that haven’t been migrated yet. We discovered that our version control tool, Subversion, is unable to merge the changes between client branches on the old structure and the trunk on the new structure automatically.

Curiousity piqued, I cooked up a script that reproduces the problem and performs the merge from various directions to examine the results. Subversion, sadly, performed dismally: none of the merge scenarios tested retained content changes when merging structural changes to the same files.
Read more »

Nobody Cares About Your Build

Every software system, from simple Python packages to huge enterprise-grade systems spanning massive clusters, has a build—a set of steps that must be followed to go from a source tree or a checked-out project to a ready-to-use build product. A build system’s job is to automate these steps.

Build systems are critical to software development.

They’re also one of the most common avoidable engineering failures.
Read more »

Image | WordPress Themes