Show Blogger Panel Hide Blogger Panel
Alex Yakunin

September 1, 2010

When (0+x)*1 != x, or dealing with legacy data

I just remembered, that in the beginning of summer Alex Ustinov has told me a nice story about legacy data import. That time he was fighting with importing legacy data from some old .DBF database using SQL Server Data Transformation Services.

He said, "I tried to pull out the data column directly “as is”, but failed - the data type of column value returned by provider sometimes differed from the expected one. Probably, that was a result of some a bug in the data provider I used, or... Anyway, I immediately remembered that in order to convert the number to an integer data type in VB, you can simply add 0 (zero) to it. So I did this, and discovered that data import was almost fully fixed: the new script was capable of importing all the rows but one! I repaired this by multiplying  the expression by 1 :)".

I instantly imagined the following code:
var target = (0 + source) * 1 ` My friend, believe me, this is necessary!

It's ridiculous, of course, but in fact such decisions are quite frequent, if we speak about legacy code. It’s easier to work around the issue rather than understand what kind of bug is there (in DBF file itself, or in data provider – who knows?), taking into account there is almost no issue-related information about either. All this stuff was born before the Internet became really popular – precisely, a million years ago.

P.S. I’m retelling this relying only on my own memory, so there can be some terminological mistakes. Thanks god, I didn't deal with VB long enough to forget it :)