Peter
Peter

Reputation: 38455

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..

Upvotes: 0

Views: 987

Answers (4)

Treb
Treb

Reputation: 20271

Ok, first some definitions:

  • A Path is an address within the file system, it can point to either a file or a directory.
  • A Directory can contain multiple files and subdirectories.
  • A File can be accessed via it's full path (e.g. 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, or FooDir 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 next BarDir and the third BuzzFolder.

Upvotes: 4

Michael Piendl
Michael Piendl

Reputation: 2884

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")

Upvotes: 0

annakata
annakata

Reputation: 75794

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.

Upvotes: 1

Dustin Campbell
Dustin Campbell

Reputation: 9855

I use "path" to refer to the full path of a file (directory + file name). I'd recommend "folder", "directory" or even "dir".

Upvotes: 3

Related Questions