Archive for the ‘Programming’ Category

Improving code with peer reviews

Tuesday, September 1st, 2009

Peer reviewing is the practice of looking at code written by others to find errors or ways to improve the code. Sometimes also called desktop reviewing, this approach can be useful for various reasons: If you have a coworker who is more experienced than you, you can learn from him/her It's often ...

What makes an abstraction good, and why should I care?

Friday, August 28th, 2009

You probably know what abstraction means - making a complex process simpler - but do you know what makes an abstraction good, and why it's important? If you are writing code for a project that lives a bit longer, or has multiple developers working on it, having a good abstraction matters. ...

Reader challenge: Keep track of code errors

Monday, August 24th, 2009

The book Code Complete suggests to keep track of common mistakes. This is so that you can see what mistakes you make most often, and so that you can have a checklist of things that you should check when debugging. I want to challenge you, dear reader, to keep track of ...

Using canvas to do bitmap sprite animation in JavaScript

Friday, August 21st, 2009

Have you ever thought about writing a game? If you have, you've probably wondered how to render animations for your game characters. In this post, I'll show you how you can use JavaScript to do time-based sprite animations, drawing them on canvas - vital if you want to do a ...

Unit-testing essentials

Monday, August 17th, 2009

Here's some essential unit-testing posts I've written recently. While some of them have examples in PHP, they should still be useful in other languages as well. Unit testing PHP series Unit testing introduction Writing and running tests Writing tests for exsisting code Mock Objects and testing code which uses the database Test-driven development General testing topics Unit-testing JavaScript How ...

How to make your code testable

Friday, August 14th, 2009

Image by Jim Frazier I've recently been working on a code-base which wasn't designed with test-driven development methodologies, or with unit testing in mind. As I implemented unit-tests to this code, there were some modifications I had to do on the code. Some modifications popped up more than others. There were a ...

Unit testing JavaScript

Tuesday, August 4th, 2009

I've recently been looking into some JavaScript unit testing frameworks. There are many alternatives, and while many of them seem good, very few of them actually matched my requirements: Must be able to run tests from the commend-line Tests should be relatively easy to write

Weekend coding: Add a character counter as the background of a textarea with JavaScript

Saturday, August 1st, 2009

Have you ever filled a textarea on a page, which had a limit to how many characters you could type into it? Or maybe you are a Twitter user, and as you know, Twitter only displays 140 characters of your tweets. (Not an actual textarea) The other day I was thinking ...

Unit testing 5: test-driven development

Saturday, July 4th, 2009

In this post I'll introduce the methodology known as test-driven development, and how to use it in your projects. The difference between "normal" and test-driven development (TDD) is that when doing TDD, you write unit tests for your new code before writing the code itself. This way you ensure good test ...

Unit testing 4: Mock objects and testing code which uses the database

Friday, June 26th, 2009

After learning to write tests and some good testing practices, it's now time to look at mock objects. When testing a class which needs an instance of another class to work, you do not want to depend on the other class too much. This is where mock objects come in - ...