Pages

08 October 2007

Scala to heaven, second step: anatomy of a scala script

This objective of this post is to contrast some java and scala code aimed at accomplishing the same scripting task: cleaning-up my garbage system.

I want to be able to count old items in a database and archive them (through my system API). Of course, if anything goes wrong, I want to be able to restore them.

I'll show what is the approach I took using java then the corresponding scala-way of doing things.

The Java way: connect to the server

First things first: get a server connection. Typically, this is how I do it in java:

DataServerConnection connection = ConnectionUtil.connect("me", "my password", "my environment file");
// I do my stuff here

Of course, when my job is over, I have to close the connection:

connection.disconnect();

But in this situation, and in plenty others like writing to an OutputStream, I may just forget to close your resource. So, here's:

The Scala way: connect to the server

There is, among a gazillion things, a very useful feature in Scala: the possibility to have parameters of a method evaluated lazily. This means that the parameter you pass to a method will be evaluated only when the method body requires it, and not as the method is called, as it is the case in Java.

This way, I can write a better connect method:
def connect(user: String, password: String, env: String, actions: => Any) = {
val connection = ConnectionUtil.connect(user, password, env)
actions
connection.disconnect
}
And use it like that:

connect("me", "my password", "my env. file", actions())

The actions are only performed once the connection is open, and the connection is closed without having to think about it. And for even more readability, I can even use the following syntax:

def connect(user: String, password: String, env: String)(actions: => Any) = {
val connection = ConnectionUtil.connect(user, password, env)
actions
connection.disconnect
}
connect("me", "my password", "my env. file"){
actions
}

Nice Ruby/blocks feel, isn't it? [for a better implementation of this pattern with try/catch and all, please check the Loan Pattern].

The Java way: processing stuff

For this script, the overall process is the same:
  • get some "Market data items" for some "type" and "currency"
  • count/archive/restore the oldest ones
The usual way to do that in Java is to nest some for loops and do the job inside the most inner loop:
for (String type : types) {
for (String currency : currencies(type)) {
for (String name : getMarketDataItemNames(type, currency)) {
final int id = market().getMarketDataItemId(type, currency, name);
doAction(action, type, id);
}
}
}
This buries deep inside the "selection" logic, the "action" logic. One alternative would be to construct first the list of elements to process, then process them. But in my case, this would mean dragging a very big chunk of the database in memory.

The Scala way: processing stuff

Scala offers the possibility to cleanly separate the selection logic from the action logic:

// select items
def items = for (itemType <- market.getMarketDataItemTypes.toStream;
currency <- currencies(itemType);
name <- market.getMarketDataItemNames(itemType, currency);
itemId = getItemId(itemType, currency, name))
yield (itemType, itemId, name)

// archive items
def archive(items: Iterable[Item]) =
for ((itemType, itemId, itemName) <- items)
archive(itemType, itemId, itemName)

archive(items)

The for/yield construct returns ("yields") a list composed of "items" (type, id, name), ready to be processed by the archive function. The interesting thing is that this list doesn't have to be build in memory at once. It is a Stream, i.e. a list whose elements are being fetched as they are needed.

The Java way: aggregating results

The last step in my script is to display the current number of processed elements as well as their total number. I did it very simply with Java:
final int totalProcessed = 0;
for (String type : types) {
for (String currency : currencies(type)) {
for (String name : getMarketDataItemNames(type, currency)) {
final int id = market().getMarketDataItemId(type, currency, name);
System.out.println(action + " item: " + name);
int processed = doAction(action, type, id);
totalProcessed += processed;
System.out.println("Done: " + processed + " Total: " + totalProcessed);
}
}
}

Again, the reporting logic is buried inside the loops, and this may fine indeed for a simple script. In other circumstances, you may want to be able to achieve a bit more independence between the functionalities:

The Scala way: aggregating results

The idea here is to be able to write:

report(count(items))
report(archive(items))
report(restore(items))

With the same report function which will:
  • take a list of Report resulting from each action,
  • print the current Report
  • cumulate the current Report with a running total Report
  • without having to process everything, then do the reporting,...
I will not go in every detail of the exact solution (which is a bit complex to my taste in fact, see below) but here are the principles. First of all, each action yields its result as a Report object, containing the name of the processed item and the result of the processed action:
def archive(items: Iterable[Item]) =
for ((itemType, itemId, itemName) <- items)
yield Report(itemName, archive(itemType, itemId, itemName))


Then, the report function judiciously uses the reduce function to do the sum and report each element:

def report(reports : Iterable[Report]) = {
reports.reduceLeft {(x:Report, y: Report) =>
(x + y).report
}
}

Not so readable for the non-expert eye, right?! Press F1:
  • report iterates over a list of Reports
  • it sums all elements 2 by 2 until we have a final result. List("h", "e", "l", "l", "o").reduceLeft((a: String, b: String) => a + b) would produce: "hello"
  • before returning the summed element, it calls the report function to allow the aggregated report to print itself to the console:

class Report(itemName: String, processed: Int) {
var total: Int = 0
def +(c: Report) = { c.total = total + c.processed; c }
def report = { reportItem; reportTotal; this }
def reportItem = println("Item " + itemName + ": " + processed)
def reportTotal = println("total number: " + total)
}
Conclusion

The sad truth is that my real-world solution is a tad more complex that the one presented above. In the "real-life", I have different types of Reports because each action doesn't bring the same kind of results.

count only returns counted elements, archive and restore return deleted elements + processed elements (to double-check that the action is ok). Abstracting over this and defining a Summable interface to provide addition over both Int and Tuples proved a bit more challenging than using the plain Java solution.

But the good news is that as long as you're not looking for too much abstraction, you will find really neat ways to write common programming logic in Scala.

04 July 2007

Scala to heaven, first step

Now let's start with our first step with Scala.

In the next posts, I'll be certainly assuming that you come to Scala from Java, however everybody is welcome!

I want first to demonstrate the use of a wonderful idea, borrowed from Haskell, the Option class. And this will be used with pattern matching. Said like that, this looks like advanced Computer Science stuff, but it's not.

This will help us manage something that plagues a lot of java applications: the dreaded NullPointerException.

An Option to parse options

Yes, I admit it. Parsing "options" on a command line is not the better way to introduce the "Option" class. So I'll try to go slow enough to reduce the confusion I have introduced in the first place,...

Anyway, this is a "real" example ("real" as "I'm using it", not as "the space shuttle runs with that"). I wrote a small utility in Scala to analyse the options passed on a command line. It can be used that way:

val action = getOptionValue("-action", "generateQuotes", args)


where
  • "-action" is the name of the option on the command line: -action generateQuotes for instance
  • generateQuotes is the default action if no "-action" option has been specified
  • args is an array of string containing all the options passed on the command line (typically through the main static method)
The Java way

How can I implement this getOptionValue method? Let's first provide a parseOption function taking only the name of the option and the arguments (args) as parameters. This function should return the value of the option if such a thing exists on the command line. What could be a Java implementation of that?

public String getOptionValue(String name, String defaultValue, Array[String] args) {
final String option = parseOption(name, args);
if (option == null)
return defaultValue;
else
return option;
}

public String parseOption(String name, Array[String] args) {
for (int i=0; i < args.length - 1; i++)
if (args[i].equalsIgnoreCase(name) && i < args.length - 1 && args[i+1] != null)
return args[i+1];
return null;
}

