Used Variable Cases In Code

In programming languages, we use variables to get rid of the hard-coded text. But naming variable is a huge deal in coding. So programmers give too much attention to the variable naming as it is important for readability of the code.

We can name variable with those cases:

1. Camel Case
2. Pascal Case
3. Underscore Case

Camel Case

Camel case came from the camel shape. We start the variable with a small letters then for each following word, we capitalized the first letter. For example this is camel case variable (justSmallVariable).

Pascal Case

Pascal case is when we capitalize first letter of each word like (JustSmallVariable).

Underscore Case

But underscore case is when we separate each word in the variable name with an underscore character such as (just_small_variable).

Those cases are the dominant ones for the variable naming in all programming languages. But there is some other rules and accepted behaviors in coding.

1. ALL CAPS CASE for constants such as (CONST_PI).

2. One letter variables for local scope ones such as the iterating factor or variable in for loop. For example i or j.

3. long clear variable for global scope or package scope variables such as (currentWindow).

4. double letters for local variable of array such as (dd) or (ff) which means there is more of d (or more of f).

I hope you learn something. If you want to get new posts, make sure to subscribe to Value In Brief by Email.

Post a Comment