-
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
Command Prefixes #23
Comments
Some facts (if I am not mistaken, double check would not hurt).
Something was amended in 4.0:
Thus, it looks like if I want to support 2.0 or if I want the same behavior for 3.0 and 4.0 then I should not use |
I have added the word Sec as a prefix to all functions and files that I create for PoshSec. I could go back and remove them and have the module manifest pick them up. This is mostly right now for v2 compatibility. However, I am probably moving in a direction to move away from V2 support to take advantage of some of the language benefits of later releases. I think we should use the prefix’s but put a note in for v2 compatibility this might not be wise. |
The issues that are identified above are exactly why I recommend very strongly against adopting this style until v4 becomes the community baseline. The bugs/discrepancies between v3/v4 on manifest defined prefixes are such that this feature should be avoided for all modules that will work on v2 or v3 IMHO. Plus, thinking about the large number of script or command authors that won't think about version when they create and share content, I prefer erring on the cautious side, so that their content has a better chance of working in downlevel versions as is, consistent across versions. All that said, if the vote is against me then my only request is that manifest-defined prefixes is listed as a recommended style specifically for modules that require PSv4+ due to the bugs in v3. |
I guess that brings up a good point, should the docs be based on PS versions? i use to avoid the defined prefix because i had run in to problems with it in V3, but with V5 (using it for psgit) it seems pretty ironed out.. |
Frankly, I really dislike prefixes. I always have. I would much rather just make people type Using "SecNoun" when I mean "Noun from the PoshSec module" breaks about a quarter of the usefulness of nouns, and isn't guaranteed to make it unique anyway, because unlike module names which are unique because they have to go in the file system, and because PowerShellGallery will enforce it 😜 prefixes don't have any guarantee of uniqueness at all. For what it's worth, I don't think most people can write code to target PS2 (you have to have PS2 to target it, if you're just testing with PS4 and In any case, PS2 was so long ago that I do not want to take it into account in the style guide, but I do think it's worth at least mentioning in the Best Practice stuff (like this), and even suggesting an alternate best practice for people who want to target it. I don't even want to talk about prefixes, but since the Microsoft Team has required people to use prefixes, but completely failed to address the issues (in fact, I think they're lying about insisting on the use of prefixes "from the very early days"), I think we have to. They don't even mention that there's a module manifest way of specifying them, or that users can specify their own prefixes at import time. Bottom line, I think we have to document what @nightroman wrote, and then recommend hard-coding the prefix if you need to support PS2 (or PS3?). Is there actually any reason the fully-qualified name difference matters? bothers you for PS3 -- not sure why it would, if you're using prefixes it's because you don't expect people to type the full name, right?). We've got some consultants here right? Have any of you ever seen people using the fully qualified |
I have created some modules for our company, for internal use. Other departments are on the edge of creating modules, and I have made a template for internal modules. Why invent a wheel twice? We have had some nasty problems with duplicate commands, so in the template I use a default prefix. This "guides" others to use the prefix. (Most of them just don't bother for any name convention) So I was a big fan of prefixes. Now I ended up here, while trying to make the code compatible for PowerShell 2. At this point not sure if we 'leave the old servers behind', or put a lot of effort in making the code work for PowerShell 2. @Jaykul: I have never seen someone using |
Considering Microsoft is deprecating v2 do we still need to consider v2 in this issue? Also, when I write a module I expect to be used by a lot of folks I usually module-name prefix commands so that I'm sure I'll get the built-in command instead of someone's poorly written proxy. Seen a few too many bugs due to command proxies. |
My feelings about this have changed a bit in the last two years, but frankly, deprecating PS2 (or even PS3) doesn't figure into that. So here's a few random thoughts: Microsoft hard-codes the prefixes into their command names.They do this for everything. Even when the module name is, say, "AzureRm" and your prefix is "AzureRm" -- how is If you rely on
|
But even then, someone could create aliases and redirect your command invocations (because you can create aliases that look like fully qualified names). Just mentioning that because it comes as a surprise to most folks. Personally I still recommend prefixing every command. I suspect I won't change that stance unless/until PowerShell provides a way to control the priority used in command name resolution via a using statement (e.g. |
It's true that basically anything can be stepped on in PowerShell -- if it's deliberate. Even properties and methods: Update-TypeData -TypeName System.String -MemberName Length -MemberType ScriptProperty -Value { 0 } |
A few years later, and this just came up again for me. I'm watching a video talking about the alpha Microsoft.Graph module that uses AutoRest to generate over 2000 commands in dozens of auto-generated modules. This module bundle highlights one key thing that prefixes have that fully qualified command names don't: the ability to use one constant prefix across many modules. Looking at the most recent updates of the Az module, all cmdlets are prefixed with Az, no matter which module they come from. That model supports faster loading time (only load the modules that are actually required) while maintaining prefix consistency across a very large set of cmdlets that spans many modules. On the flip-side though, some auto-generated cmdlets have very long names already, so prefixes really should be kept short. Like 2-4 characters short. Otherwise, they're just adding more noise to a very noisy command set. Also, what would you pick for an prefix for commands in Or maybe we should just do away with module names and nouns altogether, and just use emojis since they are supported in modern consoles. ☁️\Get-👤 etc. 🤣 |
First of all, as far as IpMo AllOnes
Get-Number # calls AllOnes\Get-Number
IpMo AllTwos
Get-Number # calls AllTwos\Get-Number
Ipmo AllOnes
Get-Number # calls AllOnes\Get-Number
AllTwos\Get-Number # calls AllTwos\Get-Number In my opinion, the Azure modules are a great example of why prefixes are awful.Although I'm glad it's "Az" in place of "AzureRM" now (
On top of that, the
Ultimately, the prefixes aren't applied consistently. A few of the modules, like Hypothetically, it's good they're shipping a collection of modules rather than a single module, but the prefix has nothing to do with that. Not having a prefix isn't going to force anyone to publish only one module. In fact, the net result of the prefix is that it leads people down the wrong path: they write scripts calling functions from multiple modules and don't even know which modules they're using, so they don't import them explicitly -- nor document which ones they are using, so you have to install "Az" (all 120 modules worth of it) and load the modules implicitly on-demand, resulting in slower scripts. |
For example: nmo -name Test1 {function Get-Thing {'Thing1'}} | ipmo
nmo -name Test2 {function Get-Thing {'Thing2'}} | ipmo
Get-Thing # returns 'Thing2'
using module Test1 {
Get-Thing # I want this to return 'Thing1'
}
Get-Thing # This would return 'Thing2' again That doesn't work though, because as you point out, As for all of the rest of the comments you made @Jaykul, while I would prefer a world without prefixes, I don't believe that no prefix is a realistic option given what we have available today as a way to define the module we want to use in scripts/functions, which is amazing given that modules came out in 2009 -- 10 years later, and it's still quite messy. |
Should we be embedding Command Prefixes in function names, or using the PSD1 to specify the default?
I'm going to start this debate by saying that I think putting prefixes into the code is wrong.
The counter argument seems to be that "ADUser" and "ADGroup" are actually nouns, not just nouns with a module prefix, and I guess I would be OK with that -- but that should be the distinction you make, and the bar you set for hardcoding a prefix: the prefixed noun should be so obvious that it's discoverable, and that all of your users will intuitively know to search for it. E.g.; "ADUser" might be ok, but "QADUser" isn't 😉
The text was updated successfully, but these errors were encountered: