Magic numbers and beyond

Are all magic numbers bad? To give the classic consultants answer - it depends. Take zero for example. If the zero is being used as an index into an array then the zero is a zero because all arrays start at zero. That's internal knowledge; knowledge that is part of the solution and a reflection of something from the problem. There is no way you can conceive of a change in the problem causing a change to that zero. So it's internal. So it's ok. But all things are relative. It might still be a good idea to refactor - to a higher level expression of the iteration perhaps. But most numbers are not internal, they come from the problem. If numbers such as this are not named then they are indeed magic numbers; they are numbers that reveal nothing of their origin.

Magic isn't limited to numbers though. Far from it. A magic number is a number and a number is an expression. So a magic number is also a magic expression. And of course, all expressions lie on the same magic-code continuum; some expressions are very intention-revealing, they're not very magic at all - while other expressions are very cryptic and thus qualify as magic expressions regardless of whether they contain numbers or not.

Beyond magic expressions we have magic statements, magic functions, magic classes, you name it, if its part of the code it can be magic. I think it's time we pushed the word magic into greater service. It's time we had a better vocabulary for hard to understand things. If you see a hard-to-understand X in code how about calling it a magic X.

The name game

When I'm training/coaching a group of people I often haven't met any of them before and sometimes they haven't met each other either. So one of the first things we all have to do is get to know each others names. It can be boring and painful asking each person to briefly introduce themselves so here's an alternative...

Instead, announce that you want everyone to write their name on a flipchart (or whiteboard) and that you're going to time how long it takes. Your mobile phone probably has stopwatch feature (if not just count out loud). Then just say "go" and start the stopwatch. Some people will be puzzled and just sit there doing nothing for a while, but eventually everyone will realize you really mean it! When they've finished and sat down again tell them how long it took, comment on the illegibility of their writing, prepare a new sheet of paper on the flipchart (or wipe the whiteboard), and ask them to do it again making it clear that this time you want it done faster. And legibly! You have to be able to read the names! Say "go" again and restart the stopwatch.

You can easily and quickly repeat this up to ten times. You can allow a little retrospective time between iterations if you like. You can insist that the names are drawn in a way that bears some relation to where they're actually sitting. The variations are endless. The ingenuity shown by the groups when I've run this is often remarkable. They easily get the time down from about 2 minutes to a few seconds. I've also found it works very well if you rerun the exercise every morning (perhaps after hiding most of the pens ;-)

Quite by chance I've learned that my friend Henrik Kniberg has been using peoples names as the theme for a similar group exercise.

UML modelling with fridge-magnets

Whiteboards are a great UML case tool. They help to make modelling a social activity. They help to emphasize that the act of modelling and the understanding it produces is just as valuable as the resulting model. The wipeability of whiteboards is also a great feature. It encourages modification and experimentation.

Whiteboards are not so good when you want to rearranging a diagram though. But... it occurred to me that if the whiteboard is magnetic then fridge-magnet-style UML-shapes might help. So I found a company that sells magnetic sheet and paid a bit extra to have it coated with a dry-wipe surface. The first sample arrived today and I've made my first prototypes. I cut out two sizes of rectangles and edged them with a permanent marker. Here's one of the larger ones (the background is a tablecloth not wallpaper!)

Now simply stick them on the whiteboard - they stick to each other of course:

Here's the big rectangles vertically in 3-section class format:

And horizontally for packages (just draw on the top-left tab):

Here's a 1-section only class diagram overview made from the smaller rectangles:

And just for Pete Goodliffe here's a Booch cloud:

I'm also going to cut out some ellipses for use-cases/scenarios and some rounded rectangles (roundtangles) for activities/states.

Dan Pink's challenge to draw yourself in just 5 lines

typedef in C

I regularly coach advanced C to the great engineers at Tandberg in Oslo. One of the topics we've discussed is typedef style. For example
  • not using typedefs (Linux kernel style) like this
struct wibble;

void wibble_this(struct wibble *);
void wibble_that(struct wibble *);
  • or with typedefs, like this
struct wibble;

typedef struct wibble wibble;

