Wednesday, July 16, 2008

DVD Extras

As part of combating the summer blog doldrums, I am considering a theme of DVD Extras for CodeToJoy.

No, there is no CtJ DVD. Essentially, this is an analogy for outtake photos and other silly posts that were left on the cutting room floor. The tension is that the quality of these posts, by definition, would not measure not up to the usual high standard.

The hope is that the banner of "DVD Extra" would mitigate the "outtake quality" of the posts.

Leave a comment or drop me a line if that sounds interesting...

Code Reviews

Many have noted that it has been quiet here at CtJ HQ. This has been due to vacation, summer activities, and partly the giant vacuum left behind by Twitter (I have resisted the autonomous collective so far). Bloggers tend to play off each other, but the wealth of ideas have been reduced to traikus (an attempt to use the haiku form to communicate, a la "nice try") and other short status updates.

Someone must keep the home fires burning, and so your humble host writes from his quiet perch, while the twittering masses party in the streets below.

This article is a good conversation piece: it lists some elements of code reviews. I could leave a comment, but in the classic tradition, I'll blog mine here.

Prime Directive

I work in open war-room that ranges from 4 to 8 people. The benefits of a war-room are outside the scope of this post, but it may shed light on this element.

The prime directive of an effective code review is to examine the code with an eye to the team philosophy, both from a domain and technical standpoint.

Let's consider technical philosophy first: a team should have a solid, unified view on a variety of issues. Are unit tests required? Do we test getters and setters? How do we handle exceptions? Where do we place inner classes in a file? And so on. (Note that this presumes that the team has read the classics (Effective Java, etc) and that the issues therein are 'settled'.)

