Upside down UML inheritance

Here's how inheritance is typically drawn in UML.



When the top two classes are in one package and the bottom class is in another package the effect is to create a package dependency pointing upwards (think of the inheritance triangle as a fat arrowhead). It's odd that this style for drawing inheritance is so dominant as it is in stark contrast to how package/layer dependencies are typically drawn - pointing downwards. The solution is simple - rotate the diagram!



However, associations are conventionally drawn left to right. Again the solution is simple - this time the diagram needs a reflection!



The Aremac Project

Is the title of a great science-fiction book by Jerry Weinberg (yes, the same one who wrote The Psychology of Computer Programming and The Secrets of Consulting - among many others). I really enjoyed reading this - the story moves along at a brisk pace and is full of invention. Sometimes the ideas seem so plausible you wonder if they are actually true. And some of them are! For example, Jerry assures me that dogs can and are trained to help owners cope with fits in exactly the way he describes towards the end of the book. Amazing. There's a clever twist in the title too which you might spot. Definitely recommended.

Drawing, Learning, Art

I spotted the following three terms from the glossary of Drawing on the Right Side of the Brain. They could be straight out of a software glossary!

Learning: Any relatively permanent change in behaviour as a result of experience or practice.

Composition: An ordered relationship among the parts or elements of a work of art. In drawing, the arrangement of forms and spaces within the format.

Abstract Art: A translation into drawing, painting, sculpture, or design of a real-life object or experience. Usually implies the isolation, emphasis, or exaggeration of some aspect of the artist's perception of reality.


Almost Instant Learning - Not

Fast track management. And an MBA in only 80 minutes! Just two of the many books spotted in the "instant learning" section of an airport bookshop. No thanks.



Beauty in the detail



Lichen covered bricks in an old weathered wall on the way to school.

Accu charity book giveaway

My wife and our three kids live in a fairly small end-terraced house. My work-related books are taking up too much space so I'm going to give a load of them away at this years ACCU conference. My plan is to choose a charity and ask everyone who takes a book to make a voluntary donation. I've already collected one boxfull. If you're coming to the conference maybe you'd like to consider contributing some books too?

The Five Dysfunctions of a Team

is the title of a great book by Patrick Lencioni. The subtitle is "a leadership fable" and pages 1-185 form a story of how a new CEO starts to turns around a dysfunctional group of individual high achievers who are not pulling together as a team. Each "chapter" is rarely more than four pages long and the story moves along at a brisk and enjoyable pace.

The last forty odd pages explain the five dysfunctions model:
  1. Absence of trust (invulnerability)
  2. Fear of conflict (artificial harmony)
  3. Lack of commitment (ambiguity)
  4. Avoidance of accountability (low standards)
  5. Inattention to results (status and ego)
Just one quote this time:

Politics is when people choose their words and actions based on how they want others to react rather than based on what they really think.

More name games

Here's another way for a new group of people to find out each others names and start to become a team:
  1. Ask each person to write a very brief bio on a piece of card.
  2. Collect in all the cards.
  3. Choose pairs by randomly picking two cards (if there is an odd number have one group of three).
  4. Pairs have to introduce each other by reading from the cards. Do this immediately so that if the writing is illegible they have to talk to each other to decipher the words.
  5. Ask everyone to stick the cards onto a board, and arrange them in a pattern to reflect where they are sitting.
  6. Ask everyone to spend a few minutes huddled around the board reading the cards.
  7. Repeat whenever you need to shuffle the pairs.


Family writeboards

I'm self employed and work from home a lot. I have a small whiteboard stuck to the wall near my desk which my son Patrick enjoys writing on. So I bought another mini whiteboard for him. I hadn't planned it - but gradually the whole family has starting writing little messages on his whiteboard. As my children grow up (I also have two teenage daughters) they're leading increasingly independent lives and we seem to all be in the house at the same time less and less. The whiteboard provides a simple and direct way to chat asynchronously. And I think that helps them express themselves more freely. I also bought a divers slate so I could jot ideas down as they come to me in the shower. They've adopted that too!

Norwegian Developers Conference submission

I made a joint submission with Olve Maudal to the Oslo NDC conference over the weekend. Here it is:

Title

cyber-dojo : a code dojo for seriously improving your development ability

Short Abstract

The usual format for a code dojo is fairly well known: participants split into small groups, each group codes on their own laptop, all groups work on the same coding exercise with keyboard drivers rotating within the each group periodically. Towards the end of the dojo the coding stops and everyone presents their work in turn. This form of practice is often called a kata.

A cyber-dojo is different in one important respect: each group still has their own laptop but they all perform the kata completely inside a web browser. A dedicated cyber-dojo server hosts the kata, saving the source files (and the outcome of running the tests) every time the run-tests button is pressed in the browser. Running a code-dojo in this manner creates many new exciting benefits:

  1. starting the kata is virtually instant - participants do not need anything installed at all.
  2. all the step-by-step incremental run-tests submissions can be inspected helping to place a much greater emphasis on the decisions taken during the kata rather than simply the code at the end of the kata.
  3. the cyber-dojo server allows everyone to peek at the current submissions of all groups!
  4. since all development environments are now identical it is even possible to introduce timeboxed iterations to the kata and rotate codebases at each iteration!
  5. it speeds up the end of kata retrospective (since you don't have to physically involve each individual laptop).

The aim of a cyber-dojo is to introduce deliberate practice to software development. The talk will explain the nature of deliberate practice, demonstrate a live kata using the cyber-dojo server, and give away copies of the server software to anyone who would like to run their own cyber-dojo.

Outline

  1. explain what deliberate practice is and how it differs from plain practice
  2. remind everyone how a standard code dojo is run
  3. introduce cyber-dojo and explain how it is different
  4. reveal the new exciting code dojo possibilities cyber-dojo creates
  5. performing a small live cyber-dojo kata
  6. short questions and answers session
  7. give away the cyber-dojo server software to anyone interested

Level

All

Expected audience

Anyone who is serious about wanting to improve their coding ability!

Names

  1. Jon Jagger, jon@jaggersoft.com
  2. Olve Maudal, olve.maudal@tandberg.com

Biographies

  1. Jon Jagger is an independent software coach-consultant-trainer-enthusiast based in England. He specializes in agile software development (people, process and principles), test driven development, deliberate practice, design, analysis, OO, UML and curly bracket languages. He served as the convenor and principal UK expert on the ECMA C# committee and has co-authored two books on C#. He is a frequent visitor to Oslo and has presented at the Oslo C++ User Group and JavaBin. He is a regular speaker at the Accu conferences. You can follow him at http://jonjagger.blogspot.com/ and http://twitter.com/JonJagger He is 43, married with three children. He loves freshwater river fishing.
  2. Olve Maudal loves to write code, but is perhaps more interested in how software is developed than what it actually does. Since 2004, Olve has been working for TANDBERG, the leading provider of telepresence and video conferencing products and solutions. Previous experience includes developing systems for finding oil (Schlumberger 1996-2000), and developing systems for electronically moving money (BBS 2000-2004). Olve is an active member of the vibrant geek community in Oslo where he is involved in JavaPils, Cantara, XP Meetup, Oslo C++ Users Group, Lean Meetup and a few other things. You can follow him at http://olvemaudal.wordpress.com and http://twitter.com/olvemaudal

Notes to the program committee

  1. If there is demand I will happily run cyber-dojo's outside scheduled talk time.
  2. http://vimeo.com/104548135 is a video demoing cyber-dojo which should give you a feel for it.
  3. http://github.com/JonJagger/cyberdojo hosts the open-source cyber-dojo git repository


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.

Snow on rock pattern



At the bus-stop on Frederick's Gate, Oslo, while waiting for the 151.

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 http://www.infoq.com/presentations/poppendieck-agile-leadership 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 http://bit.ly/cxNvjc 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.

Drive

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.

BOYD The fighter pilot who changed the art of war

is the title of an excellent book by Robert Coram. As usual I'm going to quote from a few pages:
He was determined to excel athough he did not yet know in what area. He only knew that he had to do something better than anyone had ever done it before.
Boyd is the only known Hun driver to work in the dangerous low-speed end of the airplane's envelope. And that was how he solved the adverse yaw problem.
They might have lost three or four pounds during the strenuous high-G maneuvers. They were thirsty and longed for a cold beer. But first they had to catch a ride on the truck that served as the flight-line taxi. They headed back to ops for the debrief, the most important part of the mission.
...more usable energy always goes into a system than comes out, because there is unavailable energy called entropy.
Tactically, the ability to quickly slow down is as important as the ability to quickly speed up.
Boyd despised optimization.
The Air Force launched a Zero Defects Campaign, and the base commander at Eglin wanted every person on base to sign a pledge saying he would make no mistakes during the coming year. Most organizations at Eglin already flew a flag saying the office was 100% FOR ZERO DEFECTS. But Boyd knew, as did almost everyone who signed the pledge, that he and everyone else would make mistakes. He thought Zero Defects was a stupid idea and refused to sign. A group of lieutenants working for Christie not only followed his lead but raised a flag that proudly proclaimed there were 100% AGAINST ZERO-DEFECTS.
Study after study shows that the higher the rank a military officer ascends, the less likely he is to make change.
You gotta challenge all assumptions. If you don't, what is doctrine on day one becomes dogma forever after.
Anything new and different is feared by a bureaucracy.
He did not become fixated on technology or "one-point" numerical solutions.
Boyd worked daily to remove things.
A twenty-pound maintenance ladder does not simply add twenty pounds to the aircraft.
Again and again they practiced.
In life there is often a roll call. That's when you will have to make a decision. To be [someone] or to do [something]? Which way will you go?
The lightweight fighter had such an extraordinary thrust-to-weight ratio and could recover energy so quickly that energy dumping became a tactic of choice rather than of desperation.
Boyd liked ambiguity.
One cannot determine the character or nature of a system within itself.
He must operate inside his adversary's time-scale.
People, ideas, hardware - in that order.
"You synchronize watches," Boyd shouted, "not people."

Another Great Week At Tandberg...

...is coming to an end. Tuesday and Wednesday I taught an Advanced C course. Thursday Olve Maudal and I did some work preparing for our Code Archeology talk at this years accu conference. I think it's going to be really great. I also had two really great pair programming sessions. I was flipping through Mary Poppendeick's Lean Software Development book and I noticed there was a page about Tandberg. She's been to Tandberg and rates it as the gold standard. I couldn't agree more. I've been fortunate enough to be asked back many times and each time I am awed by how good it is on so many levels. And then on the very next page of her book John Boyd is mentioned, which is a coincidence as I'm reading Robert Coram's book on John Boyd at the moment. I'm looking forward to the next time already.

Another C++ Unit Testing Idea

In a previous blog entry about unit-testing in C++ I wrote that instead of writing something like this...
expected = 42;
actual = expression();
assert_equals(expected, actual);
you could write something like this...
ARE_EQUAL(int)
{
    ...
    expected = 42;
    actual = 40+1
}
Admittedly this was not much of an improvement, if at all. However, on a flight to Oslo a few days ago I suddenly realized a way to improve it. The idea is to fold an expected == actual assertion down to this:
expected(42) == actual(40+1);
Where expected and actual can be two function templates that return objects wrapping their arguments. These objects can have an overloaded == operator that does the assertion for me. Instead of emphasizing the assertion I emphasize the roles instead. Here's some proof of concept code:
#include <cassert>
#include <iostream>

template<typename T>
struct asserted_role
{
   asserted_role(const char * name, const T * ptr)
       : name(name)
       , ptr(ptr)
   {
   }
   const char * name;
   const T * ptr;
};

template<typename T>
void failed_assertion(const asserted_role<T> & lhs,
               const char * op,
               const asserted_role<T> & rhs)
{ 
   std::cout << "FAILED ASSERTION" ...   
       << " " << lhs.name << "(" << *lhs.ptr << ") " 
       << op 
       << " " << rhs.name << "(" << *rhs.ptr << ")" 
       << endl;      
}

template<typename T>
void operator==(const asserted_role<T> & lhs,
         const asserted_role<T> & rhs)
{
   if (*lhs.ptr == *rhs.ptr)
       ;
   else
      failed_assertion(lhs, "==", rhs);
}

template<typename T>
asserted_role<T> expected(const T & t)
{
   return asserted_role<T>("expected", &t);
}

template<typename T>
asserted_role<T> actual(const T & t)
{
   return asserted_role<T>("actual", &t);
}

int main()
{
   expected(42) == actual(40+1);
}
There are a couple of things I like about this idea. The first is I no longer have to remember to get the expected and actual in the right order; if I want to I can write:
   actual(40+1) == expected(42);
The second is that the idea can be extended. For example, I can create similar function templates called lesser and greater and add a < operator:
   lesser(42) < greater(40+1);
I can create a new template function of any name I like to express the role I'm thinking of. For example, suppose I want to test that the value of one expression is equal to the value of another expression, but neither value is "expected" or "actual" they are just two values and I don't care what the values actually are, other than the two values are equal. I can create two function templates called lhs and rhs:
   lhs(2 + 2) == rhs(4);

Paloma Faith Based Development

The morning I drove into a snow-meltwater flash-food and wrote off my car - Paloma Faith was singing on the radio. The lyrics caught my ear:

Do you want the truth or something beautiful?
Just close your eyes and make believe
Do you want the truth or something beautiful?
I am happy to deceive you


The words resonate with the way some software companies are run. They close their eyes and make believe. They practice (Paloma) Faith Based Development, rather than Evidence Based Development.

British Airways - today you were RUBBISH

I use www.ba.com to book Heathrow-Oslo flights a lot. I just booked another one and accidentally specified a return day of March 20th instead of February 20th. I'm pretty careful about this kind of thing but this time I got caught out, partly because both days are a Saturday. I spotted it immediately and changed it straight away. For a flight costing £265.50 ba charged me an extra £200 which frankly I find outrageous. Their website says to ring 0844 493 0787 for help. I tried that - it's a waste of time. Endless recorded messages saying they're sorry lots of passengers have been separated from the luggage because of the snow. But no human being.

I'm reminded of something Jeff Bezos said recently - that there were two kinds of companies; those that work to charge you more, and those that work to charge you less. All my previous Heathrow-Oslo flights have been for one week. Suddenly their system was being asked for a much longer stay. It surely wouldn't take a lot of effort to get the system to spot that sudden difference and before accepting the booking simply say "we've noticed your booking is for a longer period than usual - are you sure it's correct". If their system had done that I would have been very impressed. I would have told my friends. But it didn't. Instead it charged me an extra £200.

cyber-dojo

My vimeo submission to Jason Gorman's Software Craftsmanship 2010 conference has sparked a little interest so I've created a cyber-dojo github project and uploaded a an initial git repository of the rails software that drives it.

Software Craftsmanship 2010

The following is my first attempt at a submission to Jason Gorman's Software Craftsmanship 2010 conference. My submission is to run a code dojo at the conference in the alternative manner demonstrated. It's a bit rough in places, in particular the sound seems to lag the picture slightly, and I didn't set up the Ruby game instructions properly but its a start, and Jason says we're allowed to polish it during February and March anyway (which I plan to do).



Adrenaline Junkies and Template Zombies

is the title of an excellent book by Tom DeMarco, Peter Hruschka, Tim Lister, Steve McMenamin, James Robertson and Suzanne Robertson. As usual I'm going to quote from a few pages:
On most development projects, time is a scarcer resource than money.
Film critics believe they can be successful even if the project they are on is a failure.
Perfection is not expected; delivery is.
Whenever people get together and break rank and responsibility, the organization gets a little healthier.
Organizational lines exists for control and decision-making. They don't usually exist to accelerate work throughput.
Reality is king.
An abundance of information creates a paucity of attention.
Suppressing bad news can turn solvable problems into unsolvable problems.
The result of this misdirected civility is deep mediocrity.
Whenever you hear "I don't know," you hear a declaration of trust.

2009 AYE conference report

The 2009 AYE (Amplify Your Effectiveness) conference was started by Jerry Weinberg about 10 years ago. The conference is designed for people working in the software industry but aims to increase their effectiveness by increasing awareness at the personal and team levels.

This years conference was held at the Embassy Suites hotel in Phoenix Arizona on Nov 9th, 10th, and 11th. The weather was hot and sunny as you'd expect in a desert city. The hotel is clean and spacious and air conditioned, the rooms likewise, and the staff friendly and helpful. It has a large heated outdoor pool with an accompanying jacuzzi, a spacious veranda area and an open-tent area for eating outdoors.

I've read that Jerry started the conference to win a bet he made whilst attending another conference he was not impressed with. It's therefore not too surprising that anything remotely resembling a powerpoint presentation is banned and always has been. Instead the conference emphasizes simulation and experience. The website at http://www.ayeconference.com/ contains a wiki full of material spanning many years and is well worth a look if you are interested in attending.

Each participant's name badge revealed their Myers Briggs personality type (you are asked to do an online test before you arrive). This provided an interesting topic of conversation but was only very lightly used during the scheduled sessions. Many of the sessions were role play type games, typically organized into teams.

The conference is limited to 80 participants on a first come first served basis. $300 dollars reserved a space and the total cost depended on how early you paid in full (reserve later and its dearer). Paying at the earliest opportunity meant another $900 to pay. Plenty of drink and snacks are provided together with a buffet style midday meal. On top of this the hotel room costs about $100 a night which includes an excellent breakfast. Add to this an evening meal and the flight.

The conference felt a lot like a non-technical version of the ACCU conference. It had a very relaxed atmosphere and yet at the same time was quite intense at times. I really enjoyed it and found it a very valuable experience. I met lots of great people and plan to attend in 2010.

Agile Coaching

is the title of an excellent book by Rachel Davies and Liz Sedley. As usual I'm going to quote from a few pages:
Coaches work one step at a time rather than creating a whirl-wind of change.
Patience is one of the most important qualities of a coach.
We find the hardest part of listening is resisting the temptation to jump in too early with advice or to switch the conversation to a similar story that happened to you.
People usually speak much slower than you can think, which is why it is so hard to give your full attention when someone else is talking.
You have to do more than suggest a course of action for people to follow it. You need to lead the way by explaining why it's important and then show them how to get started with it.
Your focus is process improvement, not individual performance.
Each change they adopt reduces their resistance to the next change.
Take care not to ask questions when you actually want to give guidance.
When people start caring only about their own tasks, teamwork starts to break down.
Useful information should be visible to all and not hidden away in computers. Plans kept electronically are information fridges; they give up their information only when they are opened.

Quality Software Management
Vol 2. First-Order Measurement

is the title of an excellent book by Jerry Weinberg. As usual I'm going to quote from a few pages:
Software development is not primarily a manufacturing operation for we (ideally) never develop the same software twice. This uniqueness of product means that Deming's "statistical signal" - though necessary - is not sufficient for feedback control, because there often isn't enough repetition - enough stability - to generate meaningful statistics.
In software we are attempting to obtain value by achieving higher precision than human beings have ever attempted before.
The switch from cost observation to value observation is the strongest indication that an organization has made the transition from Pattern 2 (Routine) to Pattern 3 (Steering).
Under emotional pressure, people literally stop thinking.
A fact becomes a feeling as soon as you observe it.
The triad has special significance for observation, because it is the first grouping in which there is both interaction and observation of interaction.
The way I remember the difference between faults and failures is to think of earthquakes. Faults (in the ground) leads to failures (in bridges, buildings, and so forth).
One of the most sensitive measures of the cultural pattern of any organization is how quickly it finds and removes problems.
Any plan is just a plan - a series of guesses about how the future will work out.
Bureaucracy: people doing things whose purpose they don't understand.

Jonathan Livingston Seagull

is the title of an excellent book by Richard Bach. It's well worth rereading every year or so. As usual I'm going to quote from a few pages:
...to eat, to stay alive as long as we possibly can.
Jonathan Seagull discovered that boredom and fear and anger are the reasons that a gull's life is so short, and with these gone from his thought, he lived a long life indeed.
We choose our next world through what we learn in this one.
Heaven is not a place, and it is not a time. Heaven is being perfect.
You have less fear of learning than any gull I've seen in ten thousand years.
"Why is it", Jonathan puzzled, "that the hardest thing in the world is to convince a bird that he is free, and that he can prove it for himself if he'd just spend a little time practising? Why should that be so hard?
You don't love hatred and evil, of course. You have to practise and see the real gull, the good in every one of them, and to help them see it in themselves.
Don't believe what your eyes are telling you. All they show is limitation. Look with your understanding, to find out what you already know, and you'll see the way to fly.

Shadow Data Types

This article appeared in the December 2009 issue of the accu Overload magazine.

Shadow Data Types

Suppose we have a type called wibble defined as a concrete data type (that is, a type whose representation is fully visible) as follows:
// wibble.h
#include "grommet.h"
#include "flange.h"

typedef struct
{
   grommet g;
   flange f;
} wibble;

void wopen(wibble * w, int i);
...
void wclose(wibble * w);
The definition of wibble exposes the types involved in its representation (grommet and flange in this made up example), and hence requires a #include for those types in its header file. This exposure has a price. One cost is that any change to the grommet or flange header files, or any header files they in turn #include, at any depth, will require a recompilation of any source file that #includes wibble.h (either directly or transitively). Another cost is that client code can easily become reliant on the exposed representation rather than relying solely on the functional api. Note that in C++ you can avoid this problem by declaring your data members private.

Abstract Data Types

These costs are sufficiently high that software developers have invented techniques to hide a type's representation; to turn a type into an Abstract Data Type. An Abstract Data Type is simply a type that does not reveal its representation; a type that abstracts away its representation. In this article I'll look at two abstract data type implementation techniques: Opaque Data Types, and Shadow Data Types.

Opaque Data Types

The term Opaque Data Type is a well established term for the technique of exposing only the name of the type in its header file. This is done with a forward type declaration. This certainly has the affect of not exposing any representation!
// wibble.h
typedef struct wibble wibble;

wibble * wopen(int);
...
void wclose(wibble *);

Storage class restrictions

A definite downside with this approach is that clients cannot create objects.
#include "wibble.h"

void eg(void)
{
   wibble * ptr; // ok
   wibble value; // constraint violation
   ptr = malloc(sizeof *ptr); // constraint violation
}
The wibble type's representation is defined in its source file and so only code in the source file can create wibble objects. Furthermore, these wibble objects have to be returned to users as pointers. These two constraints mean the created objects cannot have auto storage class. This is a great loss since auto storage class alone of the three storage class options allows the clients to decide where the objects live which can greatly improve locality of reference.
// wibble.c
...
wibble * wopen(int value)
{
   wibble opened;
   ...
   return &opened; // very very bad
}
...
A second possibility is to create the objects with static storage class:
// wibble.c
...
static wibble wstorage[42];
static size_t windex = 0;
...
wibble * wopen(int value)
{
   wibble * opened = &wstorage[windex];
   windex++;
   ...
   return opened;
}
...
The final possibility is to create the objects with allocated storage class. That is, to create the objects dynamically on the heap:
// wibble.c
...
wibble * wopen(int value)
{
   wibble * opened = malloc(sizeof *opened);
   ...
   return opened;
}
...
The static and the allocated approaches have opposing advantages and disadvantages. Static storage is very fast and doesn't fragment the memory but the type has to decide the maximum number of objects the application will need. That might be a dependency going in the wrong direction. Allocated storage is much slower and can create memory fragmentation issues, but the application decides how many objects it needs. In short, the classic ADT technique creates an abstraction that is very opaque and pays a hefty price for this "over-abstraction". Abstracting away the representation also abstracts away the size details of a type and it is the loss of the size information that creates the storage class restrictions. The Shadow Data Type implementation technique attempts to rebalance these forces of abstraction by separating size abstraction from representation abstraction.

Shadow Data Types

The term Shadow Data Type, in contrast to Opaque Data Type, is not a well established term. The technique I'm calling Shadow Data Type has probably been around for a long time, it's just that it doesn't seem to have ever been documented anywhere and so a term for it has never become established. I've chosen the term Shadow Data Type to try and convey the idea that when you shine a light on an object it casts a shadow which reveals something of the size of the object but nothing of the details of the object. In other words, a Shadow Data Type has a "full" type declaration (rather than a forward type declaration) but one revealing only the size of type.
// wibble.h
typedef struct
{
   unsigned char size_shadow[16];
} wibble;

void wopen(wibble *, int);
...
void wclose(wibble *);
The "true" definition of the type (together with its accompanying #includes) moves into the source file:
// wibble.c
#include "wibble.h"
#include "grommet.h"
#include "flange.h"
#include <string.h>

typedef struct
{
   grommet g;
   flange f;
} wibble_rep;

// sizeof(wibble) >= sizeof(wibble_rep)

void wopen(wibble * w, int value)
{
   wibble_rep rep;
   ...
   ...
   memcpy(w, &rep, sizeof rep);
}
...
However, there are two problems needing attention.

Synchronized Alignment?

Firstly, there is no guarantee the two types (wibble and wibble_rep) are alignment compatible. We can solve this problem. The trick is to create a union containing all the basic types. We don't know which basic types have the strictest alignments but if the union contains them all the union must also have the strictest alignment.
// alignment.h
typedef union
{
   // one of each of all the basic types go here
   // including data pointers and function pointers
} alignment;
We redefine wibble to be a union with two members; one member to take care of the memory footprint and one member to take care of the alignment:
// wibble.h
#include "alignment.h"

typedef union
{
   unsigned char size_shadow[16];
   alignment universal;
} wibble;
...
The main problem with wibble being a union is that unions are rare. Suppose you want to forward declare the wibble type in a header. You're quite likely to forget it's a union.
typedef struct wibble wibble; // Oooops
We can fix this by simply putting the union inside a struct!
// wibble.h
#include "alignment.h"

typedef struct
{
union
{
   unsigned char size[16];
   alignment universal;
} shadow;
} wibble;
...
This is now sufficiently tricky to warrant an abstraction of its own:
// shadow_type.h
#ifndef SHADOW_TYPE_INCLUDED
#define SHADOW_TYPE_INCLUDED

#include "alignment.h"

#define SHADOW_TYPE(name, size) \
typedef struct \
{ \
   union \
   { \
       unsigned char bytes[size]; \
       alignment universal; \
   } shadow; \
} name

#endif
// wibble.h
#include "shadow_type.h"

SHADOW_TYPE(wibble, 16);

Synchronized Size?

The second problem is hinted at by the comment in wibble.c
// sizeof(wibble) >= sizeof(wibble_rep)
This comment, like all comments, has no teeth. Ideally we'd like an assurance that if the types' sizes lose synchronization we're told about it. This can be done by asserting the relationship inside a unit test of course. The problem with this the possibility that the runtime check inside a unit-test won't get run. Or, more likely, that the unit-test simply won't get written at all. Fortunately in this case we can check the relationship using a compile time assertion. We start with the fact that you cannot declare an array of negative size:
extern char wont_compile[-1];
extern char will_compile[+1];
Now we have to select a size of either +1 or -1 if the asserted expression is true or false respectively.
// may or may not compile
extern char compile_time_assert[sizeof(wibble) >= sizeof(wibble_rep) ? +1 : -1];
Hiding this mechanism behind a macro inside a dedicated header helps to make the code more Intention Revealing.
// compile_time_assert.h
#define COMPILE_TIME_ASSERT(description, expression) \
extern char description[ (expression) ? 1 : -1 ]
// wibble.c
...
#include "compile_time_assert.h"
...
COMPILE_TIME_ASSERT(sizeof_wibble_is_not_less_than_sizeof_wibble_rep,
sizeof(wibble) >= sizeof(wibble_rep));
...
It's worth spending a few moments to think about alignment carefully. The wibble type contains a union to give us the strictest alignment. This means a single wibble_rep and a single wibble can overlay each other in either direction. If we create an array of wibbles the compiler will ensure the address of each wibble is suitably aligned. To do this it may add trailing padding to the wibble type but this padding will be reflected by sizeof(wibble). Similarly, any padding for the wibble_rep type will also be reflected by sizeof(wibble_rep). Importantly, since sizeof(wibble_rep) may be strictly less than sizeof(wibble) we cannot overlay an array of either type directly onto an array of the other type. However, we are only concerned with creating an array of wibbles since that is the type the client uses. There should never be any need to create an array of wibble_reps. Nevertheless, the .c file implementation must always do any array pointer arithmetic in terms of wibbles and never in terms of wibble_reps. Note also that using >= rather than == also allows binary compatibility with any alternative smaller representation.

Casting the shadow

Inside the source file we can create a helper function to overlay the true representation onto the clients memory (the fragment below uses the dot designator syntax introduced in c99):
// wibble.c
static inline void shadow(wibble * dst, wibble_rep * src)
{
   memcpy(dst, src, sizeof *src);
}

bool wopen(wibble * w, const char * name)
{
   wibble_rep rep =
   {
       .g = ...,
       .f = ...,
   };
   shadow(w, &rep);
   ...
}
Careful use of memcpy can help to make the wibble functions behave atomically from the users perspective. That is to say, the function can do the work off to the side in a local wibble_rep, and copy back into the shadow only if everything is successful. An alternative to memcpy is to cast the pointer on each access:
// wibble.c
static inline wibble_rep * light(wibble * w)
{
   return (wibble_rep *)w;
}

void wclose(wibble * w)
{
   wibble_rep * rep = light(w);
   rep->g = ...;
   rep->f = ...;
   ...
}

Constness?

It makes no sense to declare a wibble object with a const modifier unless the object can be initialized.

void pointless(void)
{
   const wibble w; // :-(
   // ... ?
}
However, this is not an issue since the wibble type is opaque anyway. Nevertheless, a slight redesign can accommodate const wibble objects if desired, at the cost of copying struct objects:
...
wibble wopen(int value)
{
   wibble_rep rep = { ...value... };
   wibble w;
   memcpy(&w, &rep, sizeof rep);
   return w;
}
void ok(void)
{
   const wibble w = wopen(42);
   ...
}

Summary

In C it is impossible to expose a type's size without also exposing its representation. It is possible to define a type concretely and to explicitly specify its representation as being "unpublished". However, since C does not offer the C++ private keyword using the representation is always possible and remains a constant temptation. Once one piece of client code succumbs more are sure to follow and like a dam bursting the client and implementation quickly become tightly coupled and any separation is washed away. Completely hiding a type's representation behind an opaque pointer/handle removes the temptation and creates a powerful abstraction but at the price of hiding the size of the type and the consequent restriction on the storage class of client memory. A shadow data type offers a half-way house where a type is effectively split into two, with one part exposing the size and the other part holding the representation. The alignment and sizes of the two parts must correspond. Client code is then able to use all three storage class options. The implementation code takes the full load of the extra complexity mapping/overlaying between the split parts. One interesting observation is that the client code would be uneffected (other than needing recompilation) if the representation was moved back into the client side type (to try and improve performance perhaps). No mechanism is universally applicable and the shadow data type is no exception! Experience and time alone will tell if and how useful it is. Caveat emptor.

Perfect Software and other illusions about testing

is the title of an excellent book by Jerry Weinberg. As usual I'm going to quote from a few pages:
Information is neutral but people's reactions to information are rarely neutral.
I'm not in the proof business; I'm in the evidence and inference business.
A process description is just that, a description ... not of what has actually been done.
To qualify as a test, an action has to seek information that will influence an action.
Fixing under pressure tends to raise the fault-feedback-ratio.
Anyone who makes promises about the future must be some sort of devil.
Errors are made, not born.
In a moment of weakness it is difficult to resist infantile suggestions.
Good tools amplify effectiveness; if your effectiveness is negative, adding tools will amplify only the negativity.

enums in C



Enums are notoriously weakly typed in C. While pondering this the other day it occurred to me that instead of writing an enum like this:
enum suit { clubs, hearts, diamonds, spades };
you could write it like this:
struct suit
{
    enum { clubs, hearts, diamonds, spades } value;
};
The struct wrapper adds a modicum of type safety. It also allows you to forward declare suit (you can't forward declare enums). The enumerators (clubs, hearts, diamonds, clubs) are still visible and can be used when a compile time value is required (e.g., switch cases). As usual, caveat emptor.