DEV Community

Cover image for Variable Naming Conventions
Merdan Durdyyev
Merdan Durdyyev

Posted on

Variable Naming Conventions

Which variable naming convention do you prefer ?

There are various variable naming conventions in use. Some programming languages, libraries, frameworks definitely set a standard and make you get used to that certain one. Others just advise you or give you a choice in terms of convention over configuration. And in some of them you are free to use any of them.
So just to look through them and remember some older conventions, take a look at the list below.

  • twowords (flat case)
  • TWOWORDS (upper flat case)
  • twoWords (lower camelCase)
  • TwoWords (upper CamelCase, sometimes PascalCase - coming from Pascal PL)
  • two_words (snake_case)
  • TWO_WORDS (SCREAMING SNAKE_CASE, CONSTANT_CASE - as all uppercase is mostly used for constants)
  • Two_Words (Camel_Snake_Case)
  • two-words (kebab-case, dash-case, lisp-case: coming from Lisp PL)
  • Two-Words (Train-Case)

There might be other variable naming conventions, but these are mostly known ones around developer community.
There are some other additions that might be useful, like adding extra info in the variable name, like type of the data to be stored in variable. This is less common nowadays because modern programming languages seem to be less strict to type of the variable. Anyway, in those old days, when it was a must for any variable to have certain data type, they looked like this :

// an integer type variable
var iAge;

// a character
var cLetter;

// a float type variable
var fWeight;
Enter fullscreen mode Exit fullscreen mode

This is an example from Pascal programming language. Anyway, it was a good tip to use, as it was possible to immediately see the data type to be stored in that exact variable.


Looking at the list above, I can conclude that mostly used variable naming conventions are "camel case" and "snake case" in many of their variations.
So are you sticking to certain ones or do you change it according to the tools (programming language, library, framework) you use ?
What is your preferred variable naming convention ?

Top comments (0)