Keep it Simple

One of the principles I’ve always tried to stick with when writing code – in PowerShell or any other language – is Keep it Simple.

Keeping code simple makes it easier to understand, easier to debug and easier to maintain. My definition of simple code may not be the same as yours but by and large simple code is easier to work with. When I was judging Scripting Games entries it was always easier to work with answers that were written in a simple manner. That doesn’t mean they were crude or badly written – it means they were written in a manner that was easy to understand.

Creating a PowerShell pipeline tends to produce a simple solution – the badly, and incorrectly, named “one-liner”.

Complications seem to creep in when solutions start using aspects of the PowerShell language. Loops and simple branching structures (if & switch) should cover most if not all your needs – I’ve seen many complications arise when multiple nested if statements are used or huge conditions used with multiple nested AND/OR statements – try and simplify.

Still not convinced for the new language features such as ternary conditional, null coalescing etc but PowerShell is now open source so if you shout loud enough you’ll get it added to the language.

Whatever your code, coding standards or goals keeping the code as simple as possible will pay off in the end.

This entry was posted in Powershell. Bookmark the permalink.

1 Response to Keep it Simple

Leave a comment