header image

Backticks are baaaaaad; don’t do backticks

Posted by: | April 30, 2013 | No Comment |

The voting/judging process has started for event 1 in the 2013 Scripting Games.  What I’m going to be doing over the next few weeks is point out some of the things that I’ve noticed when judging. Some will be good things that I think you should adopt; others will be bad things that you should avoid. There even may be some interesting stuff to get you thinking.

First off is the use of the backtick as a line continuation:

Get-Process | `
sort Handles –Descending

You don’t need a backtick at this point.  The pipe symbol acts as a line continuation marker so the backtick is redundant. All you need to do is this:

Get-Process |
sort Handles -Descending

Its the same with commas. You don’t need to do this:

Get-Process |
select Name, Id, `
Handles, CPU

because it works without the backtick

Get-Process |
select Name, Id,
Handles, CPU

You may see backticks used a lot in books but that is an attempt to reduce the width of the code to make it fit the page. We want you to be able to copy the code from the ebook and run it. The alternative is a line continuation marker which you would have to remove.

Bottom line – 99.9% recurring of the time you don’t need backticks as line continuation markers

under: PowerShell original, Scripting Games