File naming conventions

Introduction #

In the day to day work of programming, one often finds that a large fraction of time is spent looking for certain files. One of the wise adages with managing an assortment of files is to provide an organization scheme to make it easier to find what you need again. It not only helps you as the maintainer, but also helps your reader(s)** and collaborator(s) as well. This is a good habit to devleop before you find yourself managing hundreds of files.

Motivations for naming files well #

  • It is more efficient to name your files correct such that it’s easier to find.

  • With the correct file extentions it is easier to collaborate with another programmer.

Organizing your directory #

A developer also considerrs file organization and directory naming schemes as well. There’s no industry standard for this, just an organization level (if you join a team with a style guide), however there tends to be some common patterns to follow.

When you have a lot of tiles in your project directory, it is common to start thinking about the organization of contents.

The scheme itself can depend on the type of project. For example, if you’re working on a web application you might split into layers such as the back-end from front-end features.

Common File extensions #

Language File Extension Example Rules & Conventions
Java .java Main.java - File name must match the public class defined in the file
- Usually CamelCase
C++ .cpp main.cpp - C++ Programming File Organization1
Python .py main.py - Often lowercased
- Pep8 Style Guidelines2
Scheme .scm main.scm - Guile Scheme Manual
- §6.18.5 Compiling Scheme Code3
Markdown .md, .markdown foo.md - Markdown Syntax4
HTML .htm, .html index.html - Hypertext Markup Language
- Include doctype
CSS .css style.css - Cascading Style Sheets
XML .xml pom.xml - Extensible Markup Language
JavaScript .js script.js
Haskell .hs Main.hs
Shell Script .sh build.sh - add a shebang at the the top, #!/bin/sh

Common Directory Names #

  • /src - for your packages & classes
  • /test - for unit tests
  • /docs - for documentation, generated and manually edited
  • /lib - 3rd party libraries
  • /etc - unrelated stuff
  • /bin (or /classes) - compiled classes, output of your compile
  • /dist - for distribution packages, hopefully auto generated by a build system

from https://stackoverflow.com/a/8594

Ignoring files with your VCS repository #

If you’re using Git you can specify a .gitignore file that contains a list of filenames to ignore


  1. C++ Programming/Programming Languages/C++/Code/File Organization. (2020, April 16). Wikibooks, The Free Textbook Project. from https://en.wikibooks.org/w/index.php?title=C%2B%2B%5FProgramming/Programming%5FLanguages/C%2B%2B/Code/File%5FOrganization&oldid=3676078. ↩︎

  2. PEP 8 – Style Guide for Python Code https://www.python.org/dev/peps/pep-0008/ ↩︎

  3. Guile Reference Manual https://www.gnu.org/software/guile/manual/guile.pdf#page=406&zoom=100,0,96 ↩︎

  4. Markdown: Syntax https://daringfireball.net/projects/markdown/syntax [1]: https://libraries.mit.edu/data-management/store/organize/ [2]: https://docs.python-guide.org/writing/structure/ [3]: http://opensource.guide/starting-a-project/#launching-your-own-open-source-project [4]: https://medium.com/@msandin/strategies-for-organizing-code-2c9d690b6f33 ↩︎