Please don't stare too much at the for loop, it is very naive but it was as YAGNI as I needed. Let's focus instead on the return value of the parseOption function. This function can either return a String or a null pointer meaning "I have not found an option value corresponding to the name you were asking for".

Unfortunately, if I don't look at the parseOption code, I have no way to tell what the return value when the option is not found. Is it null, is it an empty string? Many times, in real life, this can be pretty much hard to tell, because the value comes from another function which comes from,... and so on.

So in presence of a large codebase, you may eventually add a superflous check:

if (option == null || option.equals("")) return defaultValue;

Better be safe than sorry,...

The Scala way

Now what does Scala offers in that situation?

The Option class provides 2 subclasses:
  • None, which represents "I have found nothing"
  • Some, which represents "I have found something, and you can get it"
The parseOption function in Scala is defined like this:

def parseOption(name:String, args:Array[String]): Option[String] = {
for (i <- List.range(0, args.length - 1))
if (args(i).equalsIgnoreCase(name) && i < args.length -1 && args(i+1) != null)
return Some(args(i+1))
return None
}



And the getOptionValue function is defined with:
def getOptionValue(name:String, defaultValue:String, args:Array[String]): String = {
parseOption(name, args) match {
case None => defaultValue
case Some(value) => value
}
}


which reads like:
  1. parse the option with the name 'name'
  2. if you find nothing, return the defaultValue
  3. if you find some(thing), designated by 'value', return that value
Pattern matching in 3 sentences

In Scala, the "object match {case xxx => ...}" construct implements the "pattern matching" idea. Given an object, if its "structure" matches a given pattern, you can use parts of this object to do your job. In that case, I get an object 'Some', which was constructed from a 'value', so I can de-construct the object and access the value.

The death of the NPE?

I find this in itself quite useful and elegant, but this is not all! What if you forgot to add a None clause to your match construct? You get a compiler warning! So, not only you can infer from the parseOption signature that you will have to deal with None values, but you are even reminded to do so!

Now, if you add the Option class to the fact that Scala encourages you to declare final variables (with the "val" modifier, a bit shorter that "final" in Java) and forces you to assign a value to modifiable ones, you can really think twice when you have to write the word "null" in a Scala program.

And even more to the point

And there are other jewels, too. You can convey this idea of a "defaultValue" in an even more concise way. The Option class has a "getOrElse" method, so the code above can be rewritten as:

def getOptionValue(name:String, defaultValue:String, args:Array[String]) = {
parseOption(name, args).getOrElse(defaultValue)
}


You can also do it the other way around. You can define an action that will be done only if the value exists. The Option class implements Iterable, so you can write:

parseOption(name, args).foreach(Console.println _)

In that example foreach iterates on every value contained in the Option (designated by "_") and print it. So the value is printed only if it exists. Of course, here, I would really prefer a more meaningful term (such as "do") but you know what? There is also a technique that allow you to add methods to scala library classes, so it is possible to write that too! More on that later,...

References

To the interested reader, here are some more references:
  • This is how David Pollak uses options, in the lift web framework, written in Scala
  • The ancestor: Maybe in Haskell (you will also notice the presence of an Either structure which can be very convenient too)

Never ending debate

As a conclusion I will add another layer at the dynamic typing vs static typing debate. One of the goal I follow by using Scala is to experiment when and how static typing is better than dynamic typing. My current observations are:
  • Sometimes it can be irritating to get the types right, and you have to be quite aware about things such as co-variance, contra-variance, dependent types and all the folklore. I will certainly write a post about that to give another "real-life" example, otherwise it can look pretty esoteric. The way I see it is that static typing is a way to encode some business constraints so that they can be checked before you even run the program. Sometimes it is possible and clean, sometimes the translation from your domain constraints to type constraints is a bit clumsy but it works, sometimes it is downright impossible and you need some "programming"
  • There are some things I can do with dynamic typing that I can not do with static typing, such as generating some classes with repetitive attributes and methods, depending on the content of a file. The dynamic solution is very concise and provide "just good enough" objects
Longer post than I thought for a "first step" but I really hope this will give you some drive to try Scala out and then you'll get the virus!

03 July 2007

Scala to heaven, ground

Selecting one "Programming language of the year", yes but which one?

The contenders

I pre-selected several contenders:

1. An ML language, such as OCaml
2. A "purely" functional language such as Haskell
3. A language designed for concurrency such as Erlang

Those 3 languages looked very interesting to me, each of them addressing fundamental software considerations. Well that's the rational pitch. But what was anedoctically exciting?

Observation round

Erlang was the promise to venture in a domain where I feel seriously weak, concurrent programming, with a brand new paradigm, very different from what I know. OCaml was a bit unknown to me, the only references I had were a colleague telling me that he gave up with OCaml one day the type inferencer was as lost as him and a financial company actually using it.

