{"id":9391,"date":"2006-11-08T03:27:00","date_gmt":"2006-11-08T03:27:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/11\/08\/dont-forget-your-gets-the-importance-of-naming-consistency\/"},"modified":"2019-02-18T13:21:12","modified_gmt":"2019-02-18T20:21:12","slug":"dont-forget-your-gets-the-importance-of-naming-consistency","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/dont-forget-your-gets-the-importance-of-naming-consistency\/","title":{"rendered":"Don&#039;t forget your GETs &#8211; The importance of naming consistency"},"content":{"rendered":"<p>PowerShell and SMO are getting together like chocolate and peanut butter.&nbsp; Yesterday I blogged about&nbsp;Bob Beauchemin&#8217;s TechEd talk about the today and today I see Dan Sullivan&#8217;s PowerSMO blog entry: <a href=\"http:\/\/pluralsight.com\/blogs\/dan\/archive\/2006\/11\/07\/41936.aspx\">http:\/\/pluralsight.com\/blogs\/dan\/archive\/2006\/11\/07\/41936.aspx<\/a>&nbsp;.&nbsp;&nbsp; Dan includes the scripts he used in a ZIP file so you can easily use them.&nbsp; I really liked what Dan is doing with one exception &#8211; his scripts don&#8217;t use the naming standards.&nbsp; In particular, his scripts don&#8217;t use &#8220;get&#8221;.&nbsp; For example, here is how it&nbsp;gets the SMO constructors: <\/p>\n<p>PS C:\\demos&gt; SMO-ctors (SMOT-ManagedComputer)<br \/>ManagedComputer()<br \/>ManagedComputer(String machineName)<br \/>ManagedComputer(String machineName, String userName, String password)<br \/>ManagedComputer(String machineName, String userName, String password, <br \/>ProviderArchitecture providerArchitecture)<br \/>PS C:\\demos&gt;<\/p>\n<p>Cool function but where is my GET?&nbsp; I want to take this example to make 2&nbsp;points:<\/p>\n<ol>\n<li>The community will get the naming consistency it demands.&nbsp;&nbsp; We made the conscious decision to not put an naming enforcement mechanism into Windows PowerShell.&nbsp; That means that we may or may not end up with a consistent set of names.&nbsp; It&nbsp;is&nbsp;our shared responsibility to point out when the naming guidelines are not being used and to respectfully point this out and ask for change.&nbsp; We don&#8217;t need to be butt heads about it but if we don&#8217;t push for consistency, we won&#8217;t get it.<\/li>\n<li>I TOTALLY understand why it is tempting to drop your &#8220;get&#8221;s.&nbsp; It can seem unnecessary and awkward at times.&nbsp; The &#8220;get&#8221; makes sense after you implement the full set of verbs for a noun but you often start with the &#8220;get&#8221; and by itself, it can sometimes seem awkward.&nbsp; <\/li>\n<\/ol>\n<p>So here is the point about &#8220;gets&#8221; &#8211; You should ALWAYS define them but you don&#8217;t have to use them.&nbsp; YUP- that&#8217;s right.&nbsp;&nbsp; We&#8217;ve anticipated this issue and addressed in our design.&nbsp; Let me give an example to illustrate.&nbsp; Let&#8217;s say that you are about to develop a bunch of scripts manipulating&nbsp; NumaNumas&nbsp; (I don&#8217;t know if there is such a thing as a NumaNuma but I had that silly video on my mind ( <a href=\"https:\/\/www.youtube.com\/watch?v=60og9gwKh1o\">https:\/\/www.youtube.com\/watch?v=60og9gwKh1o<\/a>&nbsp;) so I thought I would use it.&nbsp;)&nbsp; Anyway so the first thing you are going to do is to write a script (or cmdlet) which gets NUMAs and you might be tempted to define it as &#8220;NumaNuma&#8221; but DON&#8217;T&nbsp; &#8211; you are not penalized for following the guidelines.&nbsp;<\/p>\n<p>PS&gt; Get-Command *numa*<br \/>PS&gt; <br \/>PS&gt; function Get-NumaNuma {&#8220;Numa Numa baby&#8221;}<br \/>PS&gt;<br \/>PS&gt; Get-NumaNuma<br \/>Numa Numa baby<br \/>PS&gt;<br \/>PS&gt; NumaNuma<br \/>Numa Numa baby<\/p>\n<p>That&#8217;s right, the &#8220;GET&#8221; is optional!&nbsp;&nbsp;The way our command resolution works is that we take the token you specify and&nbsp;look it up.&nbsp; If we find it, we use it.&nbsp; If we don&#8217;t find it, we stick a &#8220;GET-&#8221; in front of it and try again.&nbsp; This means that you can define &#8220;Get-Numa&#8221; and invoke it with &#8220;numa&#8221; &#8211; the best of both worlds.&nbsp;&nbsp; <\/p>\n<p>Let me also quickly point out that if you follow the guidelines, it becomes pretty easy to develop a family of very pithy aliases.&nbsp; Imagine that you have the following commands.<\/p>\n<p>Get-NumaNuma<br \/>Set-NumaNuma<br \/>Export-NumaNuma<br \/>Import-NumaNuma<br \/>New-NumaNuma<br \/>Clear-NumaNuma<br \/>Copy-NumaNuma<br \/>Invoke-NumaNuma<br \/>Move-NumaNuma<br \/>Remove-NumaNuma<br \/>Rename-NumaNuma<br \/>Stop-NumaNuma<br \/>Start-NumaNuma<\/p>\n<p>What you do is to pick a reasonable 2 or 3 letter term for your noun and then leverage our standard aliases for verbs to produce:<\/p>\n<p>&nbsp;gnn&nbsp; &nbsp;Get-NumaNuma<br \/>&nbsp;snn&nbsp;&nbsp; Set-NumaNuma<br \/>epnn&nbsp;&nbsp; Export-NumaNuma<br \/>ipnn&nbsp;&nbsp;&nbsp; Import-NumaNuma<br \/>&nbsp;nnn&nbsp;&nbsp; &nbsp;New-NumaNuma<br \/>clnn&nbsp;&nbsp;&nbsp; Clear-NumaNuma<br \/>&nbsp;cnn&nbsp;&nbsp;&nbsp; Copy-NumaNuma<br \/>&nbsp;inn&nbsp;&nbsp;&nbsp;&nbsp; Invoke-NumaNuma<br \/>&nbsp;mnn&nbsp;&nbsp; Move-NumaNuma<br \/>&nbsp;rnn&nbsp;&nbsp;&nbsp;&nbsp; Remove-NumaNuma<br \/>rmnn &nbsp; Rename-NumaNuma<br \/>spnn&nbsp; &nbsp;Stop-NumaNuma<br \/>sann&nbsp; &nbsp;Start-NumaNuma<\/p>\n<p>The benefit is that it is consistent and therefore easy to learn and remember.&nbsp; If we don&#8217;t press for consistency, we won&#8217;t get it and we&#8217;ll end up in a world that is unpredictable and therefore difficult to learn and remember.&nbsp; By the way &#8211; check this out yourself by running the following commands:<\/p>\n<p>gal g*<br \/>gal *al<\/p>\n<p>So Dan, I love your stuff but please don&#8217;t forget your &#8220;get&#8221;s.&nbsp; <\/p>\n<p>Cheers!<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/MMC Architect<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell and SMO are getting together like chocolate and peanut butter.&nbsp; Yesterday I blogged about&nbsp;Bob Beauchemin&#8217;s TechEd talk about the today and today I see Dan Sullivan&#8217;s PowerSMO blog entry: http:\/\/pluralsight.com\/blogs\/dan\/archive\/2006\/11\/07\/41936.aspx&nbsp;.&nbsp;&nbsp; Dan includes the scripts he used in a ZIP file so you can easily use them.&nbsp; I really liked what Dan is doing with [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>PowerShell and SMO are getting together like chocolate and peanut butter.&nbsp; Yesterday I blogged about&nbsp;Bob Beauchemin&#8217;s TechEd talk about the today and today I see Dan Sullivan&#8217;s PowerSMO blog entry: http:\/\/pluralsight.com\/blogs\/dan\/archive\/2006\/11\/07\/41936.aspx&nbsp;.&nbsp;&nbsp; Dan includes the scripts he used in a ZIP file so you can easily use them.&nbsp; I really liked what Dan is doing with [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=9391"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9391\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=9391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=9391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=9391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}