Pages

April 29, 2011

We Need Debt Collectors

I've been thinking a lot about technical debt lately. We all have that one piece of code or module that everyone avoids like the plague because it is essentially a big jumble of hacks upon hacks. This isn't that big of a problem if it is a small piece of code that is rarely used, but what do you do if that code is one of the main pieces of your application?

I have been in a situation like this and it is not pretty. That one piece of code turns out to be the most popular for customer requests. The developers know something needs to be done about it, but with all the requests coming in, they are not provided with dedicated time to fix it. So in turn, the time needed to fix the problems increase with each feature. The developers then decide that the time it would take to fix the problem is more than it would take to rewrite the module from scratch so they start down that road thinking they are in the clear. However, they just doubled their work as they must maintain the current module as well. You get the picture...

The moral of this is to avoid the shortcuts that lead to technical debt and if you cannot, do your best to recover the debt ASAP or you will back yourself into a corner.

April 15, 2011

iPad 2 or Android Tablet???

ALERT: This is a non-nerd post…

My wife will be returning to school in the fall to start working towards her PhD and I am thinking that she would benefit from using a tablet. I just can’t decide if I should get her the iPad 2 or one of the newer Android tablets running Honeycomb. We currently have Android phones and she seems to like hers, but until I get Honeycomb in my hands I have no idea how Android translates to the tablet.

So what does a tech guy do? He asks for input from other tech guys who have gotten their hands on the devices. So please share any opinions you might have on the iPad 2 or one of the tablets running Honeycomb. You can either respond to the post or let me know what you think on twitter at @mrwillsw.

April 6, 2011

Java Doesn’t Make Money Easy

I am currently working on writing a small loan payment calculator application for Android, and trying to be a good boy and use the java.math.BigDecimal class to handle the money representations. It took me a bit to get it going, but I am really wishing I had gone “old school” and just used an integer and done all the calculations at the penny level.

The BigDecimal class methods initially seemed to be pretty straightforward. You just call the add, subtract, multiply, or divide methods like you would if you were doing normal calculations. So I wrote my test case, implemented the formula in my LoanCalculator class, and kicked off my test full of excitement about being able to tie all of this in to the Activity UI I had all set up. Nothing but red and a big stacktrace.

Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.

It turns out that when calling the BigDecimal.divide() method you need to specifically set the scale and rounding method so the object knows how to represent the decimal value in the cases where it is a repeating number, ex. 2/3 = 0.6666666666666…. I got that situated, got my test passed and moved on my way. I always wondered why I never saw BigDecimal used frequently and now I know why. Unless you pay attention to what you are doing and really read the API specification you will get errors and stacktraces that some devs would rather just avoid.