Haskell was perhaps the most appealing, for 2 reasons: QuickCheck (I loved Tom's Moertel description of his participation to IFCP) and the promise of mind-bending ideas baked in the language.

In order to shed more light on the subject I started reading.

"A history of Haskell, being lazy with class", is a wonderful way to introduce the language and give great insights on the "why" more than the "what" and "how". I also read "The little MLer" to become more familiar to the ML kind. And I was waiting for Joe Armstrong's book on Erlang.

But then I noticed something. Yes, that little language, there, hidden behind the others, come here!

I have a winner

What's your name? Scala
What do you know about concurrent programming? I, I have a clever actors library which may help get those performances
What about functional programming? Well, I unify the object and function approaches so you can get best of both worlds
How useful are you? I can play well with your existing java infrastructure
Do you do pattern matching and gadt? Yep
Isn't static typing to tiring? No, you just have to declare the bare minimum. The rest is inferred. By the way, this should allow me to get a top-level IDE with refactoring and code completion soon.
What about some cool stuff I have in Haskell? You mean Options, Parsers/Combinators and QuickCheck? Can do that too.
Are you system-engineering friendly? Some even pretend that dependency injection is part of me
Can you ease XML processing? I have XML literals and pattern matching against xml structures
Can I write DSLs with you? I am not Ruby but I have clever tricks that can help you a lot for that.

And the list goes on. I haven't discovered the least of what can be done with Scala and it is funny to see on the mailing list that even the language designers seems to think that there will be unexpected and surprising uses of scala features in the future.

First steps

The next steps in the "Scala to heaven" series will try to demonstrate the use of day-to-day Scala features to solve my own programming issues. As a beginner, I feel this is missing. We have good examples in the documentation, but abundance of examples won't be bad.

25 June 2007

Scala to heaven, under the surface

Selecting one "Programming language of the year", yes but which one?

At school

First, let's have a look at my abysmal lack of culture on the subject. I think my first programming language must have been Basic. The only mental image I keep from that time is a linear sequence of instructions, with the ability to go back in time or to jump in the "future" to do something else.

Then I played with the Turtle a bit (Logo), I was much more comfortable with recursion, the way function reuse was presented to me and the interactivity with the environment.

At the Engineering school

But they told me that I should structure my programs, encapsulate, and there came Pascal and (later) ADA. In the meantime, I was shown enough Scheme to understand that recursion must be a fundamental thing, at least to return change in a vending machine.

My first internship

C++ and object-orientation sparked a bit more my interest in programming languages, as I first worked on a library for algorithmic geometry. Now I have "objects" I can manipulate, turn up and down, shuffle around. My language eventually supported a wonderful abstraction. "Hello, Mr Object, I am also an object, how can I help you?".

Most of my professional life

Java was a natural move from C++. No more nasty memory bugs, pointers and de-reference. Yes, that kind of profound analysis,... But to my credit, I was more interested by finding efficient ways to understand business concepts and map them properly to a programming language than by the language itself.

The last 2 years

On the road to languages zen, I had several "enlightments". First, the Pragmatic Programmers book gave me an advice: learn a new language each year. Well yes, nice advice, but I have JAVA, the quintessential power of a modern object-language at the tip of my fingers. Why in hell would I be interested in something else?

But damn, it was a conspiracy. Paul Graham, chanting the virtues of Lisp, Steve Yegge executing the nouns (what! my favourite thinking tool?!), even my favourite platform was growing new groovy languages.

Cool! Good place to start. I happened to imagine that, for the product we developed at the time, programing was required here and there to help users describe exactly what they wanted. So I embedded Groovy in our application and started appreciate some nice features:

myList.join(", ") or myList.each { x -> doStuffWith(x) }

Wow, this makes a difference. I can express my mind much more precisely than before! Projecting my ideas on a editor is much more straightforward.

Yes, but can we do better?

Let's go: "Programming with Ruby". Seems cool, Ruby has inspired Groovy (blocks, some of it early syntax), it's recommended by the gurus and there's even this thing, making a lot of noise, there, Rails. Not a bad idea, java for webapps is such a stack.

Of course, I appreciated that I was able to build my first useless website with just a few lines of code and an editor (not to mention my further use of Camping). But I was really blown away by Ruby. So many features that can really make your life easier and say more with less.

One month ago

Time to move on, now I know I don't know. Even if I appreciate that Ruby can "steal" features from other languages, I want something new and useful this year.

Let's go hunting for the language of the year!

11 June 2007

Less is more, slow is fast (expensive is cheap?)

Dear Joel,...

Here's a letter I just received from Joel Spolsky's company, FogCreek Software. One year and a half later, they've sent me, for the second time, a DVD I had ordered. Good customer service, you would say: my first package was lost in the wild so they graciously sent me another one. But I really didn't expect that they would resend me the initial DVD that was miraculously returned to them after more than a year! Is that exceptional service or what?

Why did they do that? I was already pretty much satisfied the first time when they quickly sent me another DVD after the first one was lost (I've even heard about some companies doing that on purpose, just to show how good their support was afterwards). But what could they gain by over-satisfying me? Well, I assume, they just didn't miss that wonderful opportunity to show me how much they actually care about me. Not that I felt so miserable and alone on earth, but I was really touched by the attention. Now I really can say that this company has something special.

Ok, ok. How can they afford that? How can they sustain a double-digit growth each year by wasting so much time? Well, they simply don't ("Fog Creek is focused on growing slowly and carefully and staying profitable"). However if they pay so much attention to each of their customer, which I think they do, they are certainly here to stay.

Less is more

There is some kind of "less is more" pattern here. Less market growth, conquest, expansion,... but also more satisfied customers, upgraded installations, license extensions (anyway, Joel thinks that it takes ten years). And guess what, I think that the people working at the customer service are happier too. They certainly prefer 1000 times receive congratulations than coping with angry clients.

In a sense, this is also a "political" decision. Deliberately choosing to do less but to do better shows how you care for others: your customers, your co-workers. It is some kind of "idealist" choice. But is it also a "pragmatic" choice? Is it also a good economic choice for your company, especially for a software company (yes, I don't speculate often about fashion,...)?

Just wondering

Unfortunately, I don't have an answer with elaborate studies. But I am wondering,...

1. Are there times when you should choose "speed" against "quality"?

From the moment you select a feature to implement in your next release what do you get from delivering it faster but buggy? One more customer, of course! The one who is craving for this new feature. The one who's considering that not having it is a deal-breaker, the one,... who will be so mad to discover that it doesn't work!

[Unless he's just a golf player, he's a close buddy of the CEO, and he doesn't care so much as long as your software is buzzword-compliant. But this is another discussion]

Even when prototyping a new idea, we should be careful with "speed", because the frontier between "rapid prototyping" and "semi-chaos" is pretty thin (not to talk about the frontier between "prototype done" and "let's call it 1.0"?)

2. Is it so expensive to focus on the user-interface?

Yes, this can be pretty expensive. You may have to hire a usability engineer for the sole purpose. And I say that because I know what's the big gap between the half-baked interfaces I will ever produce and the interfaces that are carefully crafted by professionals. But this is not only for the beauty of the game. How many hours are going to be lost by: your helpdesk, your consultants, your newly-hired engineers, your partners? Oh, yes, and your customers,...

3. Why not set-up an "aggressive plan"?

This one really makes me wonder,... I guess that for any project, if you could start it over a thousand times, you may discover the most efficient way to order and parallelize activities so that the least amount of time is lost. But you can't do better, can you?

What are the variables you can play with when starting a project?

1. deadlines
2. quantity of people
3. motivation
4. quality of people
5. customer expectations

So far, an "aggressive plan":

1. fixes deadlines using ballpark estimates of the project estimates and insists that the target can't be missed. Time lines being then the only success criteria, this usually compromises any chance of success before the project even begun.

2. throws in between a moderate amount of people ("we can do it") and a big crowd ("we'll do the maximum")

There are strong suspicions that throwing more people on a project can only make it worse (Brooke's law and this study). Anyway, I am not sure there's much "aggressiveness" to have here. The "right" number of people will do. The good question is not: "is it aggressive enough?" whatever it means, but "are we properly staffed for this?"

3. motivates highly everybody

By either: insisting on the "heroic" aspect of the venture or reminding that "aggressive" concerns each one personally,...

4. tries to gather talented individuals,..

As far as 2 or 3 weeks allow it (because the preparation phase was also "aggressive")

5. decides bravely to deliver only one single feature.

No, just kidding!

Quality, ergonomic user-interfaces, sustainable project pace and even slack, why not go slow?

"less is slow, slow is fast, fast is more" (or the other way around ;-) )

One place where it makes the most sense in certainly when coding:
  • slow is fast: you worked hard to produce less, but you get more value because code is a liability, and less allow you to move things around faster
  • fast is more: there is a tipping point when you can add much more ideas to your software because you just play with the right legos
Why does it sound so paradoxical? A is ContraryOf(A). I believe strongly this is a matter of perceptions.

Perceptions

Try this at home. As an experiment:
  • crank out code (I mean "crank" if you don't religiously follow the red-green-refactor mantra)
  • take time to refactor it
  • add some meaningful comments (the why, not the how)
  • add some user doc (it can be a document or a few comments in a header)
  • take note of the additional time taken
  • forget all that for a few months (2 will usually do)
  • try to estimate how much time was saved -just for you- when you read that code again
Seems simple and obvious, so why don't we do that all the time? Because we're so focused on the here and now that we don't perceive the poor chap that will read the code in 2 months. He's not here now, to cry in anger [This is why pair programming helps. He's sitting next to you,...]

Same idea, different context: why don't we do TDD all the time? Because we don't perceive the difficulty of what we're doing. If you'd realize that each line of code can bear many different and subtle bugs, you would just want to secure it before coding the rest. [And there are plenty of other benefices too].

I am ashamed to confess this, but 2 days ago I wrote a simple "Table" class, taking a list of n row names, a list of m column names and an array of n x m values. I had to create a method that returned the value for a given row name and column name. Can you do it with you eyes closed? Good for you. I was inspired enough to write a few specs before using the class,...

Those are 2 examples showing that we should be careful with our perceptions and ask ourselves:
  • Can we really "not afford" to refactor?
  • Can we really "not afford" to give more time to a project?
  • Can we really "not afford" to hire a usability engineer?
  • Can we really "not afford" to look for better tools and practices?
My theory is that the reality of what we do is so complex that we can be easily fooled by our perceptions [Or we choose to see things this way!]

Higher-order ideas

In my next post, I'll go slow again. I'll have a look at a language I just started learning. Yes, there's going to be a substantial learning curve, desperate evenings just trying to understand why this f*****g line doesn't work. But I am pretty sure this will pay off, allowing me to get more with less, to go fast because I was slow.

I've chosen Scala as my "Programming language of the year". Scala is not even in the 50 most popular programming languages, but I think it really embodies higher-order ideas, ideas that let you express other ideas with less words, doing more with less.

Stay tuned for the "Scala to Heaven"!

06 May 2007

Net pearls

Reading tons and tons of internet stuff, I often find some posts or some documents I find interesting or funny: some net pearls.

As usual I would like to share this with the rest of the world and present those collected pearls as a post.

Pearl n. 1

This historical document by Dr. Winston Royce presents the waterfall model. The interesting sentence in this document is:
I believe in this concept, but the implementation described above is risky and invites failure.
This line must not have been quoted very often by waterfall proponents,...

Pearl n. 2

The next pearl comes from a study of the productivity of several languages. This story is interesting because it compares the use of different types of languages, static or dynamic, through different axes: productivity, length, memory consumption, speed,... Whatever my love for programming languages, the pearl is in the following conclusion:
Interpersonal variability, that is the capability and
behavior differences between programmers using the
same language, tends to account for more differences
between programs than a change of the programming
language.
Pearl n. 3

This one is both funny and interesting (read the whole thread): do we need a "might-equal" operator?
How about adding a "might-equal" operator?  I recommend useng
the characters "=?". I hav implemented my hone programming
language, incubating the might-equal operater. It works
somthing like this:

if (x =? y)
print ("x might equal y");
else
print ("x might not equal y");

Acording to my studys, the might-eqqul operatir is 299834%
more useful than the standerd ekwal operator. For
testing porposes, I have usd the mighty-kwal operatyr
in severul custom sofware packages, including spell
chex and statistics soffy-soff. I hope that you ull can
make yous of it in yore own pergroomink lunkishes.

Pearl n. 4

This presentation from Michael Feathers introduces some coaching patterns and suggests visualizing the group as an individual, "Pat", even if one-on-one action is the privileged interaction medium:
‘Pat’ does not embody an organizational goals, ‘Pat’ is an amalgam of the team
Pearl n. 5

A little bit of history here. Here's a snapshot of notes taken during the meeting that led to the Agile Manifesto.

Pearl n. 6

Acceptance tests is one area that is still not very well covered by software vendors, despite their great usefullness (in terms of executable specifications). This may not be true anymore with Greenpepper software.

Pearl n. 7

Do you like programming quizzes? Here's a nice puzzle from John McCarthy (Lisp's inventor), solved with Haskell:

We pick two numbers a and b, so that a>=b and both
numbers are within the range [2,99]. We give Mr.P
the product a*b and give Mr.S the sum a+b. The
following dialog takes place:

Mr.P: I don't know the numbers
Mr.S: I knew you didn't know. I don't know either.
Mr.P: Now I know the numbers
Mr.S: Now I know them too

Can we find the numbers a and b?
This puzzle is solved by encoding the facts in a few statements.

Pearl n. 8

You can still do funny stuff with Java! Check this out and turn the page.

Pearl n. 9

What's hot, what are the next technologies you should keep an eye on? This conference program proposes some answers:
  • Services (SOA, web services, composition, mashup)
  • Web frameworks (Rails, Tapestry) and Ajax
  • Application frameworks (Spring, OSGi)
  • Build systems (Maven) and automation
  • AOP
  • Open-source (use, participation)
  • Collaborative, open webapps (Web 2.0)
Pearl n. 10

I like concrete examples when it comes to describe concurrencies issues, the next big question in our industry (not in the previous list, which also shows that is it far from complete). But fortunately, humans do distributed computing!

Bob. Alice calls Bob: "Could you get me those numbers?"

Bob jots Alice's request on his to-do list. "Sure thing, Alice, I promise I'll get them for you after I solve this engineering problem."

Bob has handed Alice a promise for the answer. He has not handed her the answer. But neither Bob nor Alice sits on their hands, blocked, waiting for the resolution.

Rather, Bob continues to work his current problem. And Alice goes to Carol, the CFO: "Carol, when Bob gets those numbers, plug 'em into the spreadsheet and give me the new budget,okay?"

Carol: "No problem." Carol writes Alice's request on her own to-do list, but does not put it either first or last in the list. Rather, she puts it in the conditional part of the list, to be done when the condition is met--in this case, when Bob fulfills his promise.

Conceptually, Alice has handed to Carol a copy of Bob's promise for numbers, and Carol has handed to Alice a promise for a new integrated spreadsheet. Once again, no one waits around, blocked. Carol ambles down the hall for a contract negotiation, Alice goes back to preparing for the IPO.

When Bob finishes his calculations, he signals that his promise has been fulfilled; when Carol receives the signal, she uses Bob's fulfilled promise to fulfill her own promise; when Carol fulfills her promise, Alice gets her spreadsheet. A sophisticated distributed computation has been completed so simply that no one realizes an advanced degree in computer science should have been required.


Conclusion


Here we are. I didn't mean at all to reach 10 pearls exactly but this came to be precisely the number of pearls I wanted to share. This must be a proof of the profound wisdom they embody.

See you for Net pearls 2! (Sooooo handy when I have nothing to say ;-) )

11 April 2007

Pattern matching with Ruby

How do you know you got it all in your toolbox? Short answer: you never have it all. Long answer: you may add more, a lot more,...

I was reading one of Steve Yegge's old posts lately: "Choosing languages". This article introduced me to the pattern matching capabilities of a language such as Haskell. Wow,... Yes we can't do that in Ruby. But can't we really?

Indeed, this triggered my memory like a mantra: "if it's not nailed down, steal it... if it's not nailed down, steal it,..." Here's the article: If it's not nailed down, steal it. The author presents a "theft" in Ruby: the implementation of pattern matching.

So using the 'multi' gem, you are able to express the Fibonacci function as:
multi (:fib, 0) { 1 }
multi (:fib, 1) { 1 }
multi (:fib, Integer) { |n| fib(n-1) + fib(n-2) }
This may not be very impressive here, but later on in Steve's article, Steve tells us that pattern matching can really be a huge win when dealing with complex structured data. Here's an example from a contest in the Amazon's developer journal.

=============================================================
bad [[_,fs],[_,ds],[_,cs],[_,gs]] = (cs /= fs) && (cs == ds || cs == gs)

Here, the bad function gets a list as its argument. But instead of naming the list, it specifies a pattern that it expects the list to match: a list of 2-item sublists. It ignores the first element of each sublist, and assigns the second element to fs (farmer side), ds (dog side), etc. The variables then become available for use in the body of the function, after the "=" sign, where we check if if the chicken's alone with the dog or the grain.

=============================================================

For sure, writing the same thing in Java, or even in plain Ruby would be a pain. So I rolled up my sleeves and tried to enhance the 'multi' gem with the ability to use Arrays and variables in Arrays. So I allowed to write things such as:
multi(:foo, [String, Integer]) {|x, y| x; y}
multi(:foo, [:p1, :p2]) { |symbols| symbols[:p1]; symbols[:p2]}
multi(:foo, [:p1, [Integer, :p3]]) { |symbols, x| symbols[:p1]; symbols[:p3]; x}
multi(:foo, [:p1, [:_, :p2]]) { |symbols| symbols[:p1]; symbols[:p2]}
I also added some support for a 'multi' block, which is closer to a Haskell definition (though the 'let' name will be certainly shock a lisper,...):
multi(:foo) do
let(String) {|x| x.should eql "hello"}
let(String, String) {|x, y| x.should eql "hello"; y.should eql "world"}
end
My conclusion on that little experiment was:
  • The use of a "symbols" map is a bit awkward, even if it uses the symbols declared in the pattern. It looks like a trick compared to a Haskell definition
  • It is possible to reproduce Steve's examples in an easy way (I didn't say efficient!)
  • The limitations mentioned in the article regarding the use of 'multi' methods in classes still hold: they are not inherited. 'multi' is not the 'def' keyword
What I am really interested in is: will I use it? Steve says that once you've tasted Pattern matching, you start seeing it everywhere (design patterns, anyone?). I still don't see it in my daily java programming, nor in my nightly ruby programming.

Now, let's say I start seeing it ("Yes, I got it! I am in the Matrix!!"). Should I use it in my ruby code? And should I use the rest? Let's see:
Is it still Ruby? Will other people still understand what I write?

Hey, why not? I am truly amazed by the Ruby's capacities to be benefit from ideas from other languages or paradigms. Indeed, I think it still feels quite Ruby-like with functions and blocks, and those features allow me to write more concise code, at the right abstraction level.

However, capturing an animal and putting him in a zoo is not the same as watching him in its environment. Haskell, Lisp, Erlang and others are quite unique and they each provide different ways to blow your mind.

By the way, is it possible to do concurrency programming "a la" Erlang in Ruby? The challenge is opened,...



15 March 2007

StrengthFinder: discover your talents, turn them into strengths!

I was the great show opener with my Spiderman costume

When I was 10 years old, my class was organizing a small theater play, based on the novel "Colombine" which is a variation on the famous characters from the Comedia del' Arte.

I have always been fascinated by stage action but this time, this was special. Catherine, my secret-beloved-classmate was playing the role of Colombine and she was the most beautiful girl ever in her white dress.

The other central character of this comedy was Arlequin, a joyful, carefree, colorful character. Arlequin entertains Colombine, charming her with his tricks and pleasant stories. I would have loved to play this role, the role of my life for sure, but it had been given to Gilles,... my best friend.

Well, I had accepted my fate, especially since Gilles was 1. a very good Arlequin, 2. my best friend. Until the day Gilles was ill at home,...

He can't rehearse the role! "Pleaaaaaase, let me do it!!!!". Yes! Here I go, ready to seduce Catherine with all my acting talents. Helas, after a few tries, everybody sees that I am not at all the same little extravagant boy than Gilles and that my performance is, how would I say? Well, average,...

Realizing on stage that I will never be able to seduce Colombine/Catherine by being her beloved Arlequin, I burst into tears.

Then, my teacher has the kind of idea that makes a great teacher. She acknowledges that I love being on stage, that I am a serious boy, engaging to other people and that I prefer intimacy to extravagance. So she just decides to create the perfect role for me, building on my talents. I'll be presenting the play!

So, on the big night, I sat under the lights, opening the "Colombine" book, reading an introduction that created the warm feeling of entering a formidable romantic story. Even if having a Spiderman costume, the only one left, must have left some parents wondering,...

Do your best or do -your- best?

This teacher had the great instinct to let me do something I was good at and that motivated me a lot, creatively finding a way to use my talents. She turned something which could have been a traumatic experience into a success story.

This story is like the piece of a puzzle for me. Last year, I made the semi-conscious decision that I should definitely do what I was good at. Why would I try to be a good project manager, a salesperson, a coach, an entrepreneur, a PR, a professional services leader, a top-executive if I can't give -my- best at it. Not my best efforts, but my own best, the things which make me very different from anybody else. Deciding this is both relieving and very energizing. This is the second piece of the puzzle.

Rely on other's strengths, they love that!

I also remember 2 years ago how I realized that I was much more successful when letting others use their own specific talents without trying to do all by myself. Severine is good at organizing meetings, she can do it! Rely on other's talents when you lack some. They will even be grateful that you let them do what they love and what they're successful at!

No wonder why I am always asking candidates what they like to do,... This is the third piece of the puzzle.

The online test

Then, starting a new job this year, I met my project manager, freshly arrived in the company, too. I was very impressed by the way he had been handling things and connecting to people from day 1. Having read "Behind closed doors: the secrets of great managers" last year, I thought: "He's really acting by the book!" (Kaz, you are allowed to blush if you read this blog,...).

Kaz told me about an idea I had discovered last year, when working with an external HR cabinet in my previous company: improve people's strengths, not their weaknesses. This idea was really appealing but also very perturbing (more on that further down).

So Kaz wants people in his team to pass a "StrengthFinder" test. This test is provided by the Gallup institute and aims at finding the 5 top strengths amongst 34 possible strengths.

I passed the test and the first thing I noticed having read the results was: "Hey, that's the first test I cannot feel bad about!". The test is telling me: here, here,... and here, you're really great!

And what about the rest? Is there something I should improve, work on, be wary of? NO, forget it. Use all your energy maximizing your own existing talents. Not the ones you may possibly acquire on the edge of exhaustion.

This makes hell of a difference, creating a nice little psychological "click" in your head,...

Me, you, our team

I don't want to paraphrase the book, it says a lot more that I do on the subject but here are some personal and team consequences:

  • It is more than ok to rely on others strengths. This has many positive side effects: work is done ok, people love doing that, you are relieved of what you don't like
  • Ÿ It is very important to think about your team in terms of provided strengths because this is your only building material for your project. You're not going to build on their weaknesses!
  • Ÿ You can also think about the strengths you're looking for when recruiting, to complement those of your team
  • Ÿ There's no better way to set yearly objectives: people have more chances to be successful, they will bring more value to the company, they will enjoy doing their job
  • Ÿ "StrengthsFinder" is in fact more like "TalentsFinder". Now I know what are my talents, I still need to grow them to turn them into real strengths. Even Mozart had to practice violin,...

Now, this little "click" is so important that I need to talk about the thoughts that can sabotage it.

Preserve the "click"

It is very interesting to start thinking about why we can hear some kind of big warning when thinking about this "strengths-only" approach. Very nice, but,... :

1. Your defaults can ruin your life/project if you forget about them

2. You can always improve

3. You should always improve (it's a matter of will)

4. Life cannot be a bed of roses where you just do what you like

5. Why would I forget about trying to be a great Commander?

Let's take these points one by one:

1. Well, you don't have to totally forget about them! You can for instance use personal strategies to mitigate most of the side-effects. You're very creative but incapable to think about paying your bills? Add an Outlook recurrent meeting to your calendar, buy a Palm pilot, arrange an automatic transfer, put a sticker on your fridge,... Whatever. Just do the little thing that will prevent disasters. Don't try to turn into a "Logistic man/woman". But wait do better than that: find someone that will be delighted to do that for you! (Is that what marriage is all about ;-) ?)

2. Yes, you -may- improve, but is it worth the energy and, most of the time, the unpleasant feeling worth it? Why don't you use this energy to be even better and successfull in what you're already great at? You prefer to hear: "s/he's incomparable" or "s/he's trying hard"?

3. This is more like a moral argument whose psychological roots I leave to the reader to find out,...

4. Why not? By carefully selecting who you work with, you may just find in others the strengths that makes your life great. Chasing receipts and checking amounts to the cent is not considered to be anyone's preferred activity. Yet, I've met people just loving to do that!
5.
I like this one,... Well, because you can't have your cake and eat it. By focusing on your strengths, you're great but you give up being a super-heros capable of anything. I will never be Arlequin but I can be a super-presenter,...

My top 5

To finish with, here are my Top 5 strengths:

  • RELATOR
  • STRATEGIC
  • IDEATION
  • LEARNER
  • ACHIEVER

From what I know, this is pretty accurate and provides a solid starting point for improvement.

Now, why don't you take the test and drop me a line about how it feel passing it!

Disclaimer: To do the test, you have to buy the book. I have no interests in Gallup and there must be numerous other resources with the same approach, I am only interested in -your- little "click",...

Is Project Manager the highest lifeform?

Back after a looonnng time

I haven't kept the sacred "blog at least once a month" pace since last December because of my move to Tokyo (And I still don't have internet at home, arghh). However, here's my comeback
with a classical post about the developer vs project manager divide. I decided that an interview would be a better form of post than a long monolog and I really enjoyed doing it (beside I don't have to be the one to be smart!). You can find many more posts on the subject, including this recent one that had lots of comments, even if it's more on the lines of "everything sucks".

But I have more posts coming up:
  • StrengthFinder 2.0
  • Pattern matching with Ruby
  • Net pearls
So stay tuned!

An interview for a change


I have had comments by Teki on my "Interesting software vs plumbing" post. Those comments brought us to the subject of programmer's evolution: starting from being a self-satisfied geek, why would you become a project manager?

Wanting to write a few lines on the subject, I preferred to go for an interview with one of the best software professionals I've came in touch with, my friend Olivier. [some of my comment are in brackets]

me> Olivier, it is sometimes said that a programmer should evolve to a manager position to get a satisfying job in terms of career (recognition, money, autonomy, employment), what do you think about that?

him> I don't agree! A good programmer doesn't necessarily make a good project manager. Becoming a project manager is not the only possible evolution. Technical expertise is also amongst the possibilities. It is true that most of the time, the management positions are the only ones recognized socially and financially. But It doesn't have to be that way. In my previous job, I encouraged the HR department to setup 2 different "ladders" in the company.

By the way, as a recruiter, I have a very, very bad feeling, when a programmer comes to me and says: "Hey, I want to be a project manager in 2 or 3 years". Programmer is a real job, not a transition.

me> Do you think that there could be more than one "expertise ladder"?

him> I don't know, this "ladder" thing is essentially a social and monetary issue. Most people need social recognition and it is often correlated to salary (at least in France).

me> Is it possible to be a good programmer as well as a good project manager?

him> I hope so! [me> Olivier is both ;-)]

me> Is it seldom to be good at both? Can it be learned?

him> I think it can be learned. The real difference between Mr. Universe and me is not the amount of muscle, but essentially the time spent training. Training sufficiently may not make me Mr. Universe but it may still build lots of muscles. The only question is: will I enjoy the training, am I willing to do all necessary efforts?

me> Is it possible to be a good manager without having been/being a programmer?

him> Yes, I think so. I've worked with a very good project manager, who was not a programmer at all. However, he had a real respect for my expertise and trusted my judgement. Respect is a key point in our field. It is also true for programmers who are sometimes capable of utter pretention: try a newbie message on the linux.fr mailing list for instance,...
[me> I sometimes wonder if it is possible to really have a deep understanding of programmers and software without having being one yourself]

me> Will programmers take over the world :-) and be rewarded as they should? What should they do to achieve this?

him> I don't think that any "world movement" [me> or certification program,...] can achieve that. Local action is prevalent, relentless communication is my only tool. I try to communicate whenever possible: to programmers, QA, directors, sales, consultants. Communication has to be relentless to make people realize the value of programmers.

However, the recognition of the importance of programmers will continue to rise as the upper management realizes their creativity is needed and how much turnover affects the company.

me> Why is programmers perceived added value so low?

him> Their added value? Is it really so low? Yes, perceptions can be very far from reality: some people think that programming is an obscure task, reserved for some kind of mutants. Other ones (sometimes the same but at different moments!), think that programming is easy because they use Word everyday and find it intuitive, easy to use. Or, they have programmed a few Excel macros and feel it is not such a big deal. But how much complexity is hidden behind a good software? It is so hard to make it simple!

Anyway, this is unfortunately the reality for most engineers I know, from mechanical to electricians.

me> Do you think it is a Taylorist / scientist vs agile / lean issue ? What I mean is: do you think that a Taylorist view of software leads to a natural division of Commanders / Executers while an agile view of software makes it more like a collaborative / creative process ? How do you see the future to that respect?

him> Taylorism doesn't apply well to software programming. It is fundamentally a creative activity and an undeterministic process. The V-Cycle was such a big misunderstanding. It has unfortunately spread through most of development standards from administrations to banks. Driving a car is a much better analogy: you constantly have to adjust your direction, your speed and manage obstacles as they occur.

Anyway, I don't think that any agile / lean methodology will drastically change things. Whatever has been said on the subject, there are not enough total project failures. I have not seen one around me in my whole career. [me> Lucky guy, I have seen quite a few, from medium to big].

Still it is so common to expect obligation of results and not obligation of means. Can you write a best-seller in 3 months? Maybe you can write "something" in 3 months, maybe you can write a best-seller in some years, but it takes a genius to write a best-seller in 3 months. How many programming Mozarts can write a brilliant symphony for each project they start?

me> Is there a question that you would have liked to answer ;-) ?

him> The question you ask at the beginning leads us to: what does it take to be a good programmer, a good manager? Is there an universal definition of those 2 roles, or only local ones? Whatever the answer, having the 2 activities being in conflict is always a sign of a big underlying problem: lack of respect,...

06 December 2006

Testing a complex API

We all know the value of testing, and especially the importance of unit testing. However, it is sometimes quite a challenge to properly test some pieces of code.

What about testing classes that access an API that uses complex data structures as input and output?

Testing the Eclipse Modeling Framework

One example of this is the Eclipse Modeling Framework, but I am sure you will find plenty of examples of your own.

This kind of API offers points of entry to modeling data structures such as "PackageRegistry". A PackageRegistry has "getAllPackages" method returning Package objects.

Then, each Package object can be browsed for its content: Class objects, Diagram objects, nested Packages,...

Package, Class, Diagram,... are all interfaces to a complex data structure that can be navigated in order, for instance, to generate code or to create HTML reports. But how do you test this transformation code?

An "out-of-the-box" answer is to use mock objects to create the objects accessed through the API. A fine Mock object framework such as jmock is one of the best for that purpose.

However, setting up the mock structure is:
  1. extremely painful (such as in "extracting-my-teeth-one-by-one")
  2. near to unreadable
Here's what it looks like:

Mock packagesRegistry = mock(PackagesRegistry.class);
List packages = new ArrayList();
packagesRegistry.expects(once()).method("getAllPackages").will(returnValue(packages));

// now create one mock package
Mock package = mock(Package.class);
List classes = new ArrayList();
package.stubs().method("getName").will(returnValue("pack1"));
package.stubs().method("getClasses").will(returnValue(classes));

// and so on,...

This code is so awful that it is almost useless. We need a fresh approach for this kind of unit testing: a mocking DSL!

A mocking DSL

Well, it may be far fetched to call that a DSL, but the idea is to use operation calls to represent the mocks structure and the expected stubs (with real-life code sample):

topPackage = (Package) create(
mock(Package.class),
stub("getFullName", "model"),
stub("getOwnedMembers",
elist(createClassOne())),
stub("getNestedPackages",
elist(create(
mock(Package.class),
stub("getFullName", "model.pack1"),
stub("getOwnedDiagrams", elist(createDiagram())),
stub("getOwnedMembers", elist()),
stub("getNestedPackages",
elist(create(
mock(Package.class),
stub("getFullName", "model.pack1.pack2"),
stub("getNestedPackages", elist())))))))));
I let you imagine the same mock structure with "classical" declarations,...

