Category Archives: thoughts

Back to Basics – good comments are targeted comments

I can’t think of a single person who enjoys writing comments in code. I don’t, my friends and colleagues don’t, and I’m pretty sure there isn’t a meetup group for fans of it. Outside of code that I write for blog posts, I can pretty much guarantee there are only place where I write comments is in interfaces.

The simple reason for this is that a) interfaces should be explicit, and b) implementations should be self-documenting.

The reason for this blog post is that I’m seeing a lot of code at the moment that falls into one of two traps – either everything is documented, or nothing is documented.

Everything is documented

Spot what’s wrong with this code:

/**
 * The foo class represents blah blah blah...and so on, describing the 
 * class in such detail it's a pity the code couldn't be generated from it
 */
public class Foo {

    /** The name */
    private String name;

   /**
    * Do something with this instance.
    */
   public void doSomething() {
      // Get the name
      String localName = this.getName();

      // munge the local name
      localName.munge();
   }

   /**
    * Get the name.
    * @return the name
    */
   public String getName() {
      // return the name 
      return this.name;
   } 

   /**
    * Set the name.
    * @param name the name
    */
   public void setName(String name) {
      // set the name 
      this.name = name;
   } 
}

Or, to put it another way, spot what’s right with it. That’s a much shorter answer. The code is full of unnecessary comments – e.g. getName() gets the name – and code that seems to have been written just so it could be commented – e.g; String localName – this.getName(); The names have been changed to protect the guilty, but this is real code I’ve seen in a live codebase.

As as I’m concerned, implementations don’t need code-level comments because that’s what the code does anyway.

Nothing is documented

At the other end of the scale is this little gem:

public interface Parser {
    void parse(InputStream is) throws IOException, SQLFeatureNotSupportedException 
}

Interfaces, on the other hand, should have clear documentation that defines what goes in, a generic description of what should happen, and a clear description of what comes out and what exceptions can be thrown. Information at this level should state if, for example, null arguments are allowed, if a null value can be returned, the circumstances in which certain exceptions can be thrown, and so on.

Interfaces should be explicit

Interfaces, to my way of thinking, are contracts, and contracts – as any blood-sucking lawyer can tell you – exist to be honoured. They can’t be honoured if the terms are not explicitly set out.

There are no Burger Kings in Belgium, so if I’m in the UK or the Netherlands I am generally tempted to have one. On my most recent visit, I noticed this at the bottom of the receipt:

Free drink with any adult burger with this receipt Excluding Hamburger, Cheeseburger or King deal or any promotional offers”

Or, to put it another way…

/**
 * Get the free drink promised by the receipt.  This is valid for any burger.
 * @param burger the burger
 * @param receipt the receipt
 * @returns the free drink
 * @throws InvalidBurgerException if the burger doesn't qualify for a free drink
 */
public Drink getFreeDrink(Burger burger,
                          Receipt receipt) throws InvalidBurgerException {
    if (MealType.HAMBURGER == meal.type()
        || MealType.CHEESEBURGER == meal.type()
        || MealType.KING_DEAL == meal.type()
        || meal.isPromo()) {
        throw new InvalidBurgerException();
    }
    return new Drink();
}

To my simple brain, this is confusing and contradictory as hell. Your API should be clear and (as my university teachers beat into me) unambiguous – for example, the words “any” and “except” should not appear in the same sentence. Strive for clarity – if you find your API is too hard to clearly document, there’s a good chance it will be annoying to use. In the case above, an improvement would be something along the lines of

/**
 * Get the free drink promised by the receipt.  Not every burger qualifies for a free drink.
 * @param burger the requested burger.  This may or may not qualify for a free drink
 * @param receipt the receipt containing the offer
 * @returns the free drink. May be null, depending on the burger
 */
public Drink getFreeDrink(Burger burger,
                          Receipt receipt) {
    // implementation
}

Note that I’ve also got rid of the exception as a result of being more explicit.

Conclusion

Annoying as it is, documentation is extremely important in the correct place and completely useless everywhere else. Done correctly, they will make your API easier to use and easier to maintain, which is generally a good thing.

Here endeth the lesson.

Harry Potter and the Personal Lesson

Geek alert.

I love the Harry Potter books. I thought they were well-written and cohesive.  You may have read them too, and felt something similar.  What you may not have done – and you can skip to the end otherwise – is read them back-to-back in a short timespan.

I’ve read all the books multiple times, and every time I’ve picked up something new.  That’s a win, by any reasonable standard.  After book seven came out and I read it, I decided to read all the books in a single extended session.  The results were, frankly, remarkable.  Plot lines and plot points made more sense and there was a complete feeling of a story that required seven books to cover as opposed to seven related books.  The difference, when you’ve experienced it, is significant.

This is the point where I attempt to weave a personal life experience into general software engineering.  Since this was a click event in my life, hopefully I can expand on it thoughtfully in such a way that allows me to cash in on it mercilessly.

A scenario:

Point the first: We have an idea and sketch out functionality and an API

Point the second: We expand that idea, and the API, in accordance with the improvements of point one.

Generally, in my experience, the next bit is where things really go to shit.

Point the third: We add more functionality, refactor the API completely (and rationally, according to the changes) and add things which we think are needed instead of what is wanted.  We put perceived wants in place of planned needs.

And right there, things go wrong.  If you have an idea, then not evolving it is a mistake.  If you have evolved it, then pause a while.  Let it stabilise. Change is good, but if you want to build a following – particularly one which requires a stable API – change must proceed according to what you want to achieve.  Once you’re stabilised and are ready to expand your capabilities again, notify your consumers in ample time and go for it.

If you’re familiar with the the Potter books, you may see a similarity here.  For example, book five got lambasted just because the principle characters were acting as they should have been at the age they were.  Which is ridiculous, because otherwise they wouldn’t have been acting realistically. Just because they’re teenage witches and wizards doesn’t mean they’re not teenagers – they’re just teenagers who are witches and wizards.  Comme çi, comme ça.

The point is, if you’re still reading at this point, is that J. K. Rowling clearly has a view on where she was going, and didn’t fuck up her API.  She wrote according to her plan, and took the criticism as it came.  The result speaks for itself.

If you want to create something, that’s amazing.  If you want it to be useful, you have to listen to your users.  But if you only listen to your users and forget what you wanted to do in the first place, then you’re designing by committee – and that’s guaranteed to give you the worst set of compromises you can imagine.  If you’re going to build something, build it with an eye to making it useful – but keep your vision for it true.

Software people continually try to apply their practices to the general world, but it works both ways.  In this case, not compromising worked for J. K. Rowling, and it’s a damn good lesson.

Shit or get off the pot

I bought my first Playstation 3 about five years ago, and it was great.  I’m not particularly into games, but it was purchased as a media player and it worked perfectly.  Three years later, the dreaded red light of death occurred, and it went into the attic (just in case…).  I was quite impressed that it had a lifetime of three years, given that everything else I bought from Sony generally developed a fault two weeks after the warranty expired.

I mourned its loss – it could play PS1 and PS2 games as well as fulfilling my music and Blu-Ray needs.

But, it’s not like it was the only chance I ever had to buy a Playstation 3.  I bought a new one a couple of months later – only to be seriously, seriously pissed off.  It didn’t play PS1 or PS2 games – black mark number one.  More importantly, it was unable to play Blu-Ray movies without a horrible stutter in the playback.  It took me a few months to take it back – a combination of not enough time and general laziness – but it finally happened about two months ago.  Four weeks ago, I received a replacement PS3 that should have no problem with Blu-Rays.

I call bullshit.

Right now, Harry Potter and the Half-Blood Prince is stuttering its way across the screen.  Sony championed Blu-Ray, yet they seem singularly incapable of producing a machine capable of playing them. I can cope with incompetance when it doesn’t affect me, but when it does it tends to bite a little.  Happily, the good folks at Sony provided a new warranty starting from when I received the new machine.  Unhappily, I’m not sure that returning it to have the problem addressed will have any effect since they have already shown they’re unable to do what they claim to be able to.

I personally wouldn’t sign off any software that I had written or was reviewing that acted as badly as this.  The unbelievably shitty performance means that DVDs (which the PS3 has no problem with) are more watchable on this machine than the hi-def films I bought the machine for in the first place.

Sony – please – shit or get off the Blu-Ray pot.  My patience is running out, and there are a lot of alternatives out there.  Don’t make the mistake of thinking you’re the only player in the market.

PlayBe Dojo – all seats booked, and ready to go

