Sep 14, 2017

Don't use spaces in names of files, objects, etc.

Don't give objects names with spaces in them. Spaces are used to separate words. Names of objects should be single words. Object names are metadata about the object, and that metadata may need to be used by another person or system in ways you did not anticipate. Save the detailed grammatically correct wording for descriptions and comments.

Different systems handle spaces in different ways, and some don't even allow them. Avoiding them completely eliminates an entire class of possible errors when working across platforms or environments

Spaces in object names lead to inconsistency. Inconsistency leads to errors. 
  • Spaces are interpreted as word separators by many editing shortcuts. Using them reduces efficiency and contributes to errors when editing source code
  • Spaces may be ignored or treated differently than you expect when searching, sorting, etc.
  • Some systems will automatically change spaces into other symbols, such as underscores, other systems may simply remove the spaces. Still others will allow the spaces. Inconsistency leads to errors 
  • Spaces are interpreted as argument delimiters by command lines
    • Even if you yourself never use a command line, someone else may need to do so
    •  Some GUI software may use command line interpretation behind the scenes that you are unaware of
  • Spaces in names must be escaped when used in URLs, but there are multiple ways to escape them. Inconsistency leads to errors.
  • Using spaces in a file name may require that the name be surrounded by quotation marks in order for it to work with parsers or command line tools. The fact that you have to use quotes then itself leads to more problems
    • One system requires single quotes, another uses double quotes, a third accepts either, but with different meanings
    • Quotes get nested within other quotes, have to be escaped
    • Different databases have different rules for escaping strings
    • Different platforms have different support for Unicode and ANSI character sets
    • Some programs (MS Office for example) will automatically change quotation marks into special symbols (Smart Quotes)
    • Symbols in URLs must be escaped differently than those used in other contexts (command lines, database keys, etc)
It all gets very complex very quickly. You can completely avoid an entire class of confusing errors and problems by simply avoiding spaces in names.
 
  1. Best option:Use only letters and numbers, no spaces or special characters. Use camel case for improved readability
  2. Mediocre option: prohibit spaces, but allow other symbols (typically underscores) to take their place
  3. Terrible option: Make long names with lots of spaces, laugh like a supervillain at the pain you are causing others

No comments:

Post a Comment