DEV Community

Cover image for under_scores, camelCase and PascalCase - The three naming conventions every programmer should be aware of

under_scores, camelCase and PascalCase - The three naming conventions every programmer should be aware of

Prahlad Yeri on July 10, 2019

The various tokens in your code (variables, classes, functions, namespaces, etc.) can be named using one of these three styles, broadly speaking: ...
Collapse
 
juancarlospaco profile image
Juan Carlos • Edited

nim-lang.org is "Style Agnostic", AKA Style Insensitivity,
you can use Snake Case or Camel Case the way you like it.

var someVar, somePackage = "Camel Case"
echo some_var, some_package

var other_var, other_package = "Snake Case"
echo otherVar, otherPackage

var `kebab-case` = "Kebab Case"
echo `kebab-case`

var `for` = "Stropping allows to use Keywords as names"
echo `for`

type Cat = object  
var cat = "variable cat is not overwritten by Cat object"
echo Cat, cat

# echo prints to terminal (this is a comment)

## No name shadowing or overwriting here
## (This is a DocString, can be Markdown, ReSTructuredText or plain-text)

Its also for interoperability with other programming languages that may use different style,
eg. if you code Python with PyQt, it breaks the style beyond repair because everything is CamelCase on PyQt and everything is snake_case on Python.

Heres an Interactive Demo on the Nim Playground (click on RUN).
šŸ‘‘šŸ˜ŽšŸ‘

Collapse
 
revskill10 profile image
Truong Hoang Dung

Never use any of those.

One reason: In some RDBMS, column name is insensitive about those cases.

Use first_name instead of firstName , or FirstName and you'll always be fine.

Collapse
 
prahladyeri profile image
Prahlad Yeri

Yep, even in php, function names are case insensitive. A call to someFunc() or SomeFunc() or even somefunc() all go to the same function.

Collapse
 
revskill10 profile image
Truong Hoang Dung

I see some devs prefer firstName over first_name, which i see is a way to confusion if you use , for example PostgreSQL as column name.

I don't understand why they prefer that option. Maybe because it's "prettier" ?

Thread Thread
 
thphuc profile image
Phuc Tran

I'm from Java/Dart background, I also had a similar question for python.
I was thinking why we should type 1 more "_", of course this will take very short time for 1 variable or 1 method, but we will have many of them in a program.

I don't mean underscore is bad, it depends on what you prefer!

Collapse
 
ovais profile image
Mohd Ovais

I believe it widely known as Kebab Case (kebab-case) instead of Underscore.

Collapse
 
prahladyeri profile image
Prahlad Yeri • Edited

No, kebab case is different. Its the dash or hyphenated case, so dashes are used instead of underscores (to-string instead of to_string). The only place where kebab case is used is perhaps css class names (main-div, navbar-div, etc.).

The popular name for underscore case is in fact, snake case.

Collapse
 
mpmiszczyk profile image
mar

/kebab case/ as you call it is defacto standard naming convention in all Lisp's, starting room Scheme, trough Common Lisp, up to Clojure. It is phenomenon older than C and still going strong with her and current implementations.

Collapse
 
ovais profile image
Mohd Ovais

My bad, you are correct!

Collapse
 
patrykrudnicki profile image
Patryk Rudnicki

I donā€™t know the naming, but probably in Java constant value youā€™re naming in all camel case characters with underscore between words. Good to add this too if this is the official naming convention.

Collapse
 
prahladyeri profile image
Prahlad Yeri

Thanks, I've updated the post with this point.

Collapse
 
patrykrudnicki profile image
Patryk Rudnicki

Yeah, great. Good to point it too. But I mean SOME_VAL not Some_Val. Never seen this approach

Thread Thread
 
prahladyeri profile image
Prahlad Yeri • Edited

Yep, SOME_VAL is full underscores, not a variation of camel case chars, and its the more popular one. Some_Val is a mix of camel and underscores, its less popular and rarely used.

Collapse
 
codingmindfully profile image
Daragh Byrne

Lets not forget the highly authoritative MACRO_CASE!

Collapse
 
samuraiseoul profile image
Sophie The Lionhart • Edited

What you refer to as camelCase is sometimes called lowerCamelCase and what you call PascalCase is sometimes called UpperCamelCase. Also the underscore_style is sometimes called snake_case.

Collapse
 
nodws profile image
James Nodws

$howaboutnotusingany = "nice?";