Book Image

PowerShell Troubleshooting Guide

By : Mike Shepard
Book Image

PowerShell Troubleshooting Guide

By: Mike Shepard

Overview of this book

Table of Contents (15 chapters)
PowerShell Troubleshooting Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Language-agnostic code smells


Some things look wrong no matter what language they're written in. For instance, if you have 200 lines of code in a block, it's always going to be a sign that some effort might pay off in terms of rewriting it using smaller, more modular code. Also, if you see several blocks of code that are identical, or even very similar, it will probably be worthwhile from a maintenance standpoint to factor that code out into a function. Some other code smells that are very common are:

  • A very large parameter list

  • Overly short identifiers

  • Extremely long identifiers

  • Deeply-nested loops or conditionals

  • Multiple-personality functions (that is, functions that do more than one thing)

One thing that is worthwhile to point out is that these are all somewhat subjective. For instance, what is a large parameter list? Some PowerShell cmdlets have dozens of parameters. Do they smell? Everyone will have their own perception of when that line has been crossed. Even when a usage isn't excessive...