Topical Tropical

Stuff that makes me think twice 
Filed under

computers

 

Don't catch this

Inexperienced programmers can teach you a bucket load more than experienced programmers. I was reviewing someone's code recently when I came across something so nasty that I had to blog about it.

try {
x = you.getKnife().getRun().getCut();
} catch (NullPointerException e) {
x = null;
}
When I asked the programmer to reveal their intention, the answer was something along the lines of - that code kept throwing NullPointerExceptions, and this was the only way to proceed. When I asked the inevitable question of "why was that code throwing a NullPointerException?", the answer was an uninspiring "I don't know". A few moments spent debugging revealed a bug - that the developer had cloaked with the try-catch block. Scary to say the least!

As I was regaining my composure, Joel who was watching all this in the shadows piped "Never catch NullPointerExceptions". And what golden words they were! Almost anywhere you catch a NullPointerException, you are probably cloaking a bug. You should hunt for the source of the problem rather than cloak it.

You could generalise that for all workarounds - not just those that involve catching unexpected exceptions. The golden words could be generalised as "Behind every workaround lies a nasty bug". Doesn't that sound too obvious to be told? I don't know any more :-)

As I was thinking about all this, I remembered something that I find extremely annoying about Objective-C. Any operation on a null* value results in another null value (rather than a NullPointerException). Thus in Objective-C, the code above would have the same effect without the try-catch block.

The reason I find this extremely annoying is that every time I introduce a bug involving nulls, they propagate far far away from the original source of the bug. No exceptions are reported, and hence everything seems to be functioning correctly, except it isn't! The symptoms are button presses being ignored; generated fields being mysteriously blank; empty files being writen, etc. The list goes on and on.

The annoying NullPointerException is your friend :-)

*For the purists, Objective-C refers to null values as nil values.

Filed under  //   computers  

Comments [0]

Out of memory (not!)

This has got to be the most annoying thing about running Java desktop applications. The dreaded out of memory error. Large applications like Eclipse require more memory than your usual hello world program. Sun in all of its good intentioned malice has decided for you that your desktop applications will be corralled into a limited amount of memory that is decided at the start. Your applications don't gracefully slow down as they start using up swap space - like other non-Java desktop applications. There is no warning. It doesn't matter if you were working on the cure to cancer and your machine had enough memory to shame an elephant. If your Java application hits the limit rightfully or wrongfully, you will lose your work. And no, it isn't good enough for the application to tell me that I should've known better and increased the size of the heap. There is plenty of free memory on my computer - it needs to just use it!

If you think about it, the error message is wrong. My computer is not out of memory. Eclipse isn't out of memory either. It is just out of the horrible horrible limited memory that was chosen for it when it started up. 640k ought to be enough for everyone right?

Filed under  //   computers  

Comments [0]

Please help me find it!

I've been reading a lot of lengthy documents online recently, and I'm finding the user interfaces of web browsers, PDF readers and other such applications to be severely lacking. Don't even get me started about Zinio Reader.

Apple's Preview is a very good PDF reader, but it fails me when I want to search for words in a PDF document. In the following example, I searched for the word 'inject'. After it found the page, I had to scan through the page line by line with my tired eyes until I found the near invisible gray highlighted word!


I would like to poke the eyes out of the person at Apple that decided to highlight black text with a gray background! Yes, inverse video text was the only way to highlight text on a monochrome ANSI terminal when they were popular, but isn't it high time to discard this old user interface maxim and come up with someting more friendly for my 1440x900 display? Something that is easy to find on a page swarming with uniform horizontal text. Perhaps an animation of dancing girls next to your text? Hmmmmm... I think I'll settle for what a neat little PDF viewer called Skim does:

Now that's much better!

Filed under  //   computers  

Comments [0]

The cleverest computer program

I woke up one morning with the remnants of a strange computer related dream in my head:

The cleverest programmer devised the cleverest program. When he was done, it asked him "How do you know I'm done?"

I'm feeling completely lucid as I post this, and I don't find it the least bit funny :-)

Filed under  //   computers  

Comments [0]

File->Lose or File->Save

Isn't it strange that word processors have a 'File Save' command? It's as if users want their documents to be lost by default, and only saved on request!

I remember an incident at university when I was the resident geek (yes, sadly). One of my neighbours was distraught because her computer had lost an assignment that she had been working on for about three days. She hadn't saved the document once, and her computer had crashed taking her document away. Forget about backups. She didn't even have the document saved to disk.

She was horrified when I explained to her that unless she saved her document the computer would just happily lose it by default. She looked at me with incredulous eyes - "How could computers be so dumb!"

Wouldn't it be nicer if word processors just saved documents by default (wherever!), and had a 'File Lose' command instead? People don't start typing into a word processor with the intention of losing their work!

Filed under  //   computers  

Comments [0]

Always clean up before yourself

