[英]Variable\Property naming convention
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..我在 .net 中编写我的代码。
I use "path" to refer to the full path of a file (directory + file name).我使用“路径”来指代文件的完整路径(目录+文件名)。 I'd recommend "folder", "directory" or even "dir".我推荐“文件夹”、“目录”甚至“目录”。
Ok, first some definitions:好的,首先是一些定义:
C:\Temp\Foo.txt
), or a relative path ( ..\Temp\Foo.txt
).可以通过文件的完整路径(例如C:\Temp\Foo.txt
)或相对路径( ..\Temp\Foo.txt
)访问文件。 (I would consider the file name ( Foo.txt
) to be a relative path as well). (我认为文件名( Foo.txt
)也是一个相对路径)。 Therefore, if a variable is ambiguous, (ie could point to either a file or a directory, like when recursively walking through the directory tree,) I would call it FooPath
.因此,如果变量不明确(即可以指向文件或目录,例如递归遍历目录树时),我将其称为FooPath
。
If your variable always points to one file, I would call it FooFile
如果你的变量总是指向一个文件,我会称之为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
, or FooDir
for short.如果您的变量始终是目录的名称,而不是文件的名称,我会通过将其FooDirectory
或FooDir
来反映这一点。
But of course the most important rule is consistency: Choose one naming convention and stick with it.但当然,最重要的规则是一致性:选择一种命名约定并坚持下去。 Do not call one variable FooDirectory
, the next BarDir
and the third BuzzFolder
.不要调用一个变量FooDirectory
、下一个BarDir
和第三个BuzzFolder
。
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.我要说的唯一警告是,路径可能是 web 位置或文件,如果这有助于您的决定,则文件夹和目录不会在其中。
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" *“C:\Windows\Systems32”或“file://...”或“../../bin/Debug”的路径(SystemPath,AppPath)
*Dir (ImageDir, ThemeDir) for ("img" or "theme") *Dir (ImageDir, ThemeDir) for ("img" or "theme")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.