Comments Are Lies!

I recently came across a blog entry on Importance of Writing Code Comments in Software Development. It’s a proposition I’ve heard many times before, so I took a read to see if there was some reasoning I may have missed. There wasn’t.

Like the author of that article, I spend far more time reading code than writing it. O tempora o mores! Comments are not what I want to see, my friends, Clean Code is what I want to see!

Robert C. “Uncle Bob” Martin (more than) once declared: Comments are lies. He is (partially) right!

Here is some code from a project at my workplace. I’ve changed some of the names to protect the guilty but otherwise this is genuine:

//  --------------------------------------------------------------------------
//  Method Name:        CProtocolField::setValue
//  Definition:         This method sets the value attribute of the CProtocolField.
//  Qualification:      none
//  Export:             public
//
//  Return:             void
//  Parameters:         double value
//
//  Preconditions:      none
//  Postconditions:     this->getString() == value
//  Exceptions:         none

    void
    CProtocolField::setValue(const string& value)
    {
        myLength = value.length();
        myValue = new char[myLength+1];
        if (myValue != 0)
        {
            memcpy(myValue, value.c_str(), myLength);
        }
        myValue[myLength] = '\0';
        myBuffer = NULL;
    }
//  --------------------------------------------------------------------------

Ignore the terrible formatting, variable names and call to memcpy(), Did you spot the lies?

The “Method Name” is quite correct but I didn’t need a comment to tell me that. I suspect that even if you’ve never seen C++ before, you’d be able to tell me what the name of the class and its method are. The “Definition”, hardly needed a resident of 221B Baker Street to reveal it to the unsuspecting public, it sets the value, hence its name. It also does some other things, but we’ll come to that later. “Qualification” is used (in case you were wondering) to explain to the unseasoned reader whether a particular method is static or const or even virtual. Given this method is used to set a member variable (or three!), it’s pretty obviously nether of the first two. According to the declaration in the header-file, it’s non-virtual but… CProtocolField is derived from IProtocolField, which declares setValue(const string&) as pure virtual, making this method virtual. A lie!

Helpfully we’re told that this set-function has a public access specifier. I’m not sure what use a private setter would be, but we’ll move right along to the blatant lie: “Parameters: double value”! Why would any programmer write that? This method clearly takes one argument and it’s a const string&!

Of course a programmer didn’t waste their time writing this lie. It was copied and pasted from the double overload 44 lines earlier in the file. (I submitted a patch to remove the duplication, of course).

The “Preconditions” also lie. Whomever assumed responsibility for allocating myBuffer (a raw char*, no less) also assumed the precondition that this buffer has not already been allocated. This same (incorrect) assumption is made in eight other places in the same source file! Removing the memory leak was the main reason for me submitting a patch (shared code ownership is a topic for another day).

The claim in “Postconditions” tells us nothing useful. What if I never call getString(), what is the state of my object? If there were accompanying unit-tests, I would have checked them. (Instead, I wrote them).

Unit-tests are of course the best documentation for any code. They are living documents that you can execute at any time.

I said that Uncle Bob was only "partially" right. The comments below (from the same code-base) tell the truth, the whole truth and nothing but the truth:

//////////////////////////////////////////////////////////////////////////////
//
// Function Name:   ExcCxlCached::~ExcCxlCached()
//
// Definition:      Destructor for the ExcCxlCached class
//
// Qualification:   virtual
//
// Export:          public
//
// Return:          none
//
// Parameters:      none
//
// Exceptions:      none
//
////////////////////////////////////////////////////////////////////////////////

ExcCxlCached::~ExcCxlCached()
{
// Nothing to do here
}

Eighteen lines of comments for a destructor (that is obviously a destructor for the ExcCxlCached class) that does nothing! No lies, just noise.

By writing this kind of cruft, you are creating noise for the poor person who has to come along and read (and understand) your intent. The signal-to-noise ratio here is criminally low.

We’re not paid by the line-of-code, people! Please stop! If you want to do more typing, please expend it on putting some vowels and meaning into your identifiers. Or writing unit tests.