Even here, this is not a revolutionary improvement:
  1. it is still quite verbose: more complex data structure may not be readable at first glance (but do you need them for unit testing?)
  2. instead of having "create", "stub", "mock" methods, "package", "klass", "method"may be closer to the domain. If you are to test heavily the complex API, I would suggest to do so.
The MockBuilderTestCase class

The "create", "mock" and "stub" operations are offered by a MockBuilderTestCase class subclassing the MockObjectTestCase (see the jmock doc).

This is fairly simple code:
public class MockBuilderTestCase extends MockObjectTestCase {
private Stack mockStack = new Stack();

public Mock mock(Class klass) {
mockStack.push(super.mock(klass));
return currentMock();
}

private Mock currentMock() {return mockStack.peek();}
protected Mock callOnce(String methodName, Object value) {
currentMock().expects(once()).method(methodName).will(returnValue(value));
return currentMock();
}

protected Object create(Mock mock) {
mockStack.pop();
return mock.proxy();
}

protected Object create(Mock mock, Mock...) {
return create(mock);
}

protected Mock stub(String methodName, Object value) {
currentMock().stubs().method(methodName).will(returnValue(value));
return currentMock();
}
}

As "mock" operations are encountered when java executes the topmost "create" function, a new mock object is created and pushed on a Stack. Then all subsequent "stub" operations are applied to that mock. Eventually, when the "create" operation has all its arguments evaluated, the mock is ready and can be removed from the stack.

I wish I could turn the "eager/lazy" knob for evaluating arguments in java. I often find that using nested operation calls in java can provide an easy internal DSL, however, having the operation arguments evaluated first is not always practical.

Don't forget the Law of Demeter!

A last tip for an efficient and easy testing of classes that uses a complex API: don't let them access a too deep level in the API hierarchy.

That is, instead of allowing modelBrowser.getOperationNames() be like

List result = new ArrayList();
for (klass: getAllClasses()) {
for (operation: klass.getOperations()) {
result.add(operation.getName);
}
}

aim for delegation to classes dedicated to lower levels:

List result = new ArrayList();
for (klass: getAllClasses()) {
result.addAll(classBrowser.getOperationNames(klass));
}

10 November 2006

Thinking twice about it

We are conducing an interesting exploration project these days.

The product I am working on uses UML models as a primary input. Those models are used for test generation, after setting various coverage criteria on the model elements.

Conceptually, the picture is quite clear: data in, data out. However, the devil is in the details,...

Having the same UML model referenced in 2 different tools leads to pretty complex synchronisation issues between the 2 data repositories:
  • when an operation is removed, you have to remove the corresponding configuration
  • when an operation is added, you have to set some kind of defaults for it
  • when an operation is renamed, well,... you're stucked! You can only treat it as a removal + addition
