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 - File name must match the public class defined in the file
- Usually CamelCase
C++ .cpp main.cpp - C++ Programming File Organization1
Python .py - Often lowercased
- Pep8 Style Guidelines2
Scheme .scm main.scm - Guile Scheme Manual
- §6.18.5 Compiling Scheme Code3
Markdown .md, .markdown - 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 - 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


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 ↩︎

  2. PEP 8 – Style Guide for Python Code ↩︎

  3. Guile Reference Manual,0,96 ↩︎

  4. Markdown: Syntax [1]: [2]: [3]: [4]: ↩︎