For this reason I have the following mapping in my .vimrc:

nnoremap <Leader>ic :<C-U>highlight! link Comment Ignore<CR>

This makes it very easy for me to hide the lies and the noise and concentrate on the code!

Remember: Comments are a failure to express yourself clearly in your code. Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin) is recommended reading on the matter.

Formula 1

I’ve been a motorsport fan since I was a young boy. Formula 1 was and is a particular fascination. I didn’t go to my first Grand Prix until the 2005 Belgian Grand Prix, which was an amazing experience. A few months after that, I moved to Melbourne, a stone’s throw away from the iconic Melbourne Grand Prix Circuit at Albert Park. Since then, I have been every year to watch the drivers at motorsport’s zenith battle it out for the top spot on the podium on a Sunday evening.

I always book my tickets early to ensure I get the best seat that I can afford and have enjoyed every single race. The Australian Grand Prix being at the start of the season makes it singularly exciting as it’s the first time that the fans get to see what the teams and drivers have been working on over the (Northern Hemisphere) Winter months. We find ourselves with muddled-up grids at the end of breathtaking qualifying sessions and this guarantees an interesting race to the first corner (and beyond) on the Sunday.

I booked my ticket for this year’s Melbourne Grand Prix back in July of last year and didn’t give it another thought until I got a phone call from the Australian Grand Prix Corporation on a Friday morning in September. They told me that I’ve won a ride in the 2-seater F1 car at the 2012 Grand Prix weekend (subject to some Ts & Cs) just for buying a ticket. I nearly fell off my chair. I couldn’t believe it.

Skip forward to this weekend.

It’s dark at 6 o’clock on Saturday morning at Albert Park when I’m greeted by our host at the circuit and presented with a ground pass that says, “Minardi 2 Seater Passenger” and some ear plugs. After signing my life away (gulp), I’m taken to the garage to have a look around the cars. There are a few photos here.

Shortly after taking a few snaps, I’m led out to get changed into my fireproof outfit and am told that there are two drivers, Cam McConville and Zsolt Baumgartner. Zsolt, I am told, does not hold back with passengers and goes full-pelt from the word “Go”, whereas Cam would ease them in gently. Guess who was driving me!

In pit-lane I’m taken to the car, where Minardi boss Paul Stoddart explains to me how to get in, how I’d be strapped in and also the Dead man’s switch, should I succumb to the immense g-forces to which my body would be exposed in the minutes ahead. Paul helped me secure my helmet and gloves and I was ready to go.

Stepping into the car was a dream come true. I was absolutely thrilled to be there. My visor fogged up as the team tightened the race harness around me. There was no moving now, my body is now one with the car with just my lower arms and my head afforded any movement and my left hand was gripping the dead man’s switch for all it was worth (if I let go, then engine would cut out).

Before I knew it, the Cosworth V10 a few centimetres behind me was fired up, the jack dropped the Minardi to the track and Zsolt’s right foot took us hurtling along the pit-lane almost without any warning.

The cool morning air seemed to clear my visor but I still couldn’t read the names above the garages in pit lane as they whizzed past to my right. We were travelling at such velocity so quickly. I wasn’t forced back into my seat as I might have expected: the harness was that tight!

"Oh my word, I’m in a Formula 1 car!" I think I said aloud as we reached the end of the pit lane. It was exhilarating and felt a bit like the initial buzz when an extreme roller-coaster sets off. But then we were out on track…

Zsolt Baumgartner changed up through the gears in a heartbeat. And I thought we’d gone quickly in the pit lane, that was nothing! We were travelling at amazing speeds along Aughtie Drive and then bam!

It was a bit like receiving a slap to the back of the head, followed by a thump to the face as my helmet hit the padding at the back of the driver’s seat. We’d reached Turn 1 already and Zolt had applied the brakes, I suddenly realised. "Unbelievable"! We turned sharp right and then left through Turn 2 and then the power is back on…

This machine and its operator are truly phenomenal!

Thump! Turn Three! Now I’m relaxed and completely enjoying the experience. I’m watching the tyres as they stick to the track like the stickiest glue imaginable.