So working on the third generation of the product, I was challenged pretty hard by the development manager to find anything that would allow us to get rid of those synchronisation mechanisms. I was quite reluctant at first but decided to have a go at it.

Thinking twice about it

I started this exploration and it appears that I may be quite possible:
  • using the UML profile capabilities of the UML tool, it is possible to add more semantics to model elements and let user define properties on them
  • using UML2.0 interactions allow us to represent quite nicely the operations that are targeted for test generation
Yes, this could work. But wait! Look at the pay-offs, we wouldn't hope they were so great:
  • the configuration is always coherent with the model
  • there's not a line of code to edit, visualize or store this configuration
  • you have a natural way to define initial states for test generation and to deal with UML elements
  • this approach is reproducible to other UML modeling tools in the category we're targeting
  • you don't have anymore test generation projects to manage, because all the information is efficiently stored along with the modeling project!
Okay, okay the "No silver bullet" theorem still applies there. There are some obvious drawbacks:
  • we are constrained by the UML tool. The properties that are vital for -us- are displayed by -them-
  • we are, of course, a lot more dependent on the tool bugs (and of course I spotted some, even if I could find turnarounds)
  • there is no easy way to tell the user what to do to configure the test generation. It doesn't come right into his face (that's the biggest drawback to me - a UI is supposed to provide the maximum guidance to the next thing to do)
