PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, September 10, 2022

[FIXED] What is the naming standard for path components?

 September 10, 2022     cross-platform, filenames, language-agnostic, path, terminology     No comments   

Issue

I keep getting myself in knots when I am manipulating paths and file names because I don’t follow a naming standard for path components.

Consider the following toy problem (Windows example, but hopefully the answer should be platform independent). You have been given the path of a folder:

C:\users\OddThinking\Documents\My Source\

You want to walk the folders underneath and compile all the .src files to .obj files.

At some point you are looking at the following path:

C:\users\OddThinking\Documents\My Source\Widget\foo.src

How would you name the following path components?

A. foo
B. foo.src
C. src
D. .src
E. C:\users\OddThinking\Documents\My Source\ (i.e. the absolute path of the root)
F. Widget\foo.src (i.e. the relative path of the file)
G. Widget\
H. C:\users\OddThinking\Documents\My Source\Widget\
I. C:\users\OddThinking\Documents\My Source\Widget\foo.src

Here is my attempt:

A. Base name? Basename?

B. File name? Filename? The difference is important when choosing identifier names, and I am never consistent here.

C. Extension?

D. Extension? Wait, that is what I called C. Should I avoid storing the dot, and just put it in when required? What if there is no dot on a particular file?

E. ?

F. ?

G. Folder? But isn’t this a Windows-specific term?

H. Path name? Pathname? Path?

I. File name? Wait, that is what I called C. Path name? Wait, that is what I called H.


Solution

I think your search for a "standard" naming convention will be in vain. Here are my proposals, based on existing, well-known programs:

A) C:\users\OddThinking\Documents\My Source\Widget\foo.src
                                                   ---

Vim calls it file root (:help filename-modifiers)

B) C:\users\OddThinking\Documents\My Source\Widget\foo.src
                                                   -------

file name or base name

C) C:\users\OddThinking\Documents\My Source\Widget\foo.src
                                                       ___ (without dot)

file/name extension

D) C:\users\OddThinking\Documents\My Source\Widget\foo.src
                                                      ____ (with dot)

also file extension. Simply store without the dot, if there is no dot on a file, it has no extension

E) C:\users\OddThinking\Documents\My Source\Widget\foo.src
   -----------------------------------------

top of the tree
No convention, git calls it base directory

F) C:\users\OddThinking\Documents\My Source\Widget\foo.src
                                            --------------

path from top of the tree to the leaf
relative path

G) C:\users\OddThinking\Documents\My Source\Widget\foo.src
                                            ------

one node of the tree
no convention, maybe a simple directory

H) C:\users\OddThinking\Documents\My Source\Widget\foo.src
   ------------------------------------------------

dir name

I) C:\users\OddThinking\Documents\My Source\Widget\foo.src
   -------------------------------------------------------

full/absolute path



Answered By - blinry
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing