DEV Community

Discussion on: 16 Best Source Code Gems [Collection]

Collapse
 
davidhaile profile image
David Haile

Good! #2 If You Get Here...

Which reminds me: I inherited a pile of crap code that actually worked fairly well. The original programmer (forced into it) didn't know how to use a switch() statement and what he implemented was a complicated state machine with if () else if () else... nested very, very deep! The nested if,if,if statements got soo deep that at one point I added a comment that if the code reached that location the engine must be on fire (it was a generator controller).

A couple of years later they resurrected the project and of course reviewed the code and found my comment. I got in a lot of hot water over that one. My recommendation for others who find themselves in a similar position of inheriting crap code, go ahead and make comments like that, but somewhere in the header document that you inherited it from and make dam sure that future reviewers know your story. Reviewers will or should learn that is under suspicion.