« September 2003 November 2003 »
blog header image
# Java IOException and Code Coverage

Code coverage is pretty cool -- it lets you see how much of your code your unit tests exercise. The only problem is that there are a few strange cases which are hard or impossible to cover.

An impossible coverage example is a private constructor with no accessor method. Library classes like java.lang.Math have private constructors because all of the methods are static. It doesn't make sense to have an object of this class so there's no way to get to the constructor for a good reason. Unfortunately coverage tools like jcoverage count the empty constructor as a missed line of coverage.

Why do we care about one silly line? Well because from a project management perspective it's a lot better to say "we need to keep 100% code coverage" than it is to say "we need to stay as close to 100% as we can but we accept it's not possible because there are these weird cases...". Always being 100% is a hard and fast, easy to enforce rule -- if the developers are allowed to be less than 100% you'll never be able to keep track of all of the special cases the team had to work around. So covering all of the code is a good thing.

So that brings me to my particular example -- the IOException. They are checked exceptions and you have to catch them at some point in your code. When you do, you'll have to cover those catch statements or you'll be less than 100% for code coverage. Throwing an IOException is not an easy thing to do (besides FileNotFoundException**) with regular files because it usually involves some sort of catastrophic I/O error, hence the name.

My buddy Andrew reminded me of a great way to induce IOExceptions though: create a new class that subclasses the File class and override some of the read/write operations as necessary so that it always throws an IOException. Bingo, every time you use that dummy file you'll get the exception and cover your code. It's not a real file but it's the closest you can get. After all, you are testing your code and how it handles exceptions, not the File class.

Actually, that isn't quite my example -- it involves a bit more. Our fourth year project's Java code is layered, and API calls are made down the layers. Most of the file-related calls look like this:

public void upperAPIMethod(String filename)
{
   try
   {
      lowerAPI.setFile(filename);
   }
   catch (IOException ioe)
   {
      throw ApplicationException("Error reading the file!");
   }
}

The user interface is above this method in the layering, so I want to throw my own special exception ApplicationException up to it. I don't want my UI dealing with IOExceptions (and others) -- just one type of exception that it can take the message out of and display in a modal dialog box.

This method takes a string as input, has no output and throws an ApplicationException. Herein lies the problem: there is no string that will generate that ApplicationException! For black box unit testing, this is a very bad thing. So how could I change my method?

public void upperAPIMethod(File fileToSet)
{
   try
   {
      lowerAPI.setFile(fileToSet);
   }
   catch (IOException ioe)
   {
      throw ApplicationException("Error reading the file!");
   }
}

Now I can pass my dummy file in and get the ApplicationException out. Great. The only bad part is that each layer (including the UI) needs to know about File objects instead of regular String objects. Is this really a bad thing?

**I'm not concerned about FileNotFoundExceptions in this discussion because I catch them before IOException and throw an exception with a different error message -- "file not found" instead of "error reading file"

posted at October 29, 2003 at 11:19 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (5)

# iBook Woes

So after not hearing from the store about my iBook for two weeks -- not including the call I made to them a week ago -- I went in today. They ordered the part on the 21st but didn't call me to tell me (even though they said they would -- twice!). So there was some miscommunication. Now they say that the part could be on backorder and that's why it's taking so long.

So that brings me to the part. The part is what Apple likes to call the "logic board" and what most computer people would call the motherboard. Except this motherboard comes with the CPU, video card, RAM, sound and all of the inputs (firewire, USB, modem, NIC) integrated on it and, if not under warrantee, would cost over $900 CAN. Ouch.

When I first went in, they told me that the new logic board would have a one day warrantee on it. Now they tell me that it has a 90 day warrantee on it. Sheesh, I should get this is writing. I'm probably going to get the two year extended warrantee at the education discount from the school computer store anyway.

I need that machine back. :(

Update January 29, 2004 Apple has decided to fix these defective motherboards for free.

posted at October 27, 2003 at 02:22 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (8)

# Visual Studio .NET vs. Eclipse

Being mainly a Java/Eclipse developer I'm finding it quite hard to move to .NET/C#. You see, Eclipse has spoiled me and given me all of these wonderful features that I can't get in Visual Studio .NET. I'm wondering why I ever wasted my time hand-editing my code all of these years. Here's the run-down on my issues:

1. C# is Java. There, I said it. It's Java with different words and some extra stuff like Properties. Everything is the same but named differently. How convenient. It's a lot like the difference between C# and VB.NET but a little more so. The upside is that I get to say I know two languages for the price of one and a half.

2. Refactoring. Holy crap, I'm screwed. I can't use an IDE without refactoring any more -- I get completely frustrated. "What do you mean I have to change the name of this function myself in all of these files??" Global search and replace? Ick.

3. Code Indenting. The Eclipse indenting isn't perfect either but at least it doesn't trip over itself when you go one line too far down and go back up. Oops.

4. Code Completion. Right in there with indenting. Give me the end bracket/brace, damnit! I don't want to type it.

5. Code compiling. Compile my code as I write it so I can see mistakes, please. I hate recompiling my project every single time I want to check for errors. I'm not typo-free (or else I'd be a secretary).