I don't know where this experiment will lead us but the lesson is nonetheless interesting:

Think about it twice: can you state your software requirements so that the solution is not included in the question?

"We need an application to configure the parameters on the model elements"

Otherwise this may lead to other requirements,...

"Please, synchronize the data for me,..."

10 October 2006

Writing on the walls

We had this wonderful session last week about "writing on the walls". This tutorial was held by Laurent Bossavit (read here for his contribution to the Agile movement).

The purpose of this tutorial was to teach the use of 3 simple agile tools:
  • the tasks board
  • the release board
  • the burn-down chart
As far as pedagogy isinvolved, the tutorial was really great. In 90 minutes, we had planned 4 or 5 iterations, developed 3 (using dices to decrease the points on the cards!) and really experienced what if feels like to communicate the project status on the walls.

The tasks board

I have been practising the tasks board for some time now and already had this kind of revelation: holding the cards, displaying them, ripping them off, replacing them, writing your names (the pair) on it,...

This "physical", "concrete" approach to the work to be done makes it very real. It makes the people focus on something concrete, not on a line in an Excel spreadsheet or in an html page. Hence, when a card is moved from the "TODO" to the "DONE" column, you can see it's finished.

We found a common pattern for the 3 tools, during the tutorial. They deliver information in a very progressive way. The tasks board answers the questions:
  1. "how far are we done?". Glancing at the board gives you the info right away: GOOD -> many cards in the DONE column, BAD -> many cards in the TODO column (unless at the very beginning of the iteration of course,...)
  2. "how much exactly has been done?". Look at the expected/actual velocity
  3. "what has been done? / what remains to do". Reading the cards tells you what the developped features are
By the way, the exercise is a lot less futile when you have acceptance tests corresponding to each card and if they are green when the card is said to be done. But this is another story,...

The release board

This one is fairly simple. You just display the remaining cards of the milestone, sorted along the remaining iterations. In additions to the cards, you add the expected velocity of each iteration (and make it match to what you know you can do!).

The interesting part about the release board is that it tells you a story. It is like a storyboard of what's going to happen in the project. If done properly, you should understand the plot, the tension between the characters, an overall sense of coherence, and... the happy ending, of course!

