Press "Enter" to skip to content

Practical Code Development Standards

Tom Zika writes out a list of coding standards:

No magic constants 

WHERE p.ProductType <> 4

What is 4? Just set a variable (constant) from a lookup table. Or write a comment with an explanation.
It’s the least you can do.

Read on for a set of things I generally agree with. This one’s a little bit of a tough case, as in extremely high-performance systems where the cost of a lookup is just too expensive, I’d prefer to use keys rather than values and save the compute cost and possible worse query plan. That said, even in that case, yes, definitely write a comment explaining what 4 is. That said, had I picked any of the other dozen or so recommendations, I wouldn’t have had anything interesting to say other than “go read this.”

2 Comments

  1. Tom Zíka
    Tom Zíka2022-06-14

    I agree with this assessment, Kevin.

    Hopefully, people in charge of high-performance systems know better than to listen to my generic advice. 🙂

    • Kevin Feasel
      Kevin Feasel2022-06-14

      And conversely, people who are not in charge of high-performance systems know better than to think they are and that they can therefore ignore all the rules.

Comments are closed.