Quick! What's wrong with the following fragment of a test?
(Ignore the missing calls to super.setUp(), and super.tearDown() because they aren't important to illustrate my point)



void setUp() {
executeSQL("create table test_table (a number(9))");
}

void tearDown() {
executeSQL("drop table test_table");
}

void testSomething() {
// test some code here that performs operations on test_table
...
}



It is very simple to read, and it conveys its intention quite clearly. However, the problem doesn't show up until you have to run this test repeatedly.

Imagine you were using this test to develop some database code in a test driven development way. If during development you introduced an error in testSomething() which caused it to throw an exception, you'd quickly find out that the tearDown() method doesn't get called. The test stops abruptly when the exception is thrown, and poisons the next execution of the test - because the test_table isn't cleaned up.

You would only be brushing the problem under the carpet if you decided to guard against this problem by modifying your test to look like this:



void setUp() {
try { executeSQL("create table test_table (a number(9))"); } catch(Throwable t) {} // Ignore errors
}

void tearDown() {
executeSQL("drop table test_table");
}

void testSomething() {
// test some code here that performs operations on test_table
...
}



The problem with this version is that even if you ignore any exceptions thrown by setUp(), you may end up with rows from the previous run of the test poisoning subsequent runs of the test.

I'll save you some pain and let you in on a little secret. Tests of the following form are prone to having their state poisoned by previous invocations of themselves.



1. setup
2. perform test
3. cleanup

If however you wrote your tests in the following form, you'd find it easier to maintain and errors during development won't poison subsequent runs of your tests. You'll also find that your tests are more defensive, and less prone to being poisoned by other tests :-)



1. cleanup and ensure a good starting condition for the test
2. perform test

Another additional benefit of writing your tests using this pattern is that you can examine the state of your database (or any other state) after the test has executed successfully.

Finally, for completeness here's a robust version of our example:



void setUp() {
// Ignore drop failures because this may be the first run
try { executeSQL("drop table test_table"); } catch(Throwable t) {}

// DO NOT ignore creation errors because we need an empty table for our test.
executeSQL("create table test_table (a number(9))");
}

void testSomething() {
// test some code here that performs operations on test_table
...
}



So there you go! The moral of the story is to always clean up before yourself :-)

Filed under  //   computers  

Comments [0]

The curse of security, and other rants

I spent the last weekend windsurfing as far away from civilisation as I could possibly get - 200km away from Melbourne at the sleepy town of Sandy Point. My mobile phone had no coverage (hurray!). There was no way to get onto the Internet except for a cafe that offers free WIFI for those with a laptop (which includes me).

However, being the only cafe in town I couldn't avoid it when I felt the need to eat or drink. This brought me perilously close to the Internet, except for the fact that I'd diligently left my laptop at home :-)

I was however not far away enough from helpless computer users - the cafe has a strict "No support offered free WIFI access". Getting onto the Internet via WIFI is a difficult thing you see. I had to share a table with a couple that had bought a laptop with a "Wireless Internet Ready!" sticker just the other day so that they could be one with the rest of humanity in this isolated town.

I tried to ignore their cries of "The Internet doesn't work", and "What does connection refused mean?". However, I couldn't lie when they asked me if I was "good with computers".

The laptop was brand new with more stickers than the furniture in my childhood bedroom. According to windows networking, the laptop was connected to 'Sandypoint', with a strong signal strength, but websites weren't coming up.

When I tried to go to the properties window to try and re-connect (just for the heck of it), I got the very cryptic message that read something like "Your wireless settings are managed by another application. Please use that application, and don't bother me".

Hmmmm... Windows XP not managing the wireless settings? And it won't tell me who is. I'd never seen that before. After a little more clicking about the nest of icons on the task bar, I discovered that there was an Intel WIFI manager application managing the connection! Yikes. I reconnected successfully with that, but "the Internet was still not working".

A few quick ipconfig and ping and checks later I realised that there was nothing wrong with their connection except for HTTP (WWW for those of you who don't know what that means).

Hmmmm.... What's that yellow icon hidden in the nest of icons in the task bar? Something called 'Norton Internet Security'. And this bizarro application I soon found was blocking all of HTTP in the name of security :-)

It allowed me to disable it for 1min, 5mins, 15mins, and 'till the next windows restart'. Hmmm... let me see what happens if I turn it off - and like magic I heard them scream out in ecstasy "The Internet is working!", as the web browser started spewing out popup ads :-)

There are a few things that I think are really bad about this whole situation:

One, from a users perspective, the abstraction that Windows manages the connection was broken by Intel's connection manager. However, the fault isn't entirely Intel's. Windows quite knowingly provided hooks for Intel to plug in to, and was quite aware that it wasn't in control any more. However, it failed users by providing a button to edit the settings that didn't work (it just popped up an error). Even worse - it just palmed off the problem to an unnamed application. What is a user supposed to do in this case? Will somebody think of the users? :-) Especially those stuck in a one-hotspot town? :-)