void wibble_this(wibble *);
void wibble_that(wibble *);
This matters because typedefs are not idempotent in C, which is to say you can't write this
typedef struct wibble wibble;
typedef struct wibble wibble; // non-conforming duplicate
A C file has its #includes and these #includes will have their own #includes, ad infinitum. It can be tricky knowing whether a type has already been typedef'd or not, and hence whether the C file has to declare its own typedef or not (for example, when forward declaring the type). However, there is a style that neatly avoids this problem
  • in header files don't typedef
// wibble.h
struct wibble;

void wibble_this(struct wibble *);
void wibble_that(struct wibble *);
  • in source files do typedef
// use.c
#include "wibble.h"

typedef struct wibble wibble;

void eg1(wibble * w)

void eg2(void)
    wibble * w = ...
This is somewhat similar to the C++ rule that header files always use explicit :: qualification. My friend Kevlin Henney commented that the idea is also resembles using typedef's in the private section of a C++ class which is a nice observation. I haven't tried this on a large codebase. At the moment it's just an idea. Caveat emptor.

I hope you don't want floor 7

In a hotel in Beijing. I wonder what the words say? "Please press the buttons gently" perhaps?

Use-Case cartoon speech bubbles

UML Use Case/Scenario ellipses look quite similar to cartoon speech bubbles. And each ellipse is of course supposed to be "spoken" by an actor. So sometimes when I'm coaching/training/etc I cut out ellipse shaped pieces of card and do some role playing.

You can have fun too. For example, developers often phrase their use-cases from the implementation perspective rather than from the actor's perspective. So when they write "Lend a Book" as the name of their Use Case, you can get them to actually try it. Pretend your inside a library, give them a book, and ask them to role play their use case. Like this... (the headband stops their arms from aching)

At which point someone role playing a Librarian can react like this...

...which makes everyone realize they should really have written this:

Talent is Overrated

is the title of another excellent book (isbn 1857885198) by Geoff Colvin. As usual I'm going to quote from a few pages:
Deliberate practice is not what most of us do when we think we're practising.
Most organizations are terrible at applying the principles of great performance. Many companies seem arranged almost perfectly to prevent people from taking advantage of these principles for themselves.
nothing, it turned out, enabled any group to reach any given grade without putting in those hours. ... There is absolutely no evidence of a 'fast track' for high achievers.
memory ability is very clearly created rather than innate.
General Electric CEO Jeff Immelt has been clear about what the company is looking for: someone who is externally focused, is a clear thinker, has imagination, is an inclusive leader, and is a confident expert.
The roadblocks we face seem to be mostly imaginary.
Jerry Rice was the greatest because he worked harder in practice and in the off-season that anyone else; he spent very little time playing football; he designed his practice to work on his specific needs; he did much of the work on his own; it wasn't fun; he defied the conventional limits of age.
Practice is so hard that doing a lot of it requires people to arrange their lives in particular ways.
The advantage of practice was cumulative.
Deliberate practice requires that one identify certain sharply defined elements of performance that need to be improved, and then work intently on them.
Practicing without feedback is like bowling through a curtain that hangs down to knee level. You can work on technique all you like, but if you can't see the effects, two things will happen: You won't get any better, and you'll stop caring.
Feedback? At most companies this is a travesty, consisting of an annual performance review dreaded by the person delivering it and the one receiving it. Even if it's well done, it cannot be effective. Telling someone what he did well or poorly on a task he completed eleven months ago is just not helpful.
Practice is designed, so it can be designed well or badly.
Great performers never allows themselves to reach the automatic, arrested-development stage in their chosen fields. The essence of practice, which is constantly trying to do the things one cannot do comfortably, makes automatic behavior impossible.
In fact what they [great performers] have achieved is the ability to avoid doing it automatically.

It's Your Ship

is the title of an excellent book by Michael Abrashoff (isbn 0446529117). As usual I'm going to quote from a few pages:
A recent Gallup study found that when people leave their companies, 65 percent of them are actually leaving their managers.
What I suddenly realized was that I had the power to do this all along. I just never had the self-confidence.
Something happened as a result of those interviews. I came to respect my crew enormously.
Secrecy spawns isolation, not success.
No matter how fantastic your message is, if no one is receiving it, you aren't communicating.
You earn trust only by giving it.
More often than not, bureaucracies create rules and then forget why they were needed in the first place, or fail to see that the reasons for them no longer exist.
Once leadership opportunities are squandered, you can never get them back.
If a rule doesn't make sense, break it.
If a rule does make sense, break it carefully.
I felt as small as a man could. I had just had my core values calibrated by someone half my age.
One-size-fits-all programs tend to fit none.
Leadership is mostly the art of doing simple things very well.
Open yourself. Coldness congeals. Warmth heals.
The goal shouldn't be to reduce the standards for some, but to raise everyone else to the highest possible level.
Train for unity.
If you don't intend to act, then don't bother to ask if it is going on. It will only make matters worse.
I kept walking around the ship, questioning the crew, drawing them out.
Having fun with your friends creates infinitely more social glue for any organization than stock options and bonuses will ever provide.

Heathrow Blue Screen

Classroom summary techniques

A technique I use a lot when teaching/coaching is to get the participants to periodically do a summary. I have two main techniques:

The first technique (which I tend to use for smaller groups) is to ask the group to just shout out anything they can remember. Whatever they call out I write on a whiteboard and we briefly recap that topic. When the calling out slows down we stop. Then we vote; each person places three ticks on the whiteboard. I count up the ticks and we see what the top three are.

For a larger group I ask for just one thing from each person. I make it completely clear that you can choose anything you like for whatever reason you like. When someone calls something out I briefly summarize that topic but I don't write anything down.

In both cases I've found it's important not to simply ask each person, round-robin fashion, based on where they're sitting. It's much much better if you simply wait for the first person to speak, and then wait for the second person to speak, etc. That way the more confident ones naturally speak first and the less confident ones gain confidence by seeing the more confident ones go first.

Deming's knowledge of variation

Mary Poppendeick's excellent InfoQ video is online at Her summary of Deming's Knowledge of Variation at around 28 minutes is great and well worth watching.

Tandberg product development

My good friend Olve Maudal of Tandberg did a talk about Product Development in TANDBERG for the Oslo Lean Meetup. His slides are online at and are well worth a look if you care about what it takes to make world class software.

The vaccination approach to learning

Thanks to Tobias Fors for tweeting the following onto my radar.

Reading up on how learning works, I came across a couple of quotes on the subject. I particularly like the one about the vaccination approach to knowing - it exposes our fantasy that all it takes is to “send people back to school”, and then everything will be fine.

Explaining the metaphor Tobias quotes Kurt Lewin:

The learners become their own subjects and no longer objects to be filled with packages of knowledge in the manner of what Neil Postman and Charles Weingartner call the vaccination approach to knowing - “where education is something you take and, when you have taken it, you’ve had it, and if you’ve had it you are immune and need not take it again.”

2,390,000 all of a sudden

As a self-employed software coach-consultant-trainer-developer-enthusiast-etc I have to try and market myself. My marketing strategy is simple - I try to do stuff to increase my Google ranking. That's it. I monitor this by regularly typing my name into Google and seeing how many hits it generates. It's been around half a million for quite a while. I don't know why, but this morning it's suddenly jumped to over 2 million!

Skills Matter - Agile Development in C#

I'll be running Skills Matter's Agile Development in C# 3 day training course (starting March 3rd) in London. The course material is written by Kevlin Henney and is excellent. I'm really looking forward to it. Feel free to email me if you're thinking of attending.

It makes me shiver

Shiver by Natalie Imbruglia is playing. Some of the lyrics are catching my ear:

When you tell me stupid things, like you do I just have to, have to, have to, change the rules

In a rush, never trust ... if I'd only stop and take my time ... with you I'm running somewhere I can't get to

Mending a bike puncture

Ellie's bike had a puncture today. I used some tyre-levers to prise the tyre off its wheel rim. Then I carefully pulled the inner tube out and was puzzled to see a large section had folded over on top of itself! How did that happen? A hurried previous repair? I attached a pump to the valve and pumped some air into the inner tube. Then I filled a bowl of water and plunged the inner tube into the water, shifting it along section by section. Suddenly a tell-tale stream of air bubbles revealed the source of an invisible hole in the inner tube. Right in the middle of an existing patch. More evidence of a hurried previous repair. I was struck by a few thoughts

The first is that air, like software, is invisible. To get the hole to reveal itself I switched to a different medium, from air to water.

The second is the importance of root cause analysis. Find the thorn and remove it. Otherwise you'll end up patching the patch just as I did.


is the title of another excellent book by Dan Pink. As usual I'm going to quote from a few pages:
The first ten years of this century [have been] a period of truly staggering underachievement in business, technology, and social progress.
Rewards, by their very nature, narrow our focus.
By offering a reward, a principal signals to the agent that the task is undesirable.
Mediocrity is expensive.
Consider the very notion of "empowerment". It presumes that the organization has the power and benevolently ladles some of it into the waiting bowls of grateful employees.
Management isn't the solution, it's the problem.
Effort is one of the things that gives meaning to life. Effort means you care about something, that something is important to you and you are willing to work for it. [Carol Dweck].
Being a professional is doing the things you love to do, on the days you don't feel like doing them. [Julius Erving]
In the end, mastery attracts precisely because mastery eludes.
How people spend their money may be at least as important as how much they earn [for well-being].

The Puritan Gift

is the title of an excellent book by Kenneth and William Hopper. As usual I'm going to quote from a few pages:
For a century and a half, historians have been asking themselves the chicken-and-egg question: which came first: Puritanism or Capitalism?
A system is a set of connected things or parts, bound together to a purpose.
No enemy is more terrible than money, and no friend is more trustworthy.
At the heart of the system lies mutual trust.
Given's approach was avowedly descriptive rather than prescriptive.
In spite of appearances, good decision-making is essentially the same in all walks of life.
A belief that life was not merely best understood, but also best experienced, as a struggle.
You do not own a dog and bark.
Statistics are a wonderful servant and an appalling master.
The Cult of the (so-called) Expert would severely damage the great tradition of 'generalist', 'hands-on' management.
No greater damage could be done to our economy or to our society than to attempt to 'professionalize' management by 'licensing' managers, for example, or by limiting access to management to people with a special academic degree [Peter Drucker, 1954].
I absolutely loathe the idea of professional management [Jeff Immelt, 2004].

A Whole New Mind

is the title of an excellent book by Dan Pink. As usual I'm going to quote from a few pages:
At the Yale School of Medicine, students are honing their powers of observation at the Yale Center for British Art, because students who study paintings excel at noticing subtle details about a patient's condition.
The MFA is becoming the new MBA.
Stories are how we remember.
One of the best ways to understand and develop the aptitude of Symphony is to learn how to draw.
The most creative among us see relationships the rest of us never notice.
Everything you create is a representation of something else.
Poets are our original systems thinkers.
More males than females have brains that systematize and more females than males have brains that empathize.
The people who will thrive will be those who can toggle between the two. As we've seen again and again, the Conceptual Age requires androgynous minds.
If you are laughing you cannot think. That is the objective we achieve in meditation.
People have enough to live, but nothing to live for; they have the means but no meaning.

Washroom tap psychology

Have you ever been in a washroom and failed to get any water out of a tap? Of course you have. We all have. It happens to me all the damned time.

The taps I hate the most are those stupid infra-red taps. The ones that are supposed to burst into life when you waggle your hands under them. Waggle to the left, waggle to right, in-out, in-out, doing the hokey-kokey. Your occasional random reward, if you're very lucky, is a short dribble of water.

The infra-redness is a ruse - it's fake - the tap is really part of sophisticated psychology experiment. Out of sight a white-coated clipboard-clutching technician is carefully monitoring your rising frustration. A favourite ploy is withholding water once you've dobbed a large blob of soap into your hands. And then watching as you fruitlessly search for a paper towel to wipe away the soap.

Another favourite is doctoring a clearly-full soap-dispenser into a soap-refuser. And of course, setting the force of the air-blower hand-drier to either barely-enough-to-fog-a-mirror or enough-to-lift-a-twelve-stone-man-clean-off-the-ground but never anything in between.

I miss the old-style taps.