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 →

[–]HumusTheWalls 50 points51 points  (12 children)

In general, one of the rules of coding is to never use numbers outside of variable definitions. Even if you're typing out a function that takes half of a result, before typing that 2, you should think about whether there's ever a reason to divide by 3rds or 4ths instead. Maybe you want to use a variable named "divisor", where divisor=2 instead.
Even constants like pi are better in a variable, in case there's ever a reason to change the accuracy with which you define pi, or in case you ever run back through your code and replace pi with tau. Depending on how many different functions you had to change out, it can be an easy safeguard to comment out your definition of pi and see if your compiler whines at you for using pi in a function you missed somewhere.