I’m grinning like a Cheshire cat as we pummel down Lakeside Drive; the palm trees on the right are a part of my mental image of the Melbourne Grand Prix from watching it on the television back in England. Now I’m speeding past them in a Formula 1 car!

The three sharp corners at the Southern end of the circuit try to hurl my head out of the car, but my neck works hard to keep it attached to my body and before I have time to think any further about it, the main straight is right there and Zolt’s heavy right foot is flat to the floor taking us back to Turn One at Ludicrous Speed.

I can’t stop smiling as we trace the racing line on Lap 2. I’ve acclimatised to the speed and can now take in some of the smaller details: the hot air balloons up above and the track marshals dotted around the outside of the circuit. If it were not for these great people there would be no motorsport, I feel a deep gratitude for them. I also spot quite how close the Minardi’s tyres get to the green-painted concrete barriers on Lakeside Drive but I feel perfectly confident that there’s no danger of them actually touching.

A few seconds later, after the absolute ride of my life, we enter pit lane. I’m buzzing as the car is pushed back to its start position, jacked up and the engine stopped.

"Amazing!", I say to anyone who’ll listen as I vacate the seat for the next lucky passenger. It took me hours to come down from that high.

Vacating the Seat F1_2Seater_Day3_CL036 by Pete Johns, on Flickr

It was only as I caught a Melbourne taxi home that night when I realised quite how astonishingly safe I had felt with Zsolt Baumgartner driving me in the Minardi F1x2 at those astounding speeds. All credit to him and the team for putting together such a package!

The rest of the four days at the Melbourne Grand Prix were great, but somehow less significant than those few minutes where I really got to experience Formula 1 first hand.

I’ll certainly be booking early for the 2013 Australian Formula 1 Grand Prix!

Movember

Hi,

It’s Movember and time to focus on men’s health. To show my commitment, I’m donating my face to the cause by growing a moustache for the entire month of November, and need your support. My Mo will spark conversations, and no doubt generate some laughs; all in the name of raising vital awareness and funds for prostate cancer male depression.

Why am I so passionate about men’s health?

  • 1 in 9 men will be diagnosed with prostate cancer in their lifetime
  • This year 20,000 new cases of the disease will be diagnosed
  • 1 in 8 men will experience depression in their lifetime

I’m asking you to support my Movember campaign by making a donation by either:

  • Donating online at: http://mobro.co/johnsyweb
  • Writing a cheque payable to ‘Movember,’ referencing my Registration ID: 1467904 and mailing it to: Movember, PO Box 60, East Melbourne, VIC, 8002

Funds raised will help make a tangible difference to the lives of others. Through the Movember Foundation and its men’s health partners, the Prostate Cancer Foundation of Australia and beyondblue &emdash; the national depression initiative, they are funding world class research, educational and support programs which would otherwise not be possible.

If you’d like to find out more about the type of work you’d be helping to fund by supporting Movember, take a look at the Programs We Fund section on the Movember website: http://au.movember.com/about

Thank you in advance for supporting my efforts to change the face of men’s health. All donations over $2 are tax deductible.

–paj

Please donate at: http://mobro.co/johnsyweb

New beef with Facebook

Yesterday morning I had an email from Facebook letting me know that a friend had "tagged" me on his profile. This sounded fair enough, we’re friends after all. It went on to say that he tagged me under "University" with the name of my alma mater.

Curious, I logged into the website and saw the name of my former university on my profile! When I signed back up for Facebook, I deliberately withheld this information and now it’s on my profile.

But he tagged me on his profile, you said!

Details of which university I attended, the years I was there, my course and grades are all available elsewhere on the Internet; it’s not a secret! But having deliberately chosen not to put this information into Mark Zuckerberg’s databases, it’s infuriating that anybody can enter this information on my behalf and without my permission.

This morning I had a play around with Facebook, adding MI6, CONTROL and St Trinian’s School to friends’ profiles. It’s remarkably easy.

