Wednesday, April 27, 2011

A trip to Berlin

I’ve been teaching game programming at the University of Darmstadt for a couple years now: as they say, teaching something helps you clarifying it in your head. They also say that who can do something does it, who can’t teaches it Smile

irrational

Last week I called two “volunteers” as usual to write some code at the main computer in front of the rest of the class, gave them some freedom to choose a solution for a little problem we were having in our XNA game. The solution they came up with was good and, then, they generalized it, writing some more code, and then some more code, and then a little bit more code.

I asked why.

We might need it later

I replied.

So next weekend you want to go to Berlin, spring is finally coming, time to enjoy a bit of sun, it won’t last long here in Germany. You evaluate all the available options, you may take the train (even if they are so expensive here), or go by plane which is not much more expensive than the train and takes less time, or rent a car which would give more freedom but costs a bit more. You discuss it among yourselves for a while, weighing pros and cons against the cost of each option; the train will be around 200 euro per person, same as the a plane ticket, while renting a car would cost around 100 euro per day plus petrol. You finally choose and you buy a car for 5.000 euro. Why? You might need it later. Maybe you will like Berlin so much that you want to travel there every weekend, or you will need the car to go to Amsterdam instead, or even Or maybe you will not do anything like that, and you will spend ten times more now to go to Berlin than if you just hopped on a train…

 

images

In our daily life we face this kind of tradeoffs and, with material things, we very often rationally choose to spend less now for something we need now, rather than spend more for something we might need later. I’m ignoring for this post the well proved fact that decisions are not always taken rationally (for a good book on the matter look here). In software we usually take the alternative route, we might need it later, we are willing to spend more now for something that more often than not we will not need later. We do it so often that we gave it a name: Over Engineering.

I believe that this peculiar behavior stems from the fact the cost associated to each line of code we write is not directly evident, it’s not money leaving our pockets. It’s also difficult to estimate precisely, which leads to the false perception that generalizing a solution will actually save time. It will not. Each line of code has a cost over time in terms of maintenance and added complexity, that is paid by the team day after day: if it doesn’t solve a problem that we have now, it’s a sunk cost. It requires a huge amount of experience to foresee that “we might need it later” is actually going to be true, and it also requires having gone through the same problem at least few times, which is not always the case in our Industry: we are on the bleeding edge of technology, uncharted territory, where things are complex by nature. Adding more complexity that is strictly needed is not going to help our cause.

Half jokingly with my students, I showed how they could solve the problem with half the number of lines of code, which will probably mean something like half the number of bugs at the end of the project if the idea is applied consistently.

You Aren’t Gonna Need It

Tuesday, April 12, 2011

Undeniable logic

One of the biggest mistakes I used to make in my career in the Industry was to think that a logic argument, well reasoned and with plenty of data to back it up was enough to convince reasonable and clever people, the kind of people I work with. An example is my favorite topic (no, it’s not commenting code), automated testing and unit testing: we all know that writing unit tests is a Good Thing™. We all do, right? There’s plenty of evidence and my argument for writing unit tests before even writing code is very solid. I was naturally expecting that after some resistance due to various reasons, the vast majority of my co-workers would eventually give up and embrace my reasoning, if not flat out try what I was advocating. But discussing automated testing here is not my goal now: my point is that very few people could actually see and understand my point. How frustrated I had been before realizing that it was all my fault.
It took years to understand that the undeniable logic in an argument is not enough to convince someone of its validity: it’s as important and most often even more important how the argument is expressed, how it’s told and explained.
3eangz5w[1]
John is a very clever programmer, extremely sure of himself, who likes to drill into the details of a problem; his method is tried and true, and he wants to give something else a go by himself before incorporating in his work. He likes to picture a problem and see a solution. I approach John and explain him that according to several studies writing Unit Testing  makes code more reliable and reduces cost of ownership for a code base, so he can focus on the general problem rather than fixing small bugs; doesn’t it sound correct? John thinks “bah” and moves on.
Trisha is a very clever programmer, who likes to keep herself informed by reading about how others in the Industry have solved similar problems in order to possibly produce something better for herself. She likes to think about the big picture rather than wasting time on irrelevant details. She wants to feel a problem before touching the right solution. I tell Trisha that if she tries Unit Testing for herself she will find that her code will be even more reliable, simpler and easy to change when she needs to change the details of the implementation, which is a result that she can immediately see after only few weeks. Trisha politely smiles at me thinking “bah” and moves on.
Things are not as simple as in my example, but we can immediately draw some interesting conclusions from it: in both cases what I told to John and Trisha is true and verifiable, but I failed to understand how they want information to be presented to them, which is radically different! John doesn’t care that others find Unit Testing useful, he wants to try for himself, while Trisha doesn’t want to try something if others haven’t already established it’s viable. John wants to see an argument not hear it, Trisha wants to feel it not see it.
Interestingly, addressing a group of people makes it even more difficult because different personalities are likely to be present, how about:
Writing unit tests before code is proved by different studies to be effective, which is something that you can see by yourself in just few weeks of trying it out, either on some small units or in a big problem that sounds difficult to tackle. You can easily feel the advantages or come to ask me for advice if you encounter problems.
How does it sound? Smile
This realization makes leading a group of people even more challenging: now it’s important not only to have a solid and well thought-out vision, but also to understand the nature of the people we work with, how they want information to be presented to them, how they like to reason and respond to problems. Failing to communicate our vision is our mistake as leads.

Post also available on AltDevBlog.