With less than a week to go until the Belgian Play! Framework User Group holds its first coding dojo, all 20 places have now been taken.  I was half-way through a blog post to promote it when person #20 signed up, so instead I’m going to flip this over and quickly look at how having an active event can really drive up interest in your user group.

The far more organised co-founder of the usre group, Ben Verbeken, has written about the upcoming dojo here - http://ostia.be/blog/2012/09/18/playbe-first-dojo/

Here’s a chart showing sign-up activity for the group since we started it a few months ago.  We’ve had a couple of meet-ups in the meantime, and have all come into contact with like-minded others.  So far, so good – but notice the lull in sign-up activity in the middle of the chart.

In the first few days, about 18 people joined – and I think a couple of those were people who join any meetup in their area.  Since we announced the dojo, the group has pretty much doubled in size.  The lesson I’m taking from this?  Developers want to develop - having a drink and a chat is all well and good, and our past meet-ups have been good evenings, but it’s not quite the same as sitting down together and creating something new in a couple of hours.

I think that, in future, coding will be a fixture of the meet-ups.  There’s no better way to discuss development than to actually bang some code out there and then.  Using Play, you already have a head start on creating an app in a few minutes which can then be evolved by the others around you.  So, the dojo will (hopefully) be a great night with a structured plan but there’s no reason why every meet-up shouldn’t be the equivalent of several concurrent dojos.

If you would like to join the Belgian Play! Framework User Group, head over to http://play-be.org – it’s free, and there’s a lot of fun ahead of us.

Abandoned blog posts

I get ideas for blog posts all the time. As you could guess by the number of posts here (currently at 56), the majority are toyed with and then ignored. Here are three that I’ve come up in the last few days, but I couldn’t make anything of them. I figured if I wrote them down, it would help me triage a little better in the future.

#1 Throwing generic exceptions in Java
Abstract: In my current project, I’m using JEE with a classic lasagne architecture. Because validation is occurring at multiple levels, I came up with a mechanism that could throw generic exceptions into a standardised layer.

The core of it was a factory (hey, it’s Java) of

public interface ExceptionFactory
{
    T create(String message);
}

and a usage that basically defines

public static  void someValidationMethod(Map params, ExceptionFactory exceptionFactory) throws T
{
   // ...
}

One of these days, I may get around to writing it up, but the sad truth is that is was a hell of a lot easier to write and use the code than write about it. I don’t want to write something forced, so this got pushed into the fridge.

#2 Robots will probably not kill us all
One of my shameful pleasures is reading the comments made on the website of the UK newspaper The Daily Mail. The majority of the people are…well, I’m not going to go into my opinion of them, but distastefully colourful should pretty much cover it. There was a hilarious comment a few days ago where someone claimed that AIs are very close to eclipsing human intelligence and will soon make everyone on the planet unemployed. Simultaneously, having been accepted into the NAO Developer Program, my next gen NAO has arrived. It’s amazing, but I sleep soundly in the knowledge that it’s not likely to enslave me.

Now I think about it, this abstract pretty much encompasses the entire blog post that would have resulted from it.

#3 Catholic school girls
My five year old daughter attends a catholic school. Both I and my wife are atheists, but the school was highly recommended. Additionally, she started attending in September 2010, just over a month after we all moved to Belgium, and at the time didn’t speak Flemish (it’s since become her first language). The new school year starts tomorrow, and she’s very excited to be going back – and this is fantastic. She’s happy there, has friends there and is learning a lot there. She’s also learning elements of religion (no prizes for guessing which one) which I was initially worried about, but then got over it. I didn’t have a religious upbringing, but my parents were happy to let me find my own way. I attended a local church as a child, but then decided it was a crock of shit and stopped going – my own decision. My niece had a similar upbringing, and decided at age 8 to get baptised – her own decision. My conclusion was that if you shield your children from the experiences other children are having, you’re asking for trouble.

Wrap-up
I think I couldn’t have spun any of these into blog posts that a) would interest me or, b) not sound like a rant, and so I’m glad they never became first-class citizens here. I am, however, glad that I’ve noted them down simply to keep track of what I’m keeping and what I’m discarding.

The value of independence

Three or four months ago, I received an email from an on-line advertising agency inquiring whether I would be interested in allowing in-article ads on my blog. I thought about it for about a second, and immediately answered with a polite rejection. The advertisers replied pretty quickly, pointing out the money I could earn from such ads.

