变量\属性命名约定
当我为目录命名变量时,我应该以路径、文件夹或目录结尾变量名。
我在 .net 中编写我的代码..
When im naming a variable for a directory should i end the variable name with path, folder or directory.
Im writing my code in .net..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好的,首先一些定义:
C:\Temp\Foo.txt
)或相对路径(..\Temp\Foo.txt
)进行访问。 txt)。 (我也认为文件名(Foo.txt
)是相对路径)。因此,如果变量不明确(即可以指向文件或目录,就像递归遍历目录树时一样),我会将其称为
FooPath
。如果你的变量总是指向一个文件,我会称之为 FooFile
如果你的变量总是一个目录的名称,而不是文件的名称,我会通过调用它 FooDirectory 来反映这一点,或简称为
FooDir
。但当然,最重要的规则是一致性:选择一种命名约定并坚持使用。 不要调用一个变量
FooDirectory
、下一个BarDir
和第三个BuzzFolder
。Ok, first some definitions:
C:\Temp\Foo.txt
), or a relative path (..\Temp\Foo.txt
). (I would consider the file name (Foo.txt
) to be a relative path as well).Therefore, if a variable is ambiguous, (i.e. could point to either a file or a directory, like when recursively walking through the directory tree,) I would call it
FooPath
.If your variable always points to one file, I would call it
FooFile
If your variable is always the name of a directory, and never of a file, I would let this reflect by calling it
FooDirectory
, orFooDir
for short.But of course the most important rule is consistency: Choose one naming convention and stick with it. Do not call one variable
FooDirectory
, the nextBarDir
and the thirdBuzzFolder
.我使用“路径”来指代文件的完整路径(目录+文件名)。 我推荐“文件夹”、“目录”甚至“dir”。
I use "path" to refer to the full path of a file (directory + file name). I'd recommend "folder", "directory" or even "dir".
没关系——所有这些或多或少都是同义词,应该在上下文中清楚地理解。
我要说的唯一警告是,路径可以是网站位置或文件,文件夹和目录不会是其中,如果这有助于您的决定。
It doesn't matter - all are more or less synonymous and should be clearly understood in context.
The only caveat I'd say is that path could be a web location or a file, where folder and directory won't be, if that helps your decision.
对此没有官方的编码约定。
我更喜欢这种风格:
*Path (SystemPath, AppPath) for "C:\Windows\Systems32" or "file://..." or "../../bin/Debug"
*Dir (ImageDir, ThemeDir) for ("img" 或 "theme")
There is no official coding convention for this out there.
I prefer this style:
*Path (SystemPath, AppPath) for "C:\Windows\Systems32" or "file://..." or "../../bin/Debug"
*Dir (ImageDir, ThemeDir) for ("img" or "theme")