A code smell is something you find in source code that may indicate that there’s something wrong with the code. For instance, seeing a function that is over a thousand lines gives you a clue that something is probably wrong even without looking at the specific code in question. You could think of code smells as anti-“Best Practices”. I’ve been thinking about these frequently as I’ve been looking through some old PowerShell code.
I’m going to be writing posts about each of these, explaining why they probably happen and how the code can be rewritten to avoid these “smells”.
A few code smells that are specific to PowerShell that I’ve thought of so far are:
- Missing Param() statements
- Artificial “Common” Parameters
- Unapproved Verbs
- Building output using +=
- Lots of assignment statements
- Using [object] parameters to allow different types
Let me know if you think of others. I’ll probably expand the list as time goes on.