Best Programming Practices #2 – Parameters

This may seem like a no brainer, but it is often done wrong.

Set your parameters once and once only.  In other words, if you have ANY value that will be used more than once in your program, set a variable to that value and use the variable in the body of the program.

In other words:

variable1 = 40

width=variable1

rows=variable1

NOT

width=40

rows=40

Sure it’s one extra step now.  But if you ever change that value (and you probably will!), you’ll be able to change it in one place rather than hunting and searching for the fifty different places where you hard coded the value into your program.  It also means that you only have to worry about typos the first time through the program, not after each value change.

And of course, it goes without saying that you should keep all your parameters in one, easy-to-find place.  Your future self will thank you.

Leave a Reply

You must be logged in to post a comment.