Some financial institutions use the name of people’s first school and similar information as answers to security questions. It’s a huge concern that these answers can be disclosed, unwittingly, by our friends.

Although I was able to remove the information from my profile, I’ve searched through Facebook’s privacy settings, and I can see no way to prevent this information being disclosed, in the first place. I see this as a huge security risk.

If you’re a Facebook user (and the chances are very high that you are), please take a moment to review the information you disclose and also your privacy settings. Sophos’s recommendations for Facebook settings are a good guideline.

Eamonn

Wow!

I’m a Dad! This is something that is still sinking in. As my friend Chris said in a tweet this week, "Forewarned is utterly, entirely not forearmed, is it?!"

He is right.

On Thursday morning I was filed with so much more joy than I ever thought I had the capacity for. I had heard how amazing is the miracle of birth, but being there for the birth of our son was an experience that no words can describe. Really.

Since that precious moment I have been finding a new appreciation for almost everything. I now understand why new parents feel the need to share the minutiae of everything their first-born does: each little thing is just so new and so exciting. I have a whole new appreciation of what our parents have done to get us to this point in our lives and I can never thank them enough. Grandparents really do deserve congratulations on the birth of a grandchild even if they say they didn’t do anything!

Thank you to all of you who have sent messages of congratulations, love and support to K, E and me. We’re hugely grateful and as soon as we have the time and the energy we’ll be in touch. At the moment we are still catching up on sleep, on washing and enjoying time with our beautiful baby boy!

The biggest thanks of all go to K who has just done so much over the past nine months to produce a healthy baby. I am hugely proud of her, particularly for the amount of effort required to introduce E to the outside world, she really was wonderful.

I shall put some more photos up on Flickr over the coming days especially for our friends and our family overseas.

I've unlinked my feeds

In case you were wondering, I have unlinked my feeds. For what it’s worth, I think you should unlink your feeds too. Life is short, time is precious and I certainly don’t have the inclination to read the same words twice (sometimes more) in one day. Do you?

Google Buzz was the straw that broke the proverbial camel’s back. I’m yet to see the point of Buzz; Wave I get and I like. Buzz, however seems to be just a waste of time, duplicating items already shared in Google Reader, Twitter tweets, blogs, etcetera, etcetera, …

It has to stop!

Like in Ghostbusters, we must never cross the streams.

Some of the streams that I had once consolidated but have since torn asunder are enumerated below, in case you were used to having them aggregated:

There are a few others, such as my Facebook profile, but I think a wise reader like yourself is getting the gist of how to find me online.

"When are you two having kids?"

K and I have been together for nearly ten years now and have been married for seven of these. One question that we seem to get asked with increasing frequency and increasing volume is "When are you two having kids?"

This is a blog post about that: I started thinking about how to write this while we were in England last July for my brother’s wedding.

"When are you two having kids?" we we were asked many times last June. I’m not sure why this question was so foremost in our friends’ minds while we were in the UK, but it seemed to be paramount in the thoughts. I had lost count of the number of times I was asked "When are you two having kids?" by the time we boarded the aeroplane to Dubai. We occasionally were asked were we going to have kids, but it was when that seemed to be the question of the month.

We had decided about eighteen months before this visit that, perhaps, to have a small family of our own would make for an even happier future than the one that already lay ahead. We’d not announced this, however. The bedroom window had been open at a suitable angle for a year and a half but there having been no sign of a stork thus far. The best answer I could give at this juncture was, "we don’t know."

"When are you two having kids?"

The question whirred around in my mind a lot while we were overseas. I wondered what kind of answers people were expecting…

For some people, those that have decided that they don’t like children or those who are concerned about over-populating the planet, then the answer is easy and obvious.

For a couple undergoing assistance for conception, then then answer might not be quite what the inquisitor wants to hear: Oh, is that the time? Do excuse us. We should be busy opening the window for the stork. Or something.

Perhaps they expect us to say, "Oh, didn’t we tell you?"

K and I have often shared much, perhaps too much, of our lives with our friends via the Internet: photographs, tweets, blogs, email and so on. Do our friends seriously expect that we would have neglected to mention the fact that we’re expecting a baby? Come on, people!