I also found that this is a very good tool for the client to communicate with the developers. Most of the time, developers are so much engaged into their code that they end up lacking a vision for the overall product. The release board helps them getting the broader picture and to understand the customer priorities.

The burn-down (or burn-up!) chart

This one is the typical tool of the manager and illustrates a very fundamental point about "writing on the walls". On this chart (in a "burn-down" fashion), you display the stock of points to be developed at the beginning of the milestone, and after each iteration, you add a new point on the chart, showing that this stock is decreasing. So you have a more or less declining slope, made of several segments.

Then, by interpolating roughly, you draw a line that crosses the X axis, giving you a bold estimate of the release date for the whole product.

Now, what is a burn-up chart? Well, reality is not very linear. Every once and then new features or weird discoveries pop out, and your stock will be increasing. You can display things the other way around, showing that each iteration adds features and try to reach a "ceiling". Then, you can easily raise the ceiling bar if necessary. You will also be able to get an estimate of how much the ceiling is raised along a typical milestone and use this data for your next planning game (thanks Olivier for convincing me on that point!).

To sum it up, the burn charts give a graphical representation of the velocity of the team for a whole milestone and helps conveying the "are we done yet?" data on a large scale of time.

Oh, by the way, what was the fundamental point?

The fundamental point

The fundamental point is not "cool, everyone sees the project progress".

The fundamental point is "cool, everyone cannot help but see the project progress". Developers are facing their responsabilities of trying to maintain the best velocity (mark this word: maintain,...). And managers have to acknowledge that it takes time to deliver software.

Information is not only displayed but it imposes itself to everybody.

14 September 2006

Interesting software vs Plumbing

What makes interesting software? What makes hard software? What makes fun software?

Customer affinity

It all started with Martin Fowler post: CustomerAffinity. In this blog entry, Martin makes the point that "enterprise software" can be much more than "boring" and "shuffling data around". If you have enough interest for your customer (CustomerLove?), you can be pretty much delighted by finding the best ways to solve his business challenges.

So, as a programmer, even if you should be interested in frameworks (he calls that "plumbing"), you should be even more interested in the business that's supported.

Well, this has been more or less my opinion for years. I love to formalize, structure the fuzzy concepts that business people are toying with.

It is fascinating to see how human creativity can elaborate very complex things from very simple ideas. For instance, Thales is seemingly credited with the idea of buying the option to use olive presses during the next harvest. He bought the right to use something from sometime in the future. Now, play with the words in italics and you will get all the subtle ways to define options.

Is it boring?

Fine, fine, but Ravi Mohan disagrees with force (But Martin, entreprise software IS boring). He advocates that the talentest programmers would rather code a compiler than a loan-disbursing process.

So, "Computer science" and mathematics could be much more interesting than "enterprise software"? Reginald Braithwaite entry about business programming provides some answers.

Not only, getting the concepts right can be interesting (how do you define a "fraud suspicion"?), but this can raise really interesting computing issues. He takes the example of a system for routing concrete trucks: what are the optimal paths if you take the traffic into consideration? What if an accident occurs?

And Reginald raises the bar higher: can you do it in real-time? For thousands of trucks?

So, what's interesting in software? We can get some hints from those blogs:
  • customer business (Martin's interest)
  • mathematical / algorithmic challenges (from Reginald's blog)
  • scalability / performance issues (Reginald again)
  • computer-related stuff : languages, compilers, protocols, graphics-intensive software,... (Ravi )
I would also add one source of interest that is rarely given much interest as such: maintainance. Bleech! bad word, how can it be desirable? Well, when you code and design software day after day, you can also meet pretty tough challenges around maintainance. Is your code readable enough? How is conveyed your design? Can the software be plugged, unplugged gracefully? All these questions sometimes require specific talents that may be not found in the "hardcore programers" set. So, let's add one more point to the list of what makes software interesting:
  • software maintainance 'art'
Fun happens

So far, so good. There's even a good news: you may have to deal with all of these in your next software project! The chances are very thin but software is such a continuity that you may have to implement a software for hospital management:
  • what's the content and life of a medical file?
  • how do you allocate efficiently resources such as rooms, surgery equipment? (what if a big -think 'terrorist'- accident occurs?)
  • how do you do that for thousands of patients, in real time?
  • how do you get x-rays pictures from the equipement to a secured medical file?
  • how do you support a domain-specific language for an expert database?
Anyway, you will be bored somehow

Fun stuff, no doubt. So, what's REALLY boring? I'll tell you. This is what -I- call "plumbing":
  • software compatibility: "oh, version X.Y.Z is needed for this dll!"
  • environment variables: "BLOB_DIR was not set. How was I supposed to know that?!"
  • defining paths, installing stuff: "a new Windows update is there, you should restart your computer"
  • interoperability: "this very useful piece of java code is supposed to communicate with this VB crap,..."
  • fighting with your programming language to express simple ideas: "look! 6 lines of java vs 1 ruby line of code"
  • lousy operating systems: "what?! cmd.exe can not display ansi codes? What year are we?"
  • fiddling with your UI framework to get what you want: "why on earth is this not resized?"
  • and yes: business software that's repeating itself, either in the concepts or in the implementation,...
In the end, I feel it is very important to track the "boring" parts of software. Either make them disappear or become very good at dealing with them efficiently or hire someone to do that for you (why would "boring" be an universal definition?)!

And,... allow yourself to play from time to time.

So relax and enjoy

This is why I appreciate the RubyQuiz. This week's quiz is about a compression algorithm. I had a chance to learn a completly new field for me, without pressure nor any of the 'boring' constraints. I had everything at hand with a ruby interpreter (ok, not entirely true: I installed Radrails,...).

Another grid of evaluation for recruitement

Concluding thought. All those points can be considered when hiring someone:
  • comfortable with concepts?
  • has knowledge of the mathematics, algorithmics involved in programming?
  • knows how to deal with scalability/performance issues (both in software and hardware?)
  • is confident with parsing, ASTs, GUI, disk accesses?
  • can produce maintainable code?
  • can minimize the effects of boring activities? (knows how to install a full production system without spending hours on the web?)
Wow, this looks like a whole program that I can apply to myself! And I didn't even talked about project management and people,...

01 September 2006

Ruby Quizzzzzzz

After 3 weeks of vacations (a wonderful place in Greece), I felt I needed some kind of warm-up,...

So I undertook the idea to answer the week's quiz from the RubyQuiz site every week.

This week quiz was especially fine since it was also simple enough to be used as an introduction to Ruby for our weekly Dojo at work (see here and here).

The subject of the quiz is to have a class that's able to transform days of the week into a human compact format:
  • [1, 4, 6] should be displayed 'Mon, Thu, Sat'
  • ['Monday', 'Tuesday', 'Wednesday', 'Thrusday', 'Sunday'] should be displayed 'Mon-Thu, Sun'
This looks simple but may be tricky to write properly,...

It was very interesting to take a look at the other submissions after coming up with my own solution:
  • I discovered there was a way to use the Date class to get standard day names
  • You can use infernals text manipulation ideas to get the job done (short but unreadable to me)
  • No one used Sets or extended the Range class like I did
  • There were only few submissions creating ranges from an array with successive integers in a readable way (this is were I struggled the most)
  • Not everybody submitted unit tests
  • I was the only one to submit specifications using rspec
  • After writing down my own solution, I just modified it to take advantage from the "inject" method of Enumerable to make my code more concise
Well, I look forward for doing the next quiz, or even best,... submit a quiz myself!