This time, it didn’t even take a second to think about it – my answer was a flat “NO!”.

A couple of days ago, I received another email – this time from a tool vendor that’s preparing to offer free individual licenses for its tools. Would I be interested in writing an article on the tool? Certainly. What’s the difference? This – “I would love to hear your thoughts – both the good and the bad”.

I will happily review your product, your book, etc, but it will be as objective as I can make it. I refuse to hand control of this blog over to anyone, and there will never ever be a paid advert on here. I’ll review things with full disclosure, but I won’t shill for you. I will advance my own interests, but I’ll try to minimize my bias in the process. This is what the independence of my blog means to me.

But, as usual, someone else said it better…

Facebook…hmmm

I just read how Facebook changed all e-mail addresses to use their @facebook.com domain. Now, unless I misread something, I seem to recall my information section is about me, and so it’s not really up to them to change it. I wonder if they’re thinking of changing all birthdays to the same date, and having presents trans-shipped through them so they can shake the boxes first.

Happily, I own the domain that I use for my facebook email address, so I’ve created a new account called fuck-facebook@<my domain>.net, because that seems to sum it up nicely.

Which is to say, fuck facebook.

I’m not concerned about them changing the layout of their site, or introducing timelines – it’s their app, and they can do what they want with it in the free market of social networking. It may be their app but, unfortunately, it’s my data – and right now, I wish I’d never signed up to that damn place.

I would like to say I’m stunned by the unbelievably bad judgement they’ve shown with this move, but let’s face it – it’s not exactly the first time they’ve screwed with or exposed data

I’ve stripped my profile down to bare bones – no movie or music likes, minimum personal information. The next step is to check how much data of mine I can force them to purge (but I’m not holding my breath). Maybe you should think about doing something similar too.

A thought – people change each other’s facebook details often as pranks or as a prelude to fraud. In other words, they change personal details and act abusively. Facebook just happens to have a “Report abuse” section (you can find it here) – maybe you should report this as abuse too.

Update: I never realised how hard facebook made it to report something outside of something they consider to be abuse! Click on the link above, and you’ll find out for yourself. I’m trying to mail them about the following in their community standards:

On Facebook people connect and share using their real identities. This culture creates accountability and builds trust and safety for everyone.

Quick summary – real identities and creates accountability and builds trust. Talk about do what I say, and not what I do!

Presentations – large and loud, or up-close and personal?

In my previous entry, I mentioned that when the projector failed to function, laptops, tablets and smartphones were used to display the slides instead. When I think of conference presentations, I tend to think of something like this:
By Royal Cliff Beach Resort (Royal Cliff Beach Resort) [Public domain], via Wikimedia Commons

The scale of 010DEV was smaller – much smaller – but the format was still a person talking at the front, with a projector displaying the presentation slides. Due to the aforementioned technical issue and solution, what actually happened was a situation where I could focus on the speaker and not be distracted by a shimmering block of light behind them.

Thinking on this further, it occurred to me this was nothing new. The first time I ever saw a film on a airplane, it was on a huge (well…huge-ish) screen at the front of the plane. Fast forward a few years, and TVs started appearing every few meters above the aisles, giving everyone a chance to view whichever edited piece of crap was being shown.

A few years later, and seat-back personal entertainment units (I’m sure the airline industry has a snazzy name for them) turned up. Finally, you could a) control what you watched and b) actually be able to see it without 20 rows of people between you and the screen.

As more and more people now carry their own seat-back personal entertainment units in the form of laptops, tablets and smartphones – especially at technical events – I wonder if the era of the big screen presentation is coming to a close?

How to confuse a Belgian call-center operator

I love my job as a software engineer. I love it so much, in fact, that whenever I have time, I do it for free by working on open-source software and writing about software development on this excuse for a blog.

I am, therefore, highly aware that some people don’t enjoy their jobs. Call centers, for example, which will be the focus for this example.

When I lived in the UK, call centers were a fact of life. Anytime you needed to call your bank, your car insurance, your ISP, whatever, it’s a call center. Anytime you need to call one of those places because there was an issue or they’d screwed up in some way, there would be a call center operative doing their job by taking your call. Ninety-nine times out of a hundred, they would be extremely helpful because that’s the best way to enjoy your job – do it well, and try to get some satisfaction out of it. One time out of a hundred, they would be…um…anywhere on a range of not-so-helpful through to downright rude and obstructive.

