OdeToCode IC Logo

Being A Better Programmer

Tuesday, August 6, 2013

Iris and I put together “Being a Better Programmer” with tips and strategies for everything from writing code to time management. We’ll list our favorite books and tell you a bit about how we got started in the industry, as well as talk about how we learn the business domain and where to go to find some good code to read.

Learning To Program - Being A Better Programmer

One of the techniques we talk about for being a better programmer is writing code – lots of code. Sometimes the code is a hobby project you work on for personal fun, sometimes the code is a kata or a koan, and sometimes the code is something you deliberately implement to see how something works in isolation. I have many little projects checked into source control that only exist to understand how something works.

For example, the behavior of a List<T>. If you want to figure out the default capacity of a List<T>, as well as the algorithm it uses to increase capacity, then you can use a decompiler or create a small experiment project to test a List<T> under different scenarios. While the decompiler is a useful exercise on its own, a small project with code is something that can give you hours of enjoyment as you run the program under different framework versions and try different parameters.

Here’s one I wrote recently that provides some interesting results.

static void Main(string[] args)
    var list = new List<int>();            
    var newCapacity = list.Capacity;
    var oldCapacity = newCapacity ^ Int32.MaxValue;

    while (true)
        if (oldCapacity != newCapacity)
            oldCapacity = newCapacity;              
        newCapacity = list.Capacity;

For those who watch, I hope you enjoy the course!