关于Powershell函数在大小写方面的命名约定是什么? [英] What is the naming convention for Powershell functions with regard to upper/lower case usage?

查看:190
本文介绍了关于Powershell函数在大小写方面的命名约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我确实在

While I did find a lot of information on how to name Cmdlets and functions in the Cmdlet Development Guidelines I did not find any information on whether functions should be named in upper or in lower case.

这里的惯例是什么?

(我知道Cmdlet本身通常以大写形式命名,即使它们在执行时不区分大小写.)

(I do understand that Cmdlets themselves are generally named in upper case, even though they are not case-sensitive when it comes to executing.)

推荐答案

命名约定可能很棘手.虽然固定的命名约定可以提供美观或简化的用法,但不需要遵循该约定.通常,我主张的一种命名约定是Powershell中已经使用的一种约定.由于功能是基于动词-名词创建的,因此每个单词都以大写字母开头,或者如果是缩写,则全部以大写字母表示,或者如果是专有字母,则相应地以大写字母开头.

Naming convention can be tricky. While a fixed naming convention may provide aesthetics or simplified usage, it is not required to be followed. In general, a naming convention that I advocate for is the one that is used already in Powershell. As functions are created on verb-noun base, each word starts with a capital letter or if it is an abbreviation - all capitals, or if it is a proprietary - then as it is accordingly.

例如,我已经为自己创建了一些功能:

I have, for example, created some functions for myself:

Get-ServerDiag
Mount-TrueCryptVolumes
Start-RDP
Generate-RandomPassword
Nuke-Environment

您可以想象这些功能的作用,它非常清楚,直接且与内置Powershell功能兼容.但是,我确实有一些例外,这些例外来自将"几个Unix命令导入"到Powershell中(例如killallpidof等...).如果您喜欢编写其他内容,则可以始终使用Set-Alias.

You can imagine what these functions do, it is rather clear, straightforward and compliant with built-in Powershell functions. I do however have exceptions which come from "importing" a several Unix commands to Powershell (like killall, pidof etc...) You can always use a Set-Alias if you prefer to write something else.

这个问题,无论多么重要,都是可以讨论的,因为似乎没有唯一的最佳方法".归根结底,这取决于个人喜好.

This question, however important, is discussable as there does not seem to be the 'one, best way'. It is all, in the end, up to personal preferences.

这篇关于关于Powershell函数在大小写方面的命名约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