-4

I have a program that produces a command line tool called GetFood. The source code lives in a directory named GetFood/, and I have a main file that interacts with a class that gets the food. It seems to make the most sense to name the class "GetFood" since it provides all the functionality of actually getting the food, but this also forces the name of the file to be "GetFood.x".

Is this bad practice considering that the directory is also GetFood, or should I rename the directory?

  • 1
    GetFood is a verb rather than a noun, so I don't like the idea of using it as a class name. Something like FoodGetter or Chef or PizzaDeliveryGuy would be better. – Andrew Piliser Oct 6 '17 at 17:40
  • 3
    How you name your folders and files is entirely up to you. The operating system couldn't care less. Whether it's a good idea from an organizing perspective is another matter. – Robert Harvey Oct 6 '17 at 18:30
0

In general it is quite a usual practice to call the top level directory the same name as the program and to use the same name, (with an appropriate extension), for the "main" top level file. Some tool chains also had/have a tendency to put the main into a file with extension and then all of the lower level files into a directory of that same name.

I find that most tools and definitely the OS don't much care what the files & directories are called, within some constraints, but to avoid problems all directory & filenames should be ASCII letters and numbers plus possibly the characters +-_ avoid all spaces so that you don't have to quote or escape them and other characters such as &<>|/ as they have special meanings on some platforms. Also don't rely on the platform being case sensitive or insensitive, i.e. It is fine to use case to distinguish parts of names such as MyFileName but don't have another file called myFileName and use the matching capitalisation everywhere.

Personally I like the python practice & magic of having a directory that encapsulates a module and has the module name that contains a "main" file called __main__.py that defines the behaviour when the module is invoked, (using python -m modulename), and another called __init__.py that, you guessed it, performs all initialisation operations on an import as it is instantly clear what these files do and they appear first in the directory listing on most systems.

The main things are clarity and organisational consistency. These are the things that allow for people to do their work easily - a pet hate is when I am looking at someones code, (even my own), and I have to grep main to find the entry point(s).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.