6. Unit testing tool integration. For the love of Pete help those poor NUnit saps put unit testing right in Visual Studio. Why do I have to switch back and forth between apps and find the compiled executable I want to test. Integration integration integration. It's all about saving small increments of time (remember time motion studies?) ... if I have to switch 200 times a day between apps and that takes 5 seconds, there's 4000 seconds! Six and a half minutes and a hundred times more frustration.

7. CVS integration. How can a modern IDE survive without code repository integration? ... and I'm not talking about Visual Source Safe here, CVS is the minimum. Eclipse's CVS integration is beautiful. Copy it. Please.

That's it for now ... believe me, there will be more. I'm kind of exaggerating my exasperation for comedic (maybe?) effect but only a little bit. It's a seriously sad situation here.

If you know how to solve any of these problems, let me know! I'm using the original version of VS.NET (2001, I guess).

posted at October 27, 2003 at 02:18 AM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (23)

# iBook Repair Update

I called the store about my iBook today but they still haven't looked at it because they were very backlogged. They say they'll take a look at it and run some diagnostics within the next day or two and give me a call.

posted at October 20, 2003 at 04:21 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (1)

# They're All Watching You

Gregg Easterbrook, a reporter, has been fired from ESPN for remarks he made on his blog. I'm not going to comment on the nature of the remarks but it brings up an interesting point: when you blog, everyone can see you.

That includes your family, your co-workers, your boss and all of your friends. When you're typing into some insignificant text box its hard to keep in mind that the whole English-reading wired world can read your blog. That is hundreds of millions of people.

So be smart about what you write in public ... especially about things that can get you fired.

posted at October 19, 2003 at 02:55 AM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (2)

# Go Warrantee Go

So I went to the store today to get my iBook fixed. They had seen the problem before and because the machine was still under the initial year warrantee they'll do the repair for free. I should hear within the next 48 hours what the exact problem is.

It's funny but when they booted the machine up the screen worked again. Figures. They said that also happens a lot -- problems magically go away when people bring the machine in. They'll keep it on for a while until it breaks again.

They also confirmed that I can buy the extended warrantee up until my initial year expires, which is mid-December. It's two more years for $390 CAN and transferrable if I sell the machine. Given this problem I might get it just to increase the resale value.

Update Oct 15 00:06: Jamie tells me that the education discount price for the extended warrantee is only $280 CAN. Party on Wayne.

Update January 29, 2004 Apple has decided to fix these defective motherboards for free.

posted at October 14, 2003 at 03:15 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (0)

# Flying Blind

Before I take the iBook in I wanted to copy my home directory over to my PC to make a backup. Mostly just for my iCal calendars but I'd like to have all of my old email too.

So Jamie tried to walk me through logging into my machine and starting up a telnet daemon blind, without monitor. I got logged in, started Terminal and tried to start the daemon but my PC couldn't connect to it. :( Ah well.

Update Oct 13 16:53: Yeah forgot to mention that we tried the external monitor connection and it didn't work either. It has worked in the past. If I had to guess, I'd say the video card is shot.

posted at October 13, 2003 at 02:13 AM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (1)

# A False False Alarm

My iBook display is flakey. It turned on today but then just went all wonky -- it looked as though it was displaying every second line of pixels. Now the display won't turn on again but the computer boots and shuts down (via the power button) just fine. I'll take it to the store tomorrow if it's open.

Update January 29, 2004 Apple has decided to fix these defective motherboards for free.

posted at October 12, 2003 at 09:18 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (0)

# Oops, Another False Alarm

So my iBook isn't dead I guess. I opened it up to give it another try and it was warm ... I thought that was pretty strange so I tried holding the power button down for a while, over 5 seconds. The familiar Mac chime sounded and the screen came on. I should really read the iBook manual at some point.

posted at October 11, 2003 at 02:12 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (0)

# iBook Mortis? :(

I think my iBook just died. One of the USB ports was flakey for a while and then returned but now the whole machine won't turn on at all. The battery still shows it's full and when I plug it in the charging light turns on so it wasn't completely fried somehow. I haven't done a backup in a while but the only 'important' stuff I keep on there is e-mail, which I keep on the server anyway.

It really sucks having to make a warrantee claim though. It came with a one year and I didn't buy the three year extended. I guess I should be glad it's dying now and not in 4 months when the warrantee would have been expired.

Of course it might be something else. Last time I thought my iBook died the screen brightness was just turned all the way down. Heh, no I checked for that this time. :)

