Convention

Share

What is a Convention?

The term convention has two meanings:

  1. A way of doings things that everyone agrees with because that makes things easier, just like a standard, but that has never been officially codified or written in an specification like an actual standard. They are rules that aren't actually rules.
  2. An event where people convene, generally about a theme. Some of these events have "con" in their names, like DEF CON.

This article is mainly about the 1st definition.

Unwritten Rules

Conventions are ways of doing things that everyone agrees with because that makes things easier. In many cases, there are many ways to do something, and, sometimes, it's just easier if everyone did it the same way, so knowledge from one project or product transfers to another.

For example, it's by convention that menubars have the items File, Edit, View, Window, and Help, in this exact order. There's no law or rule about it. Everyone just does it this way because it's easier this way and there is no worthwhile reason to do it in any other way.

Sometimes conventions may be solidified into rules. This is very common in programming, when practices from older programming languages become rules in newer programming languages.

Some notable programming conventions include:

  • Constants are spelled in UPPER_CASE_LETTERS.
  • Private fields begin with _an_underscore.
  • Strings that contain text code use 'single-quotes' while strings that contain arbitrary English text for display use "double quotes, just like this". (this has prevented people from using an autoformatter like Python's Black before)
  • All lines of statements inside a statement block must be indented by the same amount of space or tab characters.

Sometimes a convention comes from a rule, but the rule stopped being a rule for so long people have forgotten about it!

  • The color #FF00FF, called "magic pink," is conventionally chosen as a placeholder background color in pixel art that will be turned into a transparent color later. In some older programs, like old web browsers, this magic pink was actually turned transparent when you had a file that didn't support transparency, like a BMP file.
  • The reason why some files in programming projects are spelled with all caps, like README, is because some file browsers used to sort files with filenames in all caps before other files.
  • Conversely, on Linux, dotfiles are files with names starting with a dot (.), like .htaccess, which, by convention, were generally used to configure a program. These used to be normal files, but now they are considered hidden files, hidden by default by various file browsers in Linux.

Comments

Leave a Reply

Leave your thoughts! Required fields are marked *