Bad code, part 2

Last Friday I was, half-jokingly, called a code snob. That was probably due to my continuous bitching of bad code in our project throughout Thursday and Friday. I know it is true so I will wear that label with pride! I just don’t understand developers who will write bad code that works but not refactor them later. I can understand write bad code initially to get a understanding of how the code needs to work first, then afterward refactor into nice clean code. I did that many times myself. But just leaving those badly written code once it is working? ARRRRGGGHHH!

Leah made a comment about my previous post about bad code before she jetted off to London. She said even though she didn’t understand what I was talking about she thought it must be like an English literature graduate reading a badly put together English sentence.

I think that is a rather good analogy for the non-programmers out there.

Technorati Tags:

Bad Code

Early last week we delivered a build of our application to the “customers” that has all of the planned features. Not a big bang release of course, since we practice TDD and XP so we release often. Sometimes too often for our liking but that’s another story!

So we all were in bug fixing mode but the bug list is moderated by our domain expert so there are times when all the bugs are being worked on and no new bugs are in the tracker.

The standard practice when that happens is to look for code to refactor. The amount of code we have and the uneven level of skills in the team meant there are plenty of opportunity for refactoring. After I did some light refactoring on some UI code, I came across this piece of gem:

if (someText.Length > 0)


if (someText.Length == 0)


Needless to say phrases such as, “WTF?”, “You are fired!” (in Donald Trump style), and many others came to my mind. I knew who wrote this piece of code and it amazes me that someone who has years of programming experience produces this kind of sloppy code. Even college students won’t make mistake like this.

Perhaps it is a one-off, you say? Try another piece of code that I’ve seen from the same developer at another time:

string fooString = new myForm().MyTextBox.Text;

string fooString2 = new myForm().MyTextBox2.Text;

I could immediately see three problems here. First, using a TextBox’s text property to store a default string for later use? Should have used constants. Second, exposing a TextBox as public property? Third and most important, instantiating a form just to get access to some data inside the form that has nothing to do with the form? How expensive is that!

So this developer violated some of the most fundamental rules/concepts of programming (Encapsulation in Object Oriented Programming, anyone?) for what, I don’t know and I don’t want to know.

Anyway, I showed the first piece of code to another team member who I know is discreet but even he shouted “What?” rather loudly after reading the code. I didn’t dare to show it (let alone the second one) to the team lead or the boss because I knew Donald Trump will definitely make an appearance!

Technorati Tags: ,

Stop Pretending, please

I know the idea of introducing a identity card in the UK is very controversial but pretending that Hong Kong only has recently been issuing ID card to the residents is re-writing history!

The Smart ID card referred in the BBC article is a new card with digital certificate, and that enable it to be used with post office and other commercial outlets. However, the permanent ID card has been issued by the British Government in Hong Kong since 1950s(?) and every Hong Kong residents are required to carry it at all time. I had (still have?) one since I was around 8 and had lost and replaced it twice. In fact, a number ‘2’ is appended to the end of my ID card number to indicate that. I have used this permanent ID card for immigration point at the Hong Kong airport many times in the last decade so this is not new either!

So the British Government please stop pretending that you have no prior experience in the subject of ID card, or how to efficiently issue and maintain 6+ million ID cards. Just ask your colleagues at the Foreign Office.

Of course the British Government won’t have any experience in the privacy issue in Hong Kong since that was hardly a consideration when ID card was introduced there all those years ago!

Technorati Tags: ,


BBC News commentator Bill Thompson has written a great article about software liability. Having worked at a transport/traffic software company during the first 2 years of my working life where a mistake by the programmers or QA can potentially results in fatality, I agree with Bill Thompson.

Yes, software will cost more to develop and test* but the reduction of support and bug fixing will offset the initial cost somewhat. More importantly, I want software that works most of the time, if not always. Not software that works the majority of the time if I am lucky.

* We had to proof (or able to provide proof) that our testings exercise every line and branch of our software. Thus we spent extraordinary amount of time generating contrived scenarios in order to exercise some obscure error conditions.

Technorati Tags:

Website Built with

Up ↑

%d bloggers like this: