The Genius of Verb-Noun in PowerShell
I have always admired much of the design of the PowerShell language. Its simplicity and readability to me are its two greatest features. Something that I think gets overlooked sometimes is the design of the cmdlet names, which use verb-noun in their naming, such as Start-Process. When you start to compare PowerShell against traditional command line languages like bash and CMD you begin to really appreciate how easy PowerShell makes it on the user in terms of usability and learning. The naming of the PowerShell commands provides a way for users to intuitively figure out what cmdlet they need to use and what that cmdlet does. Now, I am not saying PowerShell is BETTER in general than others like bash, but its hard to argue against PowerShell being a more readable language.
Take for instance viewing the processes running on a machine:
On a Linux machine in bash this would be the command top. How do I know this? Well, it’s just something you sort of figure out when using bash, but lets say I just started using Linux and I want to find this, I could search the man pages I suppose:
[root@linuxmachine ~]# man -k "process" awk (1) - pattern scanning and processing language bootup (7) - System bootup process chrt (1) - manipulate the real-time attributes of a process cpupower (1) - Shows and sets processor power related values cpupower-info (1) - Shows processor power related kernel or hardware configurations cpupower-monitor (1) - Report processor frequency and idle statistics . . . . taskset (1) - retrieve or set a process's CPU affinity top (1) - display Linux processes troff (1) - the troff processor of the groff text formatting system turbostat (8) - Report processor frequency and idle statistics xsltproc (1) - command line XSLT processor
Fail.
Scroll, scroll, scroll oh there it is. Top displays Linux processes. Not exactly easy to figure that out though and it is sure as hell not intuitive given the name of the command.
In PowerShell, the cmdlet is Get-Process. If I did not know that and wanted to find I would use Get-Command:
PS C:\Users\dan\Documents> Get-command *process* CommandType Name Version Source ----------- ---- ------- ------ Function Get-AppvVirtualProcess 1.0.0.0 AppvClient Function Start-AppvVirtualProcess 1.0.0.0 AppvClient Cmdlet ConvertTo-ProcessMitigationPolicy 1.0.11 ProcessMitigations Cmdlet Debug-Process 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Enter-PSHostProcess 3.0.0.0 Microsoft.PowerShell.Core Cmdlet Exit-PSHostProcess 3.0.0.0 Microsoft.PowerShell.Core Cmdlet Get-Process 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Get-ProcessMitigation 1.0.11 ProcessMitigations Cmdlet Get-PSHostProcessInfo 3.0.0.0 Microsoft.PowerShell.Core Cmdlet Set-ProcessMitigation 1.0.11 ProcessMitigations Cmdlet Start-Process 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Stop-Process 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Wait-Process 3.1.0.0 Microsoft.PowerShell.Management Application qprocess.exe 10.0.17... C:\windows\system32\qprocess.exe
Or since I know the way the PowerShell designs its cmdlet naming, I can just use tab completion, which is what I do from time to time. I know that I want to display something, so Get is usually what is used for that. I know that I want to display processes, so…
Get. Dash.Process.
Makes sense.
This illustrates one of my biggest gripes with the Linux command-line and bash in general. The commands are really, really not intuitive.
Grep. Sed. ls.
Sure, not hard to remember once you use Linux for a while, but lets call the command naming what it is. Poor design in terms of usability and readability.
PowerShell got that part right.
I was just talking to a buddy of mine about how I love the verb-noun syntax that powershell uses. However, I do have to say, that top in linux doesn’t just show you the processes, and the best way to replicate top in powershell is:
While(1) {ps | sort -des cpu | select -f 15 | ft -a; sleep 1; cls}
which…isn’t very easy to remember.
Exactly.