I think the best thing to do in these situations is to either have a single application completely in control, or have both integrated well. The half way integration is the worst possible situation for users. Windows should've just gotten out of the way, or had a clean integration with all working buttons.

Then there's Norton Internet Security. Sigh. As much as I hate the popups of ZoneAlarm, I think it's better to be verbose and tell the user that you've denied them access to something that THEY REQUESTED. Instead Norton Internet Security stayed silent about the matter, and decided it was best to just trap users.

I think Microsoft should've fought harder to keep these guys out of the Vista kernel :-) Peter Norton's company used to produce some of the best utilities back in the DOS days. I often wonder how they keep afloat these days :-)

Lastly I really don't know what the laptop manufacturer was thinking when they decided to bundle Windows with these two interlopers that would've best been left out in the name of simplicity.

Before I left the Cafe, I heard the couple muttering that they were going to take the laptop back because they couldn't figure out how to turn "Norton" off for ever :-)

Did I mention that I had the most amazing time windsurfing that weekend? :-) :-D

Filed under  //   computers  

Comments [0]

Wake me up when it's the future

I was chatting with my sister on Skype when she mentioned Roxette:

her: If you ever feel depressed you should listen to Roxette - its so 80's

So I fired up iTunes to hear a preview when I had a realization...
me: I just love 2006 :-)
her: Why?
me: I'm listening to Roxette now.
me: You mentioned it, and it's playing over here in an instant (albeit a preview)

I was still feeling so happy that humanity was out of the dark ages, and that my sister and I could have a good time together even though she was a continent away in China! And then it had to happen...!!!


Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_INVALID_ADDRESS (0x0001) at 0xbe88a07b

Thread 0 Crashed:
0 libSystem.B.dylib 0x900087bb szone_calloc + 4450
1 libSystem.B.dylib 0x900075fb calloc + 604
2 ...ple.CoreServices.CarbonCore 0x90c7df5d CSMemNewPtrClear + 47
3 ...ple.CoreServices.CarbonCore 0x90c7ddd7 NewPtrClear + 29


Sigh! Apparently 2006 is still the dark ages for memory management technologies. We will soon have OS X Leopard, which supports garbage collection in Objective-C. I wonder if it'll be adopted by apple developers more than Java was adopted as a desktop software development tool. There were a few applications developed in Java, and even a few games, but nothing memorable comes to mind :-) Microsoft's dot.net which supports garbage collection has been out for a while now. We've even hit the magical version 3.0, but I'm yet to see any mainstream desktop applications developed in it.

Wake me up when it's the future :-)

Filed under  //   computers  

Comments [0]

My mind is going :-)

I am getting the distinct feeling that my mind is going.

The toilets on our floor of the building are being ripped out, to be replaced with shiny classier toilets. The construction workers have ripped out every last smidgen of the toilet. They haven't even left the tiles on the wall. It's a complete transformation. The first thought that came across my mind when I walked past the construction zone this morning was:


They're not bothering to refactor the toilets. They're just rebuilding from scratch.

*drum rolls*

This evening I discovered that a thin spoon had been riding the dishwasher for several weeks (since I last remember seeing it). It had become wedged at a side, and I had missed it when emptying the dishwasher. When I noticed it, the first thought to run through my mind was:


Oh dear, how many releases has this been in here for???

:)

Filed under  //   computers  

Comments [0]

Lists of lists of lists of...

The web is getting bigger. No it's getting humongous. No, there's no word for the size of the web. People will start saying "your mama's butt is as big as the web" pretty soon. You have been warned :-)

Once upon a time there was the Yahoo web directory. It was your trusted companion if you wanted to find anything on the miniscule Internet that existed at that time. There were a few other lists and directories of the Internet, but inconsequential compared to Yahoo.

Then search engines started appearing, and were successful by various degrees. They however didn't really unseat the venerable Yahoo web directory.

Then came google search. That was the end of the lists. No body told Yahoo that their directory was redundant. You simply didn't need to head for a neatly organised list any more.

Then came the aggregators like Google News, and Digg. Quite popular for a while, but they didn't really hit the spot.

However, however, and however. The lists are back! They're a little shy from the Yahoo experience, and don't try and cover the entire breadth of the Internet. They realise that it's futile. Instead they concentrate on a niche. Time will tell how successful they will be, but here's a sample for your perusal. Judge for yourself, and let me know if you think they're going to end up in your bookmarks :-)

  • Feeling a bit geeky, and need your daily fix of geek news? No, don't go to slashdot, but try The Web List.
  • Fancy some media along with your geek news? You should bookmark popurls.
  • Fancy being a webmaster today? You need The Webmaster's handbook - which is badly named, but really a list.
  • Well, this isn't a list, but a page stuffed with links - Adelaider
Yes, so they aren't directories of information like the Yahoo Directory, but they're fighting for your eye balls in the same way :-)

Filed under  //   computers  

Comments [0]