Call centers, as far as I can make out, are set up to do three things – field calls, field calls that are complaints, and field complaints against the call center personnel. There is one category that it seems they’re not set up to deal with.

When you call a call center and the call ends, occasionally you’ll have a little touch-tone survey. “Did the operative help you? Press 1 for yes, or 2 for no”. Press 1 or 2, and you’ll get a cheery “Thank you for your feedback”. This is not the way to collect satisfaction data – or, at least, it’s not the way to collect anything other than the coarsest-grained data possible. The survey may as well be tone-sensitive and ask you to fart or belch to indicate your level of satisfaction.

Personally, I make a point of explicitly thanking people when they’ve been helpful. If the calls are recorded (which they invariably are, for “training purposes”), then you would hope it would show up. I also think those tapes are only used for the training purposes of lawyers when the company in question is getting sued. That’s why I also like to speak or contact the operative’s manager to pass on my positive thoughts on their performance.

Fast forward through two years of living in Belgium, and I’m back in call center land. I just signed up with Lampiris as my new utility provider, and there was an issue with my on-line sign-up. I got in touch with the service center and the guy I spoke to – in English, of course, despite the fact I’m living in Belgium – resolved the issue, looked at the root cause of the issue and got me to where I want to be in the sign-up process. I am one happy bunny.

So I ask to speak to his manager, at which point he gets a little bit confused. Now, customer service in Belgium is not what you would call satisfactory – in the majority of cases, you feel like you’ve achieved something when asking customer services anything if they haven’t poured sugar into your fuel tank as a response. Consequently, when you do get not just good but excellent customer service, you feel inordinately happy – maybe this is a country-wide long-term strategy, but I wouldn’t bet on it.

But I digress – I asked to speak to the guy’s manager, and he got confused and asked why. I briefly explained my philosophy, and he went off to get his manager (another difference to UK call centers – there, it seems the lines are constantly monitored by people issues can be referred to). The eventual outcome of this – his manager had stepped out for a minute. What a kick in the nuts! I put up with crappy customer service all the time, and when I want to express my satisfaction, there’s no-one there I can do it to!

I think I’ll file this one under “thoughts”.

Women in IT – thoughts triggered by a female colleague

This post is coming quite a way after the fact, but I just read this tweet from Pamela Fox and it reminded me that I’ve been meaning to mention this for ages.

Back in November at Devoxx here in Belgium, one of the major themes was women in IT*. I asked my female colleague (who is, by the way, an exceptional developer but I’m not going to name her because I haven’t asked permission!) if she was attending any of the talks. She said no, and then went on to explain her viewpoint.

I’m paraphrasing from memory here, but the gist of the argument was “software developers are already a minority, and I don’t like the idea of creating an unnecessary sub-minority“.

This surprised me a lot. From one point of view, I can see where she’s coming from – as software developers, we’re already regarded (to a lesser or greater degree) as a bit strange**, and we need to hang together if we’re going to avoid being hung separately. From another viewpoint, however, it ignores the marginalisation of women by men who are in the same industry. I was going to use the word victimisation, but I’ve never witnessed it personally (and you can be damn sure it wouldn’t happen twice in my presence, regardless of the gender of the victim) – maybe a commenter can bring me up to speed on this?

I’ve been lucky enough through my career to work with some exceptional developers who happened to be female. In fact, I’ve never worked with a female developer who was any less than excellent – but there’s probably a very good reason for that. Since the overwhelming majority of developers are men, it follows that the majority of bad developers are also men. I’m pretty crappy with statistics, and they can famously be made to say anything, but it seems to me that the women who punch through the marginalisation barrier do so based on skill, and thus skew the figures even more.

Right now, I’m feeling very concious about what I’m writing, with the usual thoughts of sounding patronising and, frankly, feeling like the kind of dipshit who dumps his brain into his blog only to get it run through a blender. C’est le vie.

* The chivalrous part of me wasn’t sure to use women, ladies, girls or females. Since “Men in IT” is what I would write if this were about men, the feminine noun seems to me to be the correct one.
** Strange, in this case, defining a group of people who will have vitriolic arguments over the formatting of JavaScript, for example.