4 ms·
Regarding case-insensitivity, I'm not referring to user picked names, I'm referring to the whole language. Is it ForEach, Foreach, foreach, or ForEach-Object?
by antoncohen 9y ago
Regarding case-insensitivity, I'm not referring to user picked names, I'm referring to the whole language.
Is it ForEach, Foreach, foreach, or ForEach-Object? Official documentation[1][2][3][4][5] has all four variations. Same for True/False, While, Write-Output, etc. Everything is case-insensitive and the docs can't decide which to use. Again, it kind of makes sense for a shell language when your users are used to case-insensitivity, but I much prefer stricter consistency in programming languages.
[1] https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_foreach?view=powershell-5.1 https://docs.microsoft.com/en-us/powershell/module/microsoft...
[2] https://docs.microsoft.com/en-us/powershell/module/psworkflow/about/about_foreach-parallel?view=powershell-5.1 https://docs.microsoft.com/en-us/powershell/module/psworkflo...
[3] https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-powershell-1.0/ee176828(v=technet.10) https://docs.microsoft.com/en-us/previous-versions/windows/i...
[4] https://technet.microsoft.com/en-us/library/hh551144.aspx https://technet.microsoft.com/en-us/library/hh551144.aspx
[5] https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-5.1 https://docs.microsoft.com/en-us/powershell/module/microsoft...
- ZenoArrow 9y agoForEach is an unusual statement. Depending on the context in which it's used, sometimes it's an alias of ForEach-Object, but sometimes it is not. The following article has more details on this, but one thing that I'd like to highlight now is that one way that ForEach and ForEach-Object can differ from each other is in memory use, as ForEach will load all objects that it's iterating over into memory first before starting the loop, whereas ForEach-Object will not. As suggested before, more details can be found here: https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/08/getting-to-know-foreach-and-foreach-object/ https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/... Going back to the naming conventions, the conventional way to write ForEach is in PascalCase. The variations slip into code as it's also an alias, and aliases tend to be in all lower case, and also because naming convention guidelines are just suggestions, not something that is strongly enforced (Foreach does seem to be commonly used, even if it's not necessarily in the standard styles). Generally speaking, PowerShell coding style is similar to .NET coding style. You can read a discussion about it here: https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/36 https://github.com/PoshCode/PowerShellPracticeAndStyle/issue... By the way, I respect your right to use whatever language you like best, I'm just clarifying that whilst PowerShell may not have it's "PEP-8" or gofmt, there are still conventions that PowerShell coders follow.