-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capitalization guidelines #36
Comments
I think I agree that Acronyms shouldn't get a pass on capitalization -- especially if they're strung together like that (stop kidding yourself: two capitalized acronyms together = one long acronym). In my head, I thought I was ok with capitalizing acronyms ... but when they run into another capital letter it makes things confusing, so ... I'm fine with |
The .NET Framework design guidelines recommend all caps for two letter acronyms e.g. IO as in System.IO and IP as in IPAddress. Do we want to follow that recommendation? If so the example cmdlet would be |
@rkeithhill: You didn't read my post, did you? :) |
Sorry man, tl;dr I do have a day job ya know. :-) Anyway, I was responding to Joel's recommendation of |
BTW I'll also add that it is going to look funny having a set of recommendations that fly in the face of the existing Microsoft names i.e. all the Hyper-V VM cmdlets that come from Microsoft. Then there all the NetIPAddress, NetIPHttpsConfiguration, NetIPInterface, cmdlets. Seems to me this decision has already been made by Microsoft. |
@rkeithhill Right, as was discussed in my post (where "Joel's recommendation" came from). You could have just responded to the two questions at the bottom of that post and that would have worked too. ;) And FWIW, I don't necessarily think that Microsoft's Acronym casing guidelines were really considering readability when you have multiple acronyms adjacent to one another in a very long string. |
Because who would do that!?
|
I vote for simplicity of rules. True PascalCase for acronyms (Get-AzureVmDscExtension). I'm not sure what is gained by having separate rules for two-character acronyms, other than rule complexity. |
|
For constants I prefer PascalCase. Less noisy/distracting, and different from local variable names. Sure they can look like variable names in global/script scope, and they can look like function/script parameter/argument names, but to be honest, it doesn't make much of a difference since they aren't used as often in PowerShell as they are in other languages. As for the builtin variables like $true, $false, and $PSHOME, I don't think we should recommend changing the case of those in scripts/functions because tab completion will put them in the capitalization as they are defined (unless they have been entered with an incorrect capitalization earlier in the script where they are being used). |
The .NET Framework Design Guidelines have been around for over a decade. I would use these casing guidelines for Identifiers i.e. nouns - https://msdn.microsoft.com/en-us/library/ms229043(v=vs.110).aspx Also, as I previously mentioned, I don't think it's a good idea to come up with guidelines that would fail many of the built-in nouns. I know many folks have their "personal" preference - fine, name stuff using your personal preference but WRT to two letter acronyms - this train left the station a long time ago. I believe consistency in this case is "better than better". WRT to constants, yeah I prefer PascalCase as well. |
My bad for trying to push in the Hungarian notation for constants 😉 @rkeithhill: So, I believe a little flexibility may not be a bad thing. 😄 |
Actually, @sqlchow, I those are capitalized because PowerShell Cmdlet parameters are properties of the underlying .Net class implementations. When we got the ability to write advanced functions in PowerShell code, we used PascalCase for parameters so they would match the class-based commands... |
@Jaykul thanks for letting me know 👍 I was under a completely different assumption until now. This clears up a few things for me. Then I will go with @rkeithhill 's suggestions for using .NET naming conventions for two letter acronyms. |
I agree with the eg: Here is what I would like to see for variables:
Variable naming is by far the MOST important component of readable code... and please someone put an end to:
This is horrible--- stop being lazy and just write $Card or $EachCard!
|
When you add these guidelines, I would prefer to see them formatted as a table, so that I can see the cases by looking down a single column. For example:
I initially had "Examples" and "Notes" as two separate columns, but decided to combine them. I understand some people might have reservations about my use of I know there's some redundancy between the Case column and the examples. I can live with that. Although what I'd prefer is for the examples to be more specific than
Update: I've given in to temptation 😄 and made the Item values singular. I've also, after revisiting the Microsoft .NET Capitalization Conventions, changed the Item column heading to Identifier, and removed the (to me, redundant) "name(s)" suffix from the values. I baulked at replacing Case with Casing. Perhaps I'd change my mind after a glass of Kool-Aid followed by a double shot of Victory Gin. I've also hyphenated the compound adjective "mixed-case". I need a drink... I considered the following column layout for readability:
but rejected it as too onerous and error-prone for editing. |
Like the idea of the table. Many people use code snippets included in ISE and in Visual Studio Code, in some cases they don’t match each other should we consider also making some of this style guide recommendations optional? Case that comes to mind is the process block and comment block keywords.
|
Minor correction: change |
Compare: Microsoft .NET Framework Capitalization Conventions with: Google Style uses the terms upper camel case and lower camel case. I believe that upper camel case and Pascal case - or, if you prefer (I don't! 😄 ) PascalCase - are synonymous. (Please correct me if I'm wrong.) While I like the "(nearly) deterministic" nature of the Google scheme, I think that PowerShell should follow the .NET conventions because of their close relationship. Here is the value of the
According to the .NET conventions ("A special case (sic 😄 ) is made for two-letter acronyms in which both letters are capitalized"):
whereas, according to Google (no such special case):
|
Ugh, I still prefer no special case, despite standards that I usually try to follow. When the examples are short like what you showed above representing something that looks like property names or variable names, it isn't that big a deal; however, in PowerShell it is not uncommon at all to have multiple adjacent acronyms, and when there are two-letter acronyms among those that are adjacent, the identifiers just become fugly. Some examples that may or may not be real PowerShell commands:
The biggest problem IMHO is that this special case rule is going to be missed by the vast majority of command authors out there, who have already demonstrated difficulty in understanding why nouns should not be pluralized, ever. Standards do need to evolve/adapt as needs change, and as mentioned earlier, it is very doubtful that this standard came about with thoughts toward what multiple adjacent acronyms in a single identifier would look like. It certainly wasn't created as a standard for scripters-not-developers to follow. For this community, I still feel the only successful path forward wrt command names is to keep it as simple as possible, and keeping it simple means no special case for acronyms regardless of how many letters they have, just as there is no special case for pluralization of nouns. That's a much easier battle to fight (even though it is still difficult to make others understand that -- heck, there are still plenty of PowerShell MVPs who use pluralized nouns in their work), and it is much more likely to be adopted if acronyms are always handled the same way (have a look around for how many commands there are that have acronyms with more than 2 letters that are all capitalized -- there are plenty). Consistency and ease of use (having it easier to follow) within the PowerShell command set is more important than adhering to this piece of the .NET standard that seems questionable. |
Except for one particularly important author - Microsoft! Frankly I think it would look silly to adopt a convention that many of the built-in commands will fail. It is obvious that Microsoft is following this .NET FDG rule for all of the AD, BC, VM and IP related commands.
This is not about what @KirkMunro personally does not like. ;-) |
I know it's not about me personally. I'm not the only one who doesn't like this for PowerShell. I'm just being more vocal about it.
You're kidding, right @rkeithhill? Microsoft publishes commands with pluralized nouns and misses naming standards, even when it comes to acronyms. All. The. Time. You can point to the AD, BC, VM, and IP related commands, which for the most part follow the standard except for some exceptions. But there are plenty of commands that come from Microsoft that don't follow said standard. Here is a sampling of examples from Microsoft modules on my Windows 10 system that don't follow the standard you're proposing: From the PowerShellISE-preview module: From the Azure module: Azure.Storage: All AzureRM.* modules: BranchCache module: CimCmdlets module: Defender module: Dism: MSOnline: NetAdapter: NetEventPacketCapture: netsecurity: NetTCPIP: NetworkConnectivityStatus: SecureBoot: Storage: WebAdministration: SQLPS: There are definitely others as well in modules I simply don't have installed. |
I think it's preferable to avoid the special case for capitalization of two-letter acronyms. I'm aware of the .Net conventions that @rkeithhill is referring to, but disagree with them simply because there is no reason given as to why these need a special case. @KirkMunro is absolutely right that these types of special case rules are hard to justify and endorse. That said I have used this convention myself simply because there has always been a lack of a set of guidelines like this project, but now is our chance to break from tradition. |
@KirkMunro I'm only referring to the two letter, upper case example. The vast majority of your examples demonstrate improper casing of Sure, there are some badly named cmdlets. But those are not the examples we want to follow, right? Or perhaps we can't agree those are examples of doing it "wrong"? Sigh... FWIW I don't believe some "bad" examples of deviation from the "norm" within the set of built-in commands provided by Microsoft makes a good argument for declaring the "norm" as wrong. WRT to the rest of the casing rules - I'm in agreement. Maybe this rule (2 letter acronym special case) is too subjective (like line length) where we can't agree on a standard recommendation. I know I will continue to follow the established norm as I see it as established by Microsoft. And I highly suspect the majority of Microsoft commands will continue to follow the 2 letter acronym upper case rule. Now if Microsoft adopts a different policy WRT to this rule, I'll happily switch to that. :-) |
@mattmcnabb RE:
I good friend and manager of mine (now passed) used to say It would be one thing if PowerShell had just started in Beta and we were starting this from "scratch" - feeding back to Microsoft what casing conventions we wanted them to use for commands. But we are not. As @KirkMunro points out, Microsoft is not terribly consistent mainly because you have teams other than the PowerShell team contributing commands. However the PowerShell team set the standard when they shipped: Frankly, for the "community" to recommend against the "defacto standard" is rather silly IMO like trying to close the barn door after the horses are all gone. :-) |
@rkeithhill You're right about the *-MMAgent commands. I built that example list quickly, and left a few commands in that I shouldn't have. I edited the list above removing those that shouldn't be there. I agree with following standards. I stray because I'm not 100% convinced that the .NET guidelines/standards are the PowerShell guidelines/standards. We're looking at one example: capitalization. But PowerShell has its own guidelines/standards, and in those standards they don't even talk about capitalization. Back in the PS v1 days, there were some commands with acronyms (-PS commands), and Quest created the -QAD commands (while working with Microsoft because they were filling a gap), without any specific mention of a capitalization standard. The norm (not the standard) at that time seemed to be to capitalize all acronyms, regardless of length. Other groups inside Microsoft also used all caps for acronyms, and also regardless of their length, particularly in the System Center set of servers, and many of those are still around. So from my perspective, you're pointing to .NET guidelines and saying "that's the standard" when the community/Microsoft hasn't even come out with a standard for this yet, so as far as .NET guidelines go I'm saying "that is a standard, but it isn't necessarily the standard for PowerShell" command names. In deciding upon a standard to use (since we're developing best practices here) it is worth considering all pros/cons and making sure we make the right choice. PowerShell is built on top of .NET, but the .NET aspect of it is only an implementation detail to many -- it isn't quite like other .NET programming languages. While I wish PowerShell were a programming language, is really is just a scripting language -- different rules, different use cases, plenty of issues that make it fall apart when programming is concerned. Does PowerShell also follow all of the rest of the .NET guidelines that you're pulling this out of? Or only this one, and only for a decent-sized subset of commands that come in Windows, while hundreds of others also from Microsoft that aren't shipped with Windows don't follow this particular capitalization "standard"? No matter which way this issue goes, it's messy because there are plenty of commands on either side of the fence that would then be seen as out of compliance with the standard, so we should make the right choice for PowerShell, not by cherry-picking one portion of a larger standard that isn't even adhered to in Microsoft-produced modules and that might not be best applied to PowerShell, but by picking the best choice for PowerShell going forward. |
Just a remark. Presumably, .Net names of stuff will leak to PowerShell when it uses some libraries. So if these names follow .Net naming (likely) then it will be easier if PowerShell naming is the same. It would be annoying and confusing to change capitalization just because PowerShell follows different rules. |
@KirkMunro So you'd propose that these commands:
should be cased like this:
I dunno. These commands may be few in numbers but some of them are bread & butter (core) commands. That aside, can we all agree that all the other casing rules (except for 2 letter acronyms) are good? Well OK, there is another one that should be discussed and that is |
I think all other casing rules are agreed upon, but you brought up a valid point about comment help keywords. Not only are they displayed in ALL_CAPS in the help that is generated, and in platyPS, but they are applied in ALL_CAPS in about_comment_based_help (https://technet.microsoft.com/en-us/library/hh847834.aspx) as well. With that being the case, it seems that ALL_CAPS is the way to go for comment-based help keywords. Disclaimer: I already use ALL_CAPS for comment-based help keywords, but I believe my comments here to be unbiased. :) Believe it or not, I'm on the fence for the command name capitalization standard, because I don't see a clear winner in either case, and because there are enough arguments that are good on both sides. Maybe we should put it to a vote on Twitter for a week and go with the winner. Either that or ask Microsoft to step in and declare their wishes as far as a capitalization standard goes. Or both. I'll reach out to someone who I think may help make that decision so that we can move forward on this, because I think the community will be much better off with a well defined standard for command naming that includes capitalization rules. |
I second the ALL_CAPS in comment-based help keywords. The reasoning is that because the help will be a string, there is no syntax highlighting to help the eye differentiate the help text from the keywords. ALL_CAPS helps you scan to find the keywords. I also like to make sure that I have spaces before each new keyword, but that's not germane to this topic. |
@KirkMunro Sounds like a plan. I definitely recommend reaching out to Microsoft (ie the PowerShell team). |
For the general naming (ignoring the help), the proper answer for PowerShell has been to align with the .Net coding guidelines. This has been true for a while (see: https://msdn.microsoft.com/en-us/library/dd878270(v=vs.85).aspx). As for what that means, it's what's cited in the .Net casing reference in MSDN (https://msdn.microsoft.com/en-us/library/ms229043(v=vs.110).aspx) that treats acronyms as words if they are longer than 2 characters. 2-Character acronyms are left as caps. |
Did anyone reach out and hear back from the PowerShell team? It's been a few years. |
So what you're saying, @nogeekleftbehind, is that the docs don't follow any style standard at all? Unfortunately, the PowerShell team has never been willing to follow this guide, and they have published different guides for each project they manage -- so it's hardly surprising that they can't maintain consistency in the docs. 😑 I filed MicrosoftDocs/PowerShell-Docs/issues/5467 because I think that at least within the same page they need to follow the same standard. For what it's worth, we have said this (emphasis mine):
But I would never let that code example you linked to through a code review, because of the inconsistency. Use camelCase or PascalCase for private variables -- but not both. P.S. Ugh. Allman Braces... |
So, there was a useful post by @Jaykul on #17 that got lost amid some debates that were not relevant to that specific discussion. This just came up again for me while watching a live demonstration where I realized I really didn't like the capitalization guidelines they followed, so I thought I'd try to refocus the discussion on this since we never did come to a consensus.
Here is Jaykul's post on this (slightly modified to remove points of contention that derailed the other issue), copied so that you don't have to go look it up:
I am 100% in agreement with all of this (now that I took the distracting parts out 😉).
The only place where I have any question here is around case sensitivity with acronyms, which was not called out. According to the Microsoft standard for PascalCase and camelCase, if an acronym is two letters then you don't change the case, but if it is three or more then you do. That results in command names that look like this:
Get-AzureVMDscExtension
Get-AzureVMDscExtensionStatus
Publish-AzureVMDscConfiguration
Remove-AzureVMDscExtension
Set-AzureVMDscExtension
My brain has a really hard time delineating between VM and Dsc in those command names. I always see VMD sc. Personally, I follow these same PascalCase/camelCase rules, but for acronyms I always put every character beyond the first as lowercase, to make the identifiers more readable. For example, I would have named all of the above commands like this:
Get-AzureVmDscExtension
Get-AzureVmDscExtensionStatus
Publish-AzureVmDscConfiguration
Remove-AzureVmDscExtension
Set-AzureVmDscExtension
If I was to place an exception on anything related to acronyms, it would be PS, because, well, PowerShell. Either that or I would modify Microsoft's rule, indicating that you only maintain case on an acronym if the acronym is 2 characters long, and when maintaining case any acronyms immediately after that one must use the same case. With that, the commands would instead look like this:
Get-AzureVMDSCExtension
Get-AzureVMDSCExtensionStatus
Publish-AzureVMDSCConfiguration
Remove-AzureVMDSCExtension
Set-AzureVMDSCExtension
There are examples of this in native PowerShell cmdlets as well, but for those examples, the acronym is at the beginning of the noun which seems easier to identify than when it is in the middle with mixed case acronyms side by side.
Anyway, we should explicitly decide how we want acronyms to be cased when using Pascal or Camel case. My vote would be to always make every character after the first in acronyms lowercase (like I show in the second example above), but I'll follow whatever the community decides, and I realize it would probably be best if we simply followed Microsoft's guidelines for consistency here (even if I don't like them).
So, to keep it simple, two questions:
The text was updated successfully, but these errors were encountered: