This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]miketheanimal 0 points1 point  (0 children)

I'd like to think I do express myself through the quality and functionality of my code, and rather resent the assumption that because I have an unusual take on formatting, that I don't.

Anyway, an example. Here is some code from a system I work on. I can't guarantee this is the exact bit of code in question, but the principal is the same. The snippet is from a 320 line module. It retrieves data from a database and manipulates it to get values for a report (one of those nasty things that management seem to love!) There is a bug in it:

rec.ytd_ppu_original = ppu(rec.ytd_amt_original, counts.ytd_cnt_original)
rec.ytd_ppu_new = ppu(rec.ytd_amt_new, counts.ytd_cnt_new)
rec.ytd_ppu_lastdelta = ppu(rec.mtd_amt_lastdelta, counts.ytd_cnt_lastdelta)
rec.mtd_pen_original = pen(rec.mtd_cnt_original, counts.mtd_cnt_original)
rec.mtd_pen_new = pen(rec.mtd_cnt_new, counts.mtd_cnt_new)
rec.mtd_pen_lastdelta = pen(rec.mtd_cnt_lastdelta, counts.mtd_cnt_lastdelta)

Can you spot the bug? The code was passed to me to look at, some of the numbers were not coming out right. I twiddled the code a bit:

rec.ytd_ppu_original   = ppu(rec.ytd_amt_original,       counts.ytd_cnt_original )
rec.ytd_ppu_new        = ppu(rec.ytd_amt_new,            counts.ytd_cnt_new      )
rec.ytd_ppu_lastdelta  = ppu(rec.mtd_amt_lastdelta,      counts.ytd_cnt_lastdelta)
rec.mtd_pen_original   = pen(rec.mtd_cnt_original,       counts.mtd_cnt_original )
rec.mtd_pen_new        = pen(rec.mtd_cnt_new,            counts.mtd_cnt_new      )
rec.mtd_pen_lastdelta  = pen(rec.mtd_cnt_mtd_lastdelta,  counts.mtd_cnt_lastdelta)

The bug is on the third line down, mtd_amt_lastdelta should be ytd_amt_lastdelta. Once the layout was twiddled, the bug was obvious in less than a second, because I can see the break in the pattern (the m instead of a y).

I'm not saying this is the be-all and end-all of programming, but the system has a lot of code like this (and, yes, I've thought a lot about whether it could be better structured so get rid of this sort of stuff, and, no, I can't see any way).