Search

Lukasz Machowski

Life is a mystery, wrapped in a conundrum, nested in a recursive method.

From Java to JavaScript

In this article, I provide a different perspective on how one can understand modelling with Java and JavaScript. Modelling in Java (or any 4th generation language like C# or Visual Basic) is extremely well known because it gets drummed into student’s heads at university. There is a paradigm shift required when moving to JavaScript. Here I present a practical approach to understanding the two. This is my mental-model which I would like to share with you.

This post is for you if you have been using Java for a while and want to make a step into the fresh new world of JavaScript (client and server side ie: node.js etc). It also applies to you if you have been using any 4th generation language (like C# or Visual Basic) because they all use the same classical model of inheritance. This post is even for you if you have never programmed in any of the languages. It gives a conceptual overview of something more fundamental and universal… the philosophy of modelling. I have this romantic notion that if Aristotle of ancient times had a day job today, he would have been a Developer (especially due to his ideas behind classification and other foundational concepts in software development). Please read on for a slightly different take on this topic.

The Real World

Let’s think about the real world for a second. When last did you see a class? I haven’t. When last did you see an object? All the time! Isn’t that strange? As developers, we put so much emphasis on writing code for a concept that has no real world manifestation.

Class vs Object

Now I want to go through a thought experiment.
Think of a chair:

Wooden Chair
A wooden chair.

Just about everyone would agree that IT’S A CHAIR. If I asked you to describe a chair, you might say something like:

“It has four legs and you can sit on it.”

But what about this one:

Hand Foot Chair
Another wooden chair.

This is also a chair. But completely different. It doesn’t have four legs. One big one instead. And it literally holds you up when you sit on it. They are both made out of wood, but that is clearly not so important for it’s chair-i-ness. So what exactly makes it a chair? Well it depends on the context. That’s interesting… That means that any attempt at capturing the essence of the chair, is highly dependent on the context in which we will use that definition. If I told you that the second chair was standing in an art gallery with a price tag of a Million Dollars, would you still consider it as a chair, or would it be a ‘work of art’? Too precious to sit on.

Now this is where it gets even weirder. Where is the definition of a real-world chair? Point at it. I can’t. If you forced me to find one, I might come up with something like this:

Chair Blueprint
A blue print of a chair.

Now this looks closer to something that resembles a class. But it doesn’t. If I modify the picture above, it doesn’t magically change all chairs out there that were made with the same make and model. This is just a representation of the chair. A different object that helps us describe the characteristics of the particular chair we want to build. The definition of the chair only exists in our minds. All the artefacts that describe it are completely disconnected from any instances of that chair and they simply serve as aids for us to share ideas between each other around this idea we are trying to define. The distinction between “Concept” (Class) and “Object” (Instance) only exists in our minds. It’s an idea.

Look at this set-up:

Boardroom Chairs
Chairs in a boardroom

Each chair is an instance of the same class. They are all made in the same factory from the same blue-print. Heck, even their serial-numbers are sequential. But no matter what I do to any of the instances (dismantle it, augment it, decorate it…) the other instances are unaffected. Furthermore, no matter what happens to the blue-print in China, nothing will change about these instances of chairs standing here. There is no magical link that connects these chairs to their class definition that was used to make them. It’s all in our heads.

We must acknowledge that the entire notion of class in the real world only exists in this imaginary realm that only exists in our heads. And even that notion is highly dependent on the context in which it is thought up.

Privation

Another fascinating idea that I discovered when reading Aristotle is the concept of privation. Think of the word “deprivation” or “deprive” – to be missing stuff.

Now think of a man…

Wayne In 'The Man Who Shot Liberty Valance'
American actor John Wayne (1907 – 1979) wears a Western outfit which includes a pistol in a holster and stands in a doorway in a still from the Cowboy film ‘The Man Who Shot Liberty Valance’ directed by John Ford, 1962. (Photo by Paramount Pictures/Courtesy of Getty Images)

This is a REAL MAN. He’s got two arms, two legs, a head. And if we’re talking about westerns, then he’s definitely gotta have a hat.

But what about this guy:

Man with One Arm
Another man.

Is he still a man? Yes, of course he is. Is a man with no arm still a man? Yes of course they are!

The idea that some concepts can loose characteristics that were quite specific in defining that concept, is the idea of privation. It’s the lack of something that makes it specific. This means that the definition for a “One-armed-man” is defined as “Man” minus an “Arm”.

Our existing constructs for classical modelling in software development really struggle with this concept. Classical OOP only has additive definitions. A sub class can only add fields or members to it’s base class. If you want to model privation, we would have to ADD another concept and call it “Things to Take Away”, which is still an additive concept. Interesting.

Ambiguity in the Real World

Now where is this elusive definition of “Man”? Point at the universal “Man”. You can’t. Define “Man”. No matter how good your description, I will be able to keep adding details that contradict or invalidate your definition of “Man”. Is a “Woman” a “Man”. It depends.

This seemingly trivial notion is exceptionally difficult to pin down, yet we are all perfectly happy to go about our daily lives with an imperfect definition of a man that suites us well in everyday life.

Something as simple as the following question:

What is my name?

You might say that my name is “Lukasz” (because you saw that in the title of the article). And you would be right. And wrong! On my birth certificate and ID document, that’s what it says. At work, it’s “Luke“. When I was at school it was “Lucas“. Sometimes my full name “Lukasz” is pronounced “Wookash” because that is how you say it in Polish. Which one is my name? They all are. And none of them are. It depends.

How many databases or classes have you created where a person has a “Name” field? Many. How many times did you later have to add another field like “Nickname” or “Alias”. Not so many, but it happens. We need to keep adding fields for each context that the person might be in. That’s weird. We don’t have a first class construct that natively captures the idea of the context for that field. Maybe what we need is a perspective or aspect? Interfaces could do the trick. Maybe. I don’t know.

Identity

If we have a collection of objects in the real world, how do we identify individual instances? Usually we look for distinct characteristics that are unique across all instances in that collection and we call that the identifier. But let me take that idea to the extreme…

Imagine if I could clone an object perfectly. Absolutely every atom and noticeable aspect of this object was the same. Every label that I would put on both of these objects would say the same thing. If this could happen, and you were holding these objects in both hands, EVEN THOUGH everything about them says it’s the same thing, you would without a doubt still say “But they are different. Look. I’m holding one in each hand.”

The notion of identity must be separated from the notion of existence. The objects exist separately from each other, even though every characteristic that I try describe them with says the same thing.

This leads me to the next idea…

Monad

Imagine if I tried to describe a perfect model of the generic thing. What characteristics are common to all concepts in the universe? None. And even if they were, one could argue that it’s just a matter of perspective.

So where does that leave us? In a very interesting space. Since there is no universal commonness, and since identity must be separated from existence, how can we attempt to create the ultimate base class for every modelling concept.

Well the answer is simple. The only thing we can assume about all concepts is that they share no concept in common. This means that the perfect model of the generic object MUST be this:

object = { }

In other words, it’s a thing that exists but has no fields on it.

This is called a monad in classical philosophy.

What is extremely interesting is that although we can define the perfect modelling construct for the generic object, every software implementation that I have seen needs to pollute that definition for practical reasons. Look at equals(), getHashCode() and toString() in Java. Even JavaScript objects have a ton of stuff on them like hasOwnProperty() and toString(). For practical reasons, we need to pollute the pure modelling concept. But do we really?

Heap vs Stack: A Primer

An important distinction that I need to make before proceeding is to define the mental model I use to abstract away the details of memory in a running programme. Yes, this is a severely simplified model of what happens in reality but I find that it is the only model that most programmers need to have (and usually don’t). It also forms the foundation in which I can contrast the two ways of modelling (in Java and JavaScript).

Memory is memory. There are no colours to memory. It’s all the same. You buy chunks of it and plug it in. It’s the operating systems responsibility to manage it neatly so that each program gets a fair slice of the pie. Before you accuse me of forgetting a million details around caches and buses etc, please give me this lee-way. As an electrical engineer I am fascinated by all the details and what they do but as a programmer, I also know how important it is to have a simple mental model that I can share with other programmers so I can share ideas without getting bogged down in the detail. Here I am sharing with you my mental model that I have found most practical when thinking about programming.

For each program that runs, the operating system divides a chunk of available memory into two parts: the Heap and the Stack. It doesn’t matter what the physical address is of the memory. It is useful to think of it as a contiguous block of memory that can be drawn like this:

Stack vs Heap per Process
Each process has it’s own stack and heap.

Every variable that is allocated as the program runs is added onto the top of the stack. This is indicated by a stack pointer which points to the place where the next variable should be allocated. Different data types take up different amounts of space in memory. An integer takes 4 bytes. Any object that gets created gets put on the heap. A variable is usually used to point at the object, so space needs to be allocated for the reference variable (pointer) and also the object itself. Each object has a certain amount of overhead associated, including information about what type it is. The runtime implementation may also impose additional constraints on the layout of the object so that it aligns with certain size-boundaries.

Stack vs Heap for 3 Integers
Stack vs Heap for 3 Integers

Above we have an example where we allocate 3 integers. Two of them (a and b) are plain-old-variables which only appear on the stack. The third variable (c) points to a boxed integer. Boxing is where a value type, like an integer, is created as an object on the heap so that it can be referenced like other reference types. Above you can see that “c” on the stack is pointing to (or referencing) the memory location where the boxed integer object resides on the heap. Notice how big the boxed integer is (16 bytes) in relation to what it actually needs to store (4 bytes).

Post Script

I was inspired to write this post because of a recent training session I had with two Junior Developers at work. Both of them were proficient in Java and comfortable with OOP (thanks to their University training). What I wanted to do was ramp them up on switching to JavaScript BUT I wanted to do it by contrasting the two languages from a philosophical point of view. At the same time, I wanted to make sure that their mental model of what happens in memory is also correct at the same time. I firmly believe in the importance of getting the logical layer right because so many things upstream are affected by the choice made in modelling the domain of interest. I want my two Junior’s to be excellent modellers!

I was rather surprised how similar the two languages actually are when you draw them out the way below. This is in stark contrast to the usual way in which classical inheritance is explained in comparison to prototypical inheritance. Explaining the two in this way gave me an even deeper appreciation for the Power (and Responsibility) that JavaScript gives you.

Also, I have never been satisfied with the rather weak explanations between the differences between Java and JavaScript. Although they are usually technically correct, they have always left me feeling lacking because they don’t explain to me the fundamental difference at a “thinking” level. Since I am a fan of clean and elegant models (domain driven design etc), I want to be sure that I REALLY understand the way I should be thinking with the two languages before I worry too much about the technicalities of the language themselves.

Advertisements

What Information Theory can teach us about Software Development – Notes from Scrum Gathering

I recently attended a very thought provoking talk by Janco Wolmarans (@jancowol) at the Agile Scrum Gathering Conference (@SUGZA, #SGZA). It really got me thinking.

Janco Wolmarans
Janco Wolmarans

I have captured my notes from the talk so that I can internalise what was presented and also to share it with you. My hope is that it can shed new light on how we perceive coding and it can make you look at the activities surrounding software development differently next time.

Since I am an electrical engineer, the idea of going back to this rather technical view of software development as the transfer of information across a channel really appealed to me. Although aspects of the talk appear to be very theoretical, the magic of Janco’s presentation is that it leaves you thinking… “Hmmm, that actually does apply to software development”.

At the end of the blog, I also explore some of my own ideas surrounding code comments and the benefit of double-encoding.

Introduction

Janco started his talk with a reflection on whether there is something more fundamental to software development. When we don’t understand something, we use a metaphor in its place. “Something is like something else”.

“Metaphors reign where mysteries reside” – Chuck Missler

The problem with metaphors is when they don’t apply.

What is Programming?

  1. A set of instructions for a computer to exercise (insert favourite dictionary definition here).
  2. A description of a solution to another programmer disconnected in time. This could be another physical person but it could also be yourself later in time.

What is Information? Is Code Information?

Janco ponders the thought of whether code is information. Information is a polymorphic concepts and the definition of it is specific to its context.

The general definition might look like this:

  • X consists of one or more data.
  • The data in X is well formed.
  • The data in X is meaningful.

Therefore, we can answer the question: “Yes, code is information”.

  • The data is made up of the characters of the source code.
  • The code is well formed and complete because of the syntax that defines the language.
  • The code has meaning, not only to the machine, but more importantly to other programmers.

Information Theory – Claude E. Shannon (1948)

Claude Elwood Shannon - Father of Information Theory
Claude Elwood Shannon – Father of Information Theory

Claude Elwood Shannon is known as the father of Information Theory. Just about every form of digital communication we use today is based somehow on the seminal work that Shannon did. Janco gave a brief overview of Shannon but I was most intrigued to hear it again because of my recent interest in data compression (watch this space). Janco presented the following illustration which describes communication in just about any information system. Notice the important distinction between the signal and noise. This means that a message “X” might come out slightly altered “X’ ” on the other end.

Generalised communication in an information system.
Generalised communication in an information system.

Janco presents an interesting idea, which is “What if we drew software development in this fashion.” Below is my rendition of his picture, with my own ideas on what could be considered the signal and noise.

Coding represented as a Signal and Noise
Coding represented as a Signal and Noise

Signal vs. Noise

  • The signal is the solution to a problem.
    • I added my own ideas on what would belong in the signal in the illustration above.
  • The noise is all the other things that are around the code.
    • Fluff
    • Accidental (but necessary) complexities.
    • I added my own ideas on what would belong in the noise in the illustration above.

Information Entropy

Entropy in physics is the tendency to move towards disorder.

Shannon’s definition of entropy in an information system is different.  Information entropy is the log-base-2 of the number of possible outcomes [wiki].

With two coins there are four outcomes, and the entropy (N) is two bits.
With two coins there are four outcomes, and the entropy (N) is two bits.

Janco makes the following remarks about entropy:

  • It is based on the probability.
  • Entropy is equivalent to uncertainty.
  • Uncertainty of the code doing what I expect.

The way that I like to explain entropy is with the following example…

Try and guess the next number in the sequence: “1,2,3,4…?” If you answered “5” you would be right. Now try to guess the next number in another sequence: “1, 9, 0, 6…?”. If you answered “8” then you somehow miraculously would have also been right. The second time it was a bit harder to guess what the next number might be. Therefore the second sequence had higher entropy. I base this example on my understanding of what is written on the wiki:

If one of the events is more probable than others, observation of that event is less informative. Conversely, rarer events provide more information when observed. Since observation of less probable events occurs more rarely, the net effect is that the entropy (thought of as average information) received from non-uniformly distributed data is less than log2(n). Entropy is zero when one outcome is certain.

4 Rules of Simple Design – Kent Beck

Janco then presented some important design concepts made popular by Kent Beck, the father of Agile Programming.

  1. All tests must pass.
  2. DRY: Don’t repeat yourself. Refactor the code to avoid duplication of logic. Call the common code.
  3. Clearly express intent.
  4. No superfluous parts.

Janco makes the clear connection then to an information system:

  1. Signal
  2. Entropy
  3. Entropy
  4. Noise

XP Values – Kent Beck

  1. Communication
  2. Feedback
  3. Simplicity
  4. Respect
  5. Courage

Janco points out that 1-3 relate to effective communication. He then asks: “What would a model for Dev-to-Dev communication look like through the medium of code?”

Dev to Dev communication in TDD
Dev to Dev communication in TDD

Refactoring

Refactoring is a way to achieve “DRY” and to “Clearly Express Intent”. To refactor is to express the solution in a different way but to keep the same outcome. Refactoring increases the clarity of the solution by raising the level of abstraction. This is done by encapsulating many low-level concepts into one higher-level concept (by adding more context). This leads to a reduced message space, thus lowering the level of uncertainty throughout the system.

“Being abstract is different from being vague” – Dijkstra

Abstraction = New Level where you can still be precise

Good programmers write code that other humans can understand.

Things to Explore

These are some ideas that came out from the audience or were raised by Janco as additional ideas to explore. If you have some thoughts on these or additional ones to add, please leave a comment below.

  1. We need to better articulate “Noise”. What are concrete examples to look out for and can we mitigate it?
  2. We want to have a Ubiquitous Language. See Domain Driven Design (DDD).
    1. Strive for one mental model across Client – BA – Dev.
    2. Have a problem with different perspectives of the problem.
  3. Mob Programming
    1. Reduces noise because we all share a common signal.

That was the end of my notes from Janco’s talk. Below are my own ideas to augment what he presented.

Comments are Noise! Really? I say no! It’s a redundant Channel.

Something that really struck me as odd during the talk was Janco’s negative attitude towards comments in code. This sentiment seemed to be shared by several members of the audience. This didn’t sit well with me at all. It seemed like Janco’s take was that code should be self describing. The problem with code comments was that they tend to be superfluous and they can easily get out of date. Maybe I was missing a critical piece of context that they were privy to and I wasn’t.

I have also heard other people saying “Only write comments where the logic of the code is not obvious”. My personal commenting style obviously annoys the heck out of those people, because I comment everything. Sorry.

My take on it is simple (you will see why it makes sense later):

Write comments everywhere so you can tell the whole story of the code only by reading the green lines (comments). Ignore the actual code until you need to dig into the detail.

This seems crazy at first. Why on earth would you write the perfect solution in code and then write it again (imperfectly) in English? Let me reveal another important concept that was NOT addressed in the talk by Janco but I learnt the hard way at my excellent time at Cyest. It was once again confirmed at Synthesis.

The Value of Double-Encoding

Imagine if I could tell you that we could write code in such a way that a positive outcome is guaranteed when a bug is discovered. You would probably say I was crazy. The answer is simple…

Encode the solution more than once. If one encoding has a bug then the other encoding can be used to look where the logic differs from the first. If the bug is a logical error then both encodings will not make sense in the context of the situation (thus highlighting the logical error). This is a win-win situation.

We have been doing this with Unit Testing for ages. Unit tests are an additional encoding of expected outputs given known inputs. It checks that the code (encoding 1) behaves exactly as expected when compared to the unit test (encoding 2). If the outputs differ then the system reports a failure and a bug is picked up. What is interesting is that at the extreme end of this argument it even makes sense to simply “copy-and-paste” actual implementation into a unit test and compare the outputs against each other. The value in this is only made clear down the line (later in time) because unit tests tend to change slower than code. If a bug is introduced into the code, there is still the previous implementation in the unit test that will give capture the old behaviour exactly. Obviously this approach assumes good sets of known inputs.

My idea is that the code comments act as a second encoding to the code but it’s not in a completely separate [disconnected] place in the code (like unit tests are), rather it’s inline with the code. The wording then becomes the following:

Encode the solution more than once by commenting everything (even the obvious code). You can find encoding bugs by looking for places where the code differs from what is described in the comment (or vice-versa). You can find logical errors by tracing through the expected logic and seeing where either the code or the comments tell a different story. This is a win-win situation.

3 Possible Outcomes with 2 Encodings
3 Possible Outcomes with 2 Encodings

For the first time, Janco’s idea of relating code to an information system gives me a language to use where my argument makes some sense. The idea is commonly used in very noisy channels. By adding a redundant channel to transmit the signal, you are able to compare both results at the end and more easily pick out the signal from the noise. The chance of both encodings having an error is much smaller than only one of the encodings having an error. With one channel, you really can’t tell.

If you were to extend this idea to 3 channels then something even more useful pops out:

Best of 3 wins.
Best of 3 wins.

If we use inline (or in-band) redundancy in the form of code comments AND we use out of band redundancy in the form of unit tests then we are able to use a “best of 3” strategy to decide which encoding has the bug. The chance of all 3 being wrong is now even less, making bugs much easier to find.

I have found this technique SO useful when writing and maintaining rather complex code (the calculation engine for a financial modelling tool, for example) that I have now decided that I will write all my code like this. As with all developers, writing the unit tests is a “Best-effort” endeavour. I always have great intentions but there is usually some external factor hindering me. However, inline code comments are something I can ALWAYS do, and therefore I have chosen to do exactly that.

Therefore, if you ever come across my code and it’s commented EVERYWHERE (even in the obvious bits), please don’t get upset with me… there is some method to my madness. I never know where the bug will be in my code, but the tiny bit of extra effort it takes to add the multiple encodings pays itself back many times given the full life span of the code.

“It’s not magic… it’s statistics” – Luke

Comments from my Colleagues

The following is a very interesting set of replies that I got from people I work with. I humbly thank them for their insight because I have a lot of respect for their ideas. I feel that it’s very important that I post this because it captures to polarization of thinking around the topic above. It also provides a very seasoned perspective on how my argument around comments in the code should be considered carefully.

I have only provided first names here to keep the conversation flow simple.

Garth:

I have to say that I agree with Janco that comments are mostly noise and really don’t buy your idea of commenting everything.

I like Robert C. Martin’s reasoning that your code should be human readable and therefore comments add no additional value.  The emphasis should therefore be on writing “Clean Code”, and not cluttering your code with comments.

Check out Robert C. Martin’s “Clean Code: A Handbook of Agile Software Craftsmanship“.  I found this book to be incredibly inspiring and good at showing what “clean code” is and what “clean code” should be.  The book is in the “library”, so check it out.

Johan:

I believe that comments can be noise however have a look at the following code:

using System;
using System.Numerics;
namespace PiCalc {
internal class Program {
private readonly BigInteger FOUR = new BigInteger(4);
private readonly BigInteger SEVEN = new BigInteger(7);
private readonly BigInteger TEN = new BigInteger(10);
private readonly BigInteger THREE = new BigInteger(3);
private readonly BigInteger TWO = new BigInteger(2);
private BigInteger k = BigInteger.One;
private BigInteger l = new BigInteger(3);
private BigInteger n = new BigInteger(3);
private BigInteger q = BigInteger.One;
private BigInteger r = BigInteger.Zero;
private BigInteger t = BigInteger.One;
public void CalcPiDigits(){
BigInteger nn, nr;
bool first = true;
while (true) {
if ((FOUR*q + r - t).CompareTo(n*t) == -1) {
Console.Write(n);
if (first) {
Console.Write(".");
first = false;
}
nr = TEN*(r - (n*t));
n = TEN*(THREE*q + r)/t - (TEN*n);
q *= TEN;
r = nr;
} else {
nr = (TWO*q + r)*l;
nn = (q*(SEVEN*k) + TWO + r*l)/(t*l);
q *= k;
t *= l;
l += TWO;
k += BigInteger.One;
n = nn;
r = nr;

}
}
}
private static void Main(string[] args) {
new Program().CalcPiDigits();
}
}
}

From the function names it is clear that we are calculating PI. However, I believe that comments or a link to the algorithm IS needed. Just renaming the variables will most probably not work. Further, I have had many times where clients that are not technical looks at the code and can understand what it does via the comments and have been able to give valuable input. So even though comments do tend to ‘decay’ over time if the ‘signal’ component is strong enough in the comments they will continue to provide pointers in the right direction.

Garth:

Hi Johan. My argument would be that the code example you have given is NOT an example of clean code and hence it is confusing to read.

The main problems with the code is that:

  • Variable names are not descriptive
  • The method is way to long

A clean code example would probably be more something like:

while(true) {
if(descriptiveCondition())
descriptiveMethodName()
else
anotherDescriptiveMethodName()
}

The names of the methods then lend to describing the logic and the code becomes more “human readable”

Luke:

Both comments really add a lot more depth to this discussion. Both sides highlight important aspects that need to be considered in context.

I appreciate you taking the time to shed light on the parts that matter in code.

I might not have the perfect commenting strategy but it is interesting to relate the idea to Information Theory as Janco presents it. It makes you think…

What Garth presents is clearly a good method to enhance the fidelity of the signal (in one band). I would imagine that we all would agree that If this is possible then it’s always preferable. However, Johan highlights a case where (for arguments sake) it’s not. When I look at the PI digit calculator, I also know that the code is usually used in a performance critical section (eg: I want to calculate PI to the billionth digit etc) and there might be good reasons (that I am not aware of from the little context we have) why the code needs to be written in that fashion. It that was the reason for the style of code as written, then I would personally prefer to have the inline comments to help me along without having the performance knock of the extra method calls (and yes, I do realise that I might be opening a can of worms now around the debate on micro-optimisations being done by hand vs the runtime jitter).

Tom:

My turn!

While I agree with Garth on better descriptive names, I think we must use some common sense and judgement not to normalise to the n-th degree. In languages with first-class functions then it’s mostly cool, but in crummy Java and C# you tend to end up with a proliferation of rubbish functions that are only useful in a single context.

E.g. Too many functions called batty names like:
If (StringIsNotNullAndEqualToSynthesis(myString)) {
.. Blah
}

are actually not as readable as
If (“Synthesis”.equals(myString)) {
.. Blah
}

Also – I find it really helps to try to make your code as immutable (google it) as possible,

e.g. Garths previous example:

while(true) {
if(descriptiveCondition())
descriptiveMethodName()
else
anotherDescriptiveMethodName()
}

Shows clearly that mutation is happening and therefore not clear what the code is actually doing (because it all happens outside of this snippet). This makes this code difficult to lift out without diving into the rabbit hole of each function. The rule of thumb is that a function should take as parameters all it’s inputs, and are a return value return all the outputs. It should not mutate anything else (as far as possible).

Soooooo many benefits to doing this:

  • Truly testable code (no injecting weird dependencies into seemingly unrelated objects during test setup).
  • Super easy to debug (maybe no debugger required even! Stuff doesn’t ever change!)
  • Performance benefits! You don’t need to copy data around for various usages, because you can guarantee that data doesn’t change you can simply pass around a reference to each caller without the danger of them modifying it! (flamebait achtung!)

Hey I’m not saying this is a firm rule, it’s simply a nice starting point – obviously you are going to need to mutate stuff. I’m just stating that I bet you the “mutant” area of your code will contain the bulk of your bugs 🙂

Garth:

Hi Tom,

I fully get your point about immutability and functions taking all their inputs as parameters and spitting out one output.  What I find is that this is a natural by-product of test driven development.  So for me this is one of the reasons why test driven development is a must and not an option.

Gilbert:

Hi Luke, great that you took the time to write this down. I like the direction; esp. with double verification and in-line value of comments. The problem is comments are not machine-verifiable/runnable. Perhaps if we write our comments in a language like gerkin, we’d achieve in-line unit tests. Something like (excuse inaccurate syntax):


// Scenario: Sums 2 numbers
// Given 15 and 12
// Expect 27
int sum(int i, int j) {}

Another point, is the trends seem to be towards higher level unit-test; so the double verification is not on the base utilities – these will get covered through broader, more efficient sweeps.

Of course code should be as expressive as possible.

Can Agility Change the World? – Notes from Scrum Gathering

Some people just have it. Cara Turner (@Cara_Faye) at the Scrum Gathering definitely has it! She delivered an inspiring and thought provoking keynote, which I would like to share with you. Her slides are here and I borrow several screenshots from them because she has great visuals.

@Cara_Faye
Cara Turner (@Cara_Faye)

Cara is involved in a company called Codex which teaches eager South Africans how to become coders. They embrace Agility as a key tenet of their methodology and give the students hands on experience on how to deliver working code. This is their solution to the scarcity between skills and jobs in the country.

My post starts with a realisation which stems from the thinking inspired by Cara. It relates the current student-crisis in South Africa to the startling realisation that Cara and people at Codex discovered. My post follows with a brain-dump of my notes from her presentation. I hope there are some interesting ideas that you find useful in here. Leave me your thoughts in the comments below.

Double Pyramid of Needs

The missing link between Government and Industry

Cara presented her thoughts on scarcity and privilege. This is relevant because there is a severe shortage of programming skills amongst the have’s and have-not’s in South African society. At the time of writing, South African students are protesting because of fees (news article here, and here: #FeesMustFall). My take on it is that there is an underlying (deeper) issue at the root of the problem and it’s NOT education, and Cara’s presentation gave me a glimpse of what it might be.

When CodeX started out, they (diligently) believed that the solution would be to uplift education in order to improve employment. This is how Cara presented it:
Network Effect

This makes intuitive sense. Sure, why not! What startled me was when she said that they learnt the hard way that their real challenge in achieving that was to first bridge the digital divide that stopped students from being able to spend time on their education. It’s all the stuff at the bottom that has to come right too.
The Digital Divide

The real problem is NOT people’s unwillingness to get educated. And not even their access to education. The real problem is their inability to do so due to constraints on all the factors below education. Eureka! For the first time I can see the direct connection that the government has in the technological upliftment of its people. They mustn’t worry about the upper factors because people like Cara can do that. Industry can do that. Business can do that. Universities (which I see as a bridge between Industry and Academia, themselves being a Business) can do that.

Instead, Government MUST provide people with the basics: electricity, water, sanitation, safety, health, social support etc. The rest will sort itself out. Governments responsibility is to ENABLE education by allowing the factors below to come right for each individual.

I like to see the double pyramid like this:

The double pyramid showing what Industry and Government should focus on
The double pyramid showing what Industry and Government should focus on

Governments responsibility is to do this. It has let us down! Dear President Zuma @PresidencyZA, please focus on your pyramid and we will handle the rest.

The way that Cara explained how they overcame this challenge (or to use a software term: ‘worked around the issue’) was by applying an agile-inspired solution to the problem. Flip the triangle around. They instead acknowledged that people will have transport issues and be unreliable. Going to the clinic is not something you do in an hour… it takes a whole day. Looking after your brothers children while he goes to your grannies funeral is just a part of life. Instead of having set lectures and exams at specific times, students work at the pace they can sustain (Khan Academy comes to mind). There are concrete milestones along their learning path. It doesn’t matter if you go away for a week. You can continue where you left off. This is genius. It reminds me of how Agile has broken the reliance on Fixed Requirements upfront. So too has CodeX broken the reliance on firm commitments by the students all the time.

Someone on the radio said today ‘People in positions of privilege won’t understand these issues that the students are facing’. With the context presented so elegantly by Cara, I think I am able to get a glimpse of it now.

I have an open challenge to you… while we wait for government to bridge the gaps of the first pyramid (relying on mass-action like tomorrows march by students to the Union building to make the issue real), what are ways that you can ‘flip the triangle around’ to work around the gaps? Swap one thing for another in your context and imagine what would happen… then try it out!

What follows is a collection of my notes from Cara’s keynote session. This provides additional context to the argument above but also has several gems that are worth taking from her talk.

Can Agility Change the World?

Cara Turner’s Keynote

What makes a hero? Ordinary people that decide that they will make a change and embrace the opportunity to make a change they want to make.

Hero = Ordinary People + External Trigger + Change

But we are all too busy with the problems in front of us. In spite of our best efforts, when the going gets tough, we fall back to our old habits.

Scarcity Science

Relevant for anyone that experiences a “Sense of Lack” or “I never have enough”. What happens to the mind is that our active and background mind is fully consumed on the problem in front of us. We get tunnel-vision focus on what is in front of us. This is an important mechanism from an evolutionary perspective but it also becomes a hindrance in our modern day world filled with stress. This becomes a problem if it persists all the time. We go into a mode of “What is the lesser of two evils”.

In times of scarcity, when there isn’t enough of a resource, the following happens:

  • No time to stop and think
  • We make poorer decisions
  • There is a greater cost to making mistakes
  • This causes more problems
  • Leads to failure
  • Puts more pressure by creating a demand to solve
  • No slack

In a time of scarcity, you behave in a way that reinforces that you will have very little in the future.

The effect of Design

Cara shared a story about Bomber planes during the war that would come back from successful missions, only to crash during the landing at their home airport. The reason was poor design where the landing gear lever was right next to and looked very similar to the air brake lever. All it took was one small change to change the whole situation around. They simply put a rubber band on the one lever to differentiate the two.

A rubber band was placed on one of the levers
A rubber band was placed on one of the levers

One small change can make a big difference

Agility and Scarcity

Look for tools and practices that can:

  • Improve feedback
  • Support decision making

Change Super Powers

  • Change and adapt. Make an assessment on where you are and whether you are getting better.
  • What is the next small change to make a constant cycle of “Change and Adapt”?

The Network Effect

Consciously choose to act on our strengths. It has a rippling upward-spiral effect on the whole system. I like to say: “Always be positive. Its easy to focus on the negative but don’t, learn from it and focus on the positive instead”.

A small positive change can have a positive spiral effect on the whole system
A small positive change can have a positive spiral effect on the whole system

Continual Improvement

“We are uncovering better ways by doing it and helping others do it.” – Agile Manifesto.

It’s our responsibility to share our techniques and insights with others. That way we can ensure a continual improvement.

What’s Next?

  1. Challenge: What are the small things that you can change to see what kind of effect it will have?
  2. Don’t try to learn everything upfront before you start. Just start.
  3. Start and keep learning as you go.
  4. Share your knowledge as you go. [This is the line that inspired me to start blogging].
  5. Be part of a community.
  6. Keep inspecting and adapting as you go.
  7. Build us a new super her tool. Build it together with your community.
  8. We need all kinds of hero’s.
  9. Solve the problem in front of you.

I aim to use the above as a personal checklist. Very inspiring Cara!

Our Next Challenge

One demographic holds all the skills in software. There is a great digital divide between the different demographics. Why? Because of Scarcity and Privilege.

We are not all made equally.
We are not all made equally. Some enjoy more benefits than others.

Help short people be like tall people. The system is designed for tall people but we have a workaround.

Tall people are just better off. The system is designed for tall people.

Everyone's perspective matters.

How do we change the system?

  • Innovation is social.
  • We need people that have skills and knowledge of their specific problems.

Organisations with greater gender and ethnic diversity pay better dividends. Gender and racial diversity is a good sign of health in an organisation.

Diversity + Inclusion = Improved Business Performance

Change is hard. Gestures cost money to achieve the benefits and avoid the costs. We must make a meaningful investment into it if we want to reap the reward. This sounds similar to where the Agile community has been.

Change Routines

  • Mentorship
  • Change the way you recruit
  • Extend invitations broader than you normally do. Invite people.

Agile Skills

  • Create a safe space.
  • Talk about the issues. Have those uncomfortable communications.

Why is it so hard? Because we have a sever shortage of skills. CodeX aims to bridge that gap through education in agile software development. Eduction is a foundation, but actually it’s at the top of a basic needs pyramid.

Next Challenge

  • Scaling agile training
  • Person to person interactions

Creating Change

  • Look at the problem in front of you.
  • Make an experiment.
  • Share it with the community.

Parting Thoughts

  1. Tackle the Wicked Problems
  2. Be unlikely
  3. Be yourself
  4. Rise to the Challenges to create the change you want to see in the world

“The best way to predict the future is to invent it.” Alan Kay

Unlikely Heroes – SUGSA Agile Scrum Gathering Conference

I recently had the privilege of attending the Scrum Gathering in Rosebank, Johannesburg. This was my first proper Agile conference and it was quite an eye-opener for me. In this post, I would like to share with you some of my observations and comments. Mainly as a way for me to internalise the content, but hopefully so that you can find some aspect of it useful and thought provoking too.

Where are all the Woman in Software?
In Agile, of-course!

One of my most pleasant surprises from the conference was how many active, passionate and inspiring woman I saw at the conference. Speakers AND attendees. Not as software developers, but as scrum masters and coaches [NOT project manageresses]. The fact that I find this surprising is a sad reflection of the software development industry but I was excited to take part in an event that really show-cased thinking with a female touch. Both Keynote sessions that I attended were presented by ladies (Thato Kgatlhanye and Cara Turner). I must say that I haven’t been this inspired in a long time. They really packed a punch. Good on them! Thank you!

Thato Kgatlhanye - Rethaka thato@rethaka.com
Thato Kgatlhanye – Rethaka
thato@rethaka.com

Cara Turner (@Cara_Faye)
Cara Turner (@Cara_Faye)

It’s as if any male-dominated influence in the software development world hasn’t yet had a chance to dominate, leaving a much welcomed gap for women to take the lead. It makes sense, because the agile movement is still relatively young – as in youthful, not infantile. Everyone started on an equal footing so there hasn’t been a chance for the vacuum to be created.

This transformation is one of the unsung heroes that the agile movement has enabled!

It often seems to get forgotten when mentioning agile. It wasn’t explicitly said anywhere in the conference (unless I missed it), but I feel it should be.

Disconnected Circles

supervista_educationicons_maths_256Another interesting thing that struck me at the conference is how segregated the various communities seem to be. I am making a concerted effort to attend as many user groups, events and gatherings as I am able to (and I thank my wife for giving me the space to do that), but I was surprised at the lack of familiar faces from the other groups. You almost expect to see some familiar faces that are always present in certain gatherings, but this group seemed completely new to me. During the sessions I realised why this was… most of the people attending were NOT developers… they were Scrum people. That made me think how segregated the groups actually are. I felt lucky to be part of the conference because I felt like I got to find out some “inside information” that I otherwise would not have been able to get access to. It does make you wonder why more developers don’t attend agile conferences. I would really recommend this for any developers that need to better understand business, their users and working in a team (and that should be all of them). It also makes me realise how valuable the culture is at my work (Synthesis). It’s a culture worth protecting because it emphasises the need for this multi-faceted thinking. Agile seems to have that covered.

Lightning Talk: Saving the day by starting today
Tjaard du Plessis

sigma_projectmanagment_energy_128My colleague, Tjaard, was asked to present a lightning session within a window of only 10 minutes. This means that the speaker really needs to think carefully how best to get the their message across effectively. True to Tjaard’s style, he managed to pull this off flawlessly. I felt that his session was just as impactful as any of the longer sessions.

In his talk, Tjaard introduces 2 important principles that often relate to each other:

  1. Parkinson’s Triviality Principle
    • We have a tendency to focus on trivial problems and ignore complexity… because it’s easier to do so.
    • We tend to digress into solving the simple cases.
    • Therefore we shouldn’t spend most of our time focussing on a trivial problem.
  2. Pareto 80/20 Principle
    • 80% of the land is owned by 20% of the people.
    • 80% of the value in our system is due to 20% of the functionality/features.
    • Engineers and Entrepreneurs see the world as a problem to be solved.
    • The problem of trying to get all the “What-Ifs” is: “What-if I haven’t thought of all the what-ifs“?

His realisation is that both 1 and 2 are related.

“We tend to digress to the trivial because we can’t think of all the what-ifs.”

The solution is to “JUST START!

So how do we define “Start”? Well, in engineering, the process is well defined: Analyse -> Design -> Develop. In software, the process of development is part of the analysis.

A start in software is NOT something you do AFTER you have certainty. You gain the certainty only after you have started.

Delivery is the best way to gain certainty. While you are gaining certainty, you are delivering. We need to be in the correct arena to solve the complex problems.

I imagine that Tjaard had this picture in mind (which he shared with me during a break).
http://www.applitude.se/2011/02/the-project-triangle-turned-upside-down/

irontriangleturnedupsidedown
This highlights how the traditional waterfall model fixes the features at the expense of uncertainty on time and cost. Agile on the other hand insists that the cost, time and quality be fixed and the features that will be delivered are the unknown.

Tjaard then proceeded to show a photo of their user story map, highlighting how stories that are important are placed above a release line (20% features that give 80% benefit), while other items are captured below the line. This technique breaks the tension usually experienced because thoughts by team members at random times are acknowledged and captured but they are placed below the line so that they don’t distract from what is important.

Tjaard’s challenge to all of us is the following:

How is it that your team is obtaining certainty?
… and START there!

Conclusion

There was definitely a lot more covered in the conference that I have not captured above. I intend on completing my notes over the next few days.

Create a free website or blog at WordPress.com.

Up ↑