Since we have returned from our twelve week scan, I suppose now might be the appropriate time to share such a piece of information. I am absolutely delighted to announce that about the third week in July we expect to have a third (and only a third) member of the Johns household.

Yes, I'm back on Facebook

Pete Johns]

You may recall that back in January I deleted my Facebook account. The main reason for doing so was to free up more time. To be honest with you, haven’t found that I have had that much spare time in the months that followed. I didn’t miss Facebook at all and most people didn’t even realise I had deleted my account. So that was nice.

Unfortunately, what I hadn’t reckoned on was that Kirsty would become a Pete Proxy for many people’s words and pictures and that was a bit of a pain. Neither had I counted on the fact that some people would discontinue their blogs and opt for Facebook notes instead. And I like to nosey into my friends’ lives in my RSS reader!

Despite the plethora of ways to contact me electronically (listed here), it transpired that I was an e-outcast, a social e-leper without a Facebook account.

While I was off work sick on Monday, I did the unthinkable and signed up for a new account, the main reason being so that Kirsty is no longer the Proxy Pete.

So now that I am "back" what does this mean? Well, hopefully it’ll mean that I’m a bit easier to keep in touch with for those of you who don’t "do" email or Twitter or Skype or blogs or whatever.

There are a couple of RSS feeds to which I can subscribe to see my friends notes and any notifications that may concern me. Direct messages come straight to my inbox, so I can reply to those as a normal email, which will continue to be my preference for such things. Adium, my instant messaging application of choice, "talks" directly to Facebook, so I can use the inbuilt messaging without having to visit the webpage, which is, frankly, brilliant. My status updates will come from Twitter integration, my photographs directly from Flickr and my "notes" are just my long-running blog delivered to Facebook via RSS. If only I could still view your status updates in my RSS reader!

So the workflow of using Facebook shouldn’t take up as much time as it did with my previous account. That’s the theory anyway. You can help minimise the time I waste on Facebook by not sending me applications or group requests. That would be great! Thank you so much.

It’s nice to be back in touch, it really is. I just wish there was another way. Perhaps I should open a pub…

One-line of Python: string -> hex

Just a little something that may come in handy in the future (for my reference, rather than yours), a Python one-liner for converting an ASCII string to hexadecimal pairs.

to_hex = lambda s: ' '.join(['%02X' % ord(ch) for ch in s])

As you were…

Thank you, all. #wgs

I realise that I have been harping on about Leukaemia Foundation’s World’s Greatest Shave a lot over the past four weeks. It’s all done and dusted now and so I justed wanted to wrap up with a thank you to everyone who supported me, particularly in the past 24 hours.

When I woke up yesterday morning, I was anxious about the day ahead. Having never had my legs waxed, I was concerned about the pain that lay ahead, particularly given the very hairy nature of my legs. At 12:30, I went to Claire Françoise’s salon and after a brief wait was led to a little room with a couch and a bucket of hot wax. K came in too, to take some photographs for you people, which I will upload later today.

I have to say, folks, that my anxiety was for nothing. Claire was very fast and in no time at all, I was looking down on a pair of freshly-waxed, pale white, freckle-covered legs. I was reminded of an early scene in Spike Milligan’s book ‘Puckoon’, where The Milligan is giving out to The Author on writing such legs.

Back at the office, I was told that it was now time to go downstairs for my head shave. This was never a part of the plan, but there we go. There was a WGS event happening on the ground floor of my office block, so it seemed appropriate to do it there and then where some of my sponsors could witness the event first-hand. You will have to make-do with the photographs!

This morning, after an hour locked away in the bathroom (during a thunderstorm for effect) with a large tub of Veet and a Mach III, I emerged with smooth arms, chest and head. Again, there will be photos online later today.

You’ve kindly donated $2,120 to the Leukaemia Foundation. I’m extremely grateful for your generosity. And now, I have to concentrate on hair growth ahead of my brother’s wedding in Swindon, England on 12 June. Thank you very much.

Page 4 of 13