The key is to maintain consistency. If there is no consistency or stated philosophy from the tech lead, it should be discussed. But once it has been decided, it should not be debated. All too often, a code review can re-open a debate, but for efficiency, avoid this (unless something isn't working out). IMO, the philosophy should not be written down (the code is the example).

Establishing consistency is a major benefit in a war-room. If a team is still "partying like it's 1999" in cubes, then the stand-up meeting can help here.

The domain philosophy is similar. Questions include: if we upgrade from a previous version, and have 2 Foo objects with the same id, what happens? Should a user be allowed to delete a Foo when it is still linked to a Bar?

Code Coverage

As a reviewer, it is natural to ask if the person wrote unit tests. A good follow-up is to ask them about code coverage. The coverage should meet the level established by the team philosophy. Ditto for code complexity metrics.

Internationalization

Beware of hard-coded strings. Reviewers should always be aware of the context where strings are used, and understand which contexts require locale bundles.

Concurrency

Ask the developer if the code is thread-safe, or if it runs in a multi-threaded section of the code. There is a high probability that s/he will look up at the ceiling involuntarily (that's where all the answers are), and pause for a moment. Hijinx ensues.

Versioning

Universities do not have classes called "Versioning 401" and yet it is one of the biggest challenges we face. With respect to data, the team should be aware of versioning issues. e.g. The lifecycle of data across releases, the migration algorithm, and so on.

This is a giant trap for new persistent objects because often the ramifications are not seen for a long time.

The Upshot

Team philosophy and consistency is important, and there is no better place to see it in action than code reviews. Well, there is one better place: pair-programming. But that's another post.

Tuesday, June 24, 2008

Willy Wonka and the iPod Factory

Even the letters-to-the-editor in Wired are better than most articles in other magazines.

Monica Kerschner posted a comment here, which was printed in the July 2008 issue.

Quoteth Monica K, on the topic of Steve Jobs:

" I'm reminded of another CEO [snip]. This gentleman was equally perfectionistic, shrouded his company in secrecy, and was so rude to customers that he allowed one to be turned into a blueberry. Yet he created one of the most popular and profitable products in the world. This other CEO is fictional, but that's about the only difference between the crazes over Willie Wonka's chocolates and Apple's iPod. " (full quote here)

Brilliant. Love it.

Monday, June 23, 2008

The Forgotten Argument for Closures in Java

Background

This article is an excellent summary of the various closures proposals for Java 7+.

However, in the opening paragraphs, it implies that the case for closures are:

(a) a closure is a classic, useful programming construct

(b) the cool languages have them and enjoy increased expressive power

This is all well and good.

But Wait

However, there is another argument, as espoused by Neal Gafter (and reported by Alex Miller). Essentially, it is as follows:

  • Multicores are coming (the free-lunch is over).
  • Brian Goetz is cooking up a new fork-join library for concurrency (JSR 166).
  • BGGA closures simplify the API for JSR 166 (as evidenced by a prototype).
This argument can be debated in two ways:

(a) do we still want closures, even with this info?
(b) which closure proposal is the best for this simplification?

With respect to (b), it may well be true that the other proposals also simplify the API.

Either way, this is a major motivator and thus a central argument.

The Upshot

Don't be fooled by posts that imply that the closures proposals are "keeping up with Scala or C#" or especially "driven by the elite language lawyers" (which drives me crazy).

As Dick Wall has said, we should assume that all of the key players are earnestly trying to do the right thing for Java.

One of those things is simplifying Java's use of multicores. You may still argue against closures, or BGGA, but be sure to include it in your analysis.

ps. One may well ask for a simple, concrete example of the simplification with BGGA. Alas, I don't have one at hand (the JavaDoc is provided here, but it is not a good illustration). Please post a link in the comments if you have worked with the prototype.

Sunday, June 22, 2008

Gant crushes XML in poll

CodeToJoy Newswire
St Louis, Missouri
June 2008

Revelers in St Louis were recently polled on their preference for an all purpose build-tool. The choices consisted of:

  • Gant, a build-tool which fuses Groovy and Ant
  • Traditional build-tools which use XML configuration
In a severe blow to XML, Gant dominated the competition. Pundits around the globe noted that this result reflects the groundswell movement toward Gant and other build tools that provide innate, full-blown language capability.

In this montage, CtJ documents many of the votes cast.





When asked if they believed that Gant will usher in a new era of build libraries, some voters, shown below, answered "Dude!" in a tone that implied the answer was obvious.


Members of a local band, Gumbohead, chimed in with their votes, citing pragmatism: "We appreciate the debate between declarative and imperative languages as much as anyone, but at the end of the day, the build is a cornerstone of every project and we need tools that are simple and powerful."


Throughout the evening, there was little support for XML. Said one woman, "XML is fantastic for data exchange but when you need conditional or iterative logic, things just begin to break down."







In the end, Gant carried the day. Some weary XML supporters left the venue, and held their own party in a goth nightclub in another part of the city. They lit candles and used spoken-word sessions to express their angst at being trapped in a world full of angle brackets.

Monday, June 9, 2008

Domain Specific Error Messages

Background

As defined by Fowler, an internal DSL uses a host language (e.g. Ruby, Groovy) and an external DSL uses a full-blown parser (e.g. ANTLR).

In the latest JNB article, Mark points out that internal DSLs must live within the syntax rules of the host language. This is fine if the audience is composed of software developers, but what if the domain is microbiology?

The following might not be clear:


if( specimen.isBlood && test.isAmpicillin ) {
test.doAlert
}

However, this is debatable: maybe it's ok. Maybe an internal DSL can whittle down its host syntax so that it is reasonable. Debate among yourselves.

The Universal Issue

There is one universal issue for both developers and microbiologists alike: we make typos. We can bend internal DSLs to look good, but what happens when we make a typo? Will the error message be meaningful for a microbiologist? Or would it reveal the host language with a dev-oriented message?

For example:

if( specimen.isBlood && test.isAmpicillin
test.doAlert
}

Now, what if one were to use ANTLR? Can we get a level of error reporting such as:

Could not understand the statement.
Possible cause is mismatched parentheses.
Please type '-help' for a language synopsis.
Please type '-samples' for quick examples.

What if the grammar were even simpler, such the following, but there is a semantic problem:

if specimen.isAmpicillin and test.isBlood
test.doAlert

Could we get a domain-specific error message such as:

Error: 'ampicillin' is not a specimen
Error: 'blood' is not a test
Check appropriate values for 'specimen' and 'test'
with '-values'.

I don't know the answer for either internal or external DSLs. For the latter, I'm going to this month's StL JUG to ask the question. See you there.

Sunday, June 8, 2008

Control-F on a Macbook Pro ?

Generally speaking, I am enjoying the new Macbook Pro. As expected, I am adjusting to the keyboard, not an easy feat considering my enduring love for my ancient, bacteria-laden Microsoft Natural Keyboard Pro.

However, I have noticed that when using vi on the MBPro, that I am at a loss as to how to form the Control F key. For reference, look at the Wireless keyboard at the Apple site (click here).

Right now, I'm using an inelegant, ridiculous gesture: left-thumb on Ctrl and and right-index on F. It is like a novice pianist trying to play a Chopin piece. Or like an Emacs user trying to do, well, anything. (I am convinced Emacs was originally a set of isometric exercises for guitarists and pianists alike.)

How do you type Ctrl F ? It seems like a beast for the left hand. Left-pinky on Ctrl ?