Update January 29, 2004 Apple has decided to fix these defective motherboards for free.

posted at October 11, 2003 at 12:32 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (0)

# Secure Files

We had an interesting Internet Security lecture today. Some of it talked about how secure documents/files go through a few phases, one of which included litigation. The state of affairs is pretty sad, but the point was that a completely technical solution can be either impossible or undesirable from a business standpoint. Like Prof Adams said, it's better to have 70% of a $180M business than 98% of a $50M business.

The problem I have is when companies dupe the ignorant general public into thinking something is secure, sell it to them as such and then sue the pants off anyone who dares to break it.

The recent case of a "security" company suing a student for revealing how to "break" their security is absolutely laughable. Common sense dictates that there has to be some sort of decent security there for something to be called "secure". Simply bypassing the loading of a driver is not subverting anything, it is just a bad implementation.

Consider this analogy: If you voluntarily left an iPod in the hallway outside your locker and someone took it, would that still be stealing? Would anyone sympathize with you for expecting it not to be taken? I don't think so. Your principal wouldn't do anything but have a good chuckle.

If you put your iPod in your locker and someone stole it people would definitely sympathize. The combination lock, though easily broken with a crowbar, is an effective enough security device. People had to agressively (and irreversibly) subvert it to enter the locker and take the iPod.

OK, now what if your locker was held closed with a twist-tie? You still have to open the locker to steal the iPod or even see it. It's not in the wide open like in the first case -- the owner isn't effectively 'giving it away'. You still have to break the shoddy "protection", but was it good enough? Of course not. Common sense (used often enough in law to be relevant here) would dictate you should have had more protection. Curious people will come along and snoop in your unlocked locker. You can bet that an insurance company wouldn't cover your loses.

I definitely don't have a solution to this problem (if I did, I'd be a rich man no doubt) but what's going on in the courts in the US with the DMCA is pretty sad. The shift key is not a subversion of copy-protection, that is just absolutely ridiculous. Maybe if secure documents were actually more secure people would take copyright infringement more seriously.

posted at October 11, 2003 at 03:20 AM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (0)

# Engineering or Art?

To hack or not to hack, that is the question. Hacking is becoming a lost art some would say. Software projects are too large for one person to keep in a single brain. Process becomes necessary. This doesn't sound like a lot of fun.

But here's the deal -- it's all about who you are writing your software for. If you're writing it for you by all means hack away. But if you are a real software engineer you should be able to put your stamp on it. You should be able to say "I did the best I could to ensure good quality here" and that doesn't include hacking up something.

Of course it all depends on the quality threshold you are aiming for but companies don't bring in software engineers to hack little pieces of code together. They expect large projects and for them to be done with a relatively high level of quality, which admittedly in software isn't saying much.

Hacking is definitely an art -- if you've ever seen someone pour out code from their head rapid-fire you know what I mean -- it's pretty amazing. But I'm beginning to think its day has past. In a way it's sad but it looks as though, probably for the better, new software will be engineered stronger than art.

posted at October 08, 2003 at 05:45 AM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (3)

# MSN Messenger Bugs (Me)

I'm having a bit of a problem with MSN Messenger lately. I have a DSL connection with Bell which seems to be disconnecting for short periods. If MSN Messenger is running and I am "Away" sometimes when the DSL connection is restored Messenger will change my status to "Online". Then when I return to my computer I have a bunch of messages like "why aren't you talking to me?" and "hellllloooooo?" from people. Sheesh.

I haven't had this problem until recently -- maybe since a month ago. I am using MSN Messenger 6.0.0602, the latest build available. It would certainly be nice if they fixed this problem.

On a related note: just because MSN Messenger says I'm "Online" doesn't mean that I am sitting at my computer at that moment. People have lives outside of a box sitting on their desk -- don't be insulted if I don't answer posthaste, OK people? :)

While I'm complaining about Messenger I might as well complain about MSN Messenger for the Mac, which still doesn't have the new emoticons. Anarchy, I tell ya.

posted at October 07, 2003 at 01:30 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (5)

# Disappearing Blog Trick

You know you haven't posted in a while when your front page goes blank. Thanks Peter for the heads up. Hmmmm maybe I should write something.

Oh yeah, I got my second email from an interested employer concerning my resume. Recruiters out there should keep in mind that I haven't graduated yet. This isn't 1998 so no, I will not leave in the middle of my last semester to join your team for thousands of penny stock options. I must finish (finally) and I will be available to work in January.

The fact that recruiters use Google is kinda cool though. My first email came from a little company in Austin about a development position using Eclipse. Just goes to show you I guess ... you'll never know where the next opportunity will come from.

posted at October 01, 2003 at 10:16 PM EST
last updated December 5-, 2005 at 02: 2 PM EST

»» permalink | comments (3)

Google
 
Search scope: Web ryanlowe.ca