Friday 8 October 2010

The Weird Ways People Do Things

Part 1 of a Potentially Infinite List

Not much time today, so a quick one. I was shoulder-surfing/pair-programming with a very experienced Java EE developer the other day and watched in (silent) amazement as he performed an int-to-String conversion like this:


  methodThatExpectsAString("" + numThings);

I hadn't seen that idiom used since my university Java 1.0 days!


In most modern, typed languages these kinds of conversions are so frequent that they are semi-automatic to type (I often find myself typing valueOf when all I really meant was value!) - so why is it so hard for people to know and use the library methods that have been in the language since Day One? You only have to search for Java integer to string to see how many people don't know stuff that's covered in the Java Tutorial that immediately follows the "Hello World" demo.


To be fair, my keystroke-saving colleague is actually using the very first int-to-String technique outlined in the aforementioned tutorial. I just prefer the more explicit statement of intention offered as an alternative:

  methodThatExpectsAString(String.valueOf(numThings));

Oh well. As my Great Uncle Bruce used to say; it's all part of life's rich tapestry...

No comments:

Post a Comment

Comments welcome - spam is not. Spam will be detected, deleted and the source IP blocked.