I\'ve been chatting with my colleagues the other day and heard that their coding standard explicitly forbids them to use the var
keyword in C#. They had no idea
First, as a general rule, coding standards should be discussed and agreed by the team, and the reasoning behind them should be written down, so that anyone can know why they are there. They shouldn't be the Holy Truth from One Master.
Second, this rule is probably justified because code is more times read than written. var
speeds up the writing, but may slow down the reading a bit. It's obviously not a code behaviour rule like "Always initialize variables" because the two alternatives (writing var
and writing the type) have exactly the same behaviour. So it's not a critical rule. I wouldn't forbid var
, I would just use "Prefer..."