Unbest Practices #1 – Comments Full of Awesome
I love seeing good documentation in code. I really love seeing honest documentation in code. Seeing comments that basically show the developer has given up, hacked together a poor workaround to get a tasked accomplished at the cost of performance for every customer… full of Awesome. This is slightly redacted code from a stored procedure that was at the head of a blocking chain on one of my prod servers this weekend:
-- REVIEW
-- Currently processing updates as re-inserts.
-- This is because we don't really have a guaranteed key into
-- this table: the <redacted> key isn't completely sufficient.
-- We might be able to get there by using the <redacted> foreign key as well
-- and tracking that in the @<redacted> table.
-- This also avoids our needing to write the query twice or
-- creating a view to use in the update as well as the insert.
So yes, this product performs UPDATEs as explicit DELETEs and INSERTs. I would not be surprised if this was originally coded in purple crayon.
Peoples: take the time to find the answer – not a passable solution. I tell my son’s that and they understand that at the age of 9 and 12.