Programming: Naming and code writing conventions

Share on email
Email
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on facebook
Facebook
Share on email
Share on twitter
Share on linkedin
Share on facebook
Article the naming conventions in programming: Camel case, Pascal case, kebab case, snake case and underscore case by wpr0ck
Article the naming conventions in programming: Camel case, Pascal case, kebab case, snake case and underscore case by wpr0ck
Article the naming conventions in programming: Camel case, Pascal case, kebab case, snake case and underscore case by wpr0ck
Article the naming conventions in programming: Camel case, Pascal case, kebab case, snake case and underscore case by wpr0ck

Explanations with examples of the 4 most common naming conventions in programming: Camel case, Pascal case, kebab case, snake case and underscore case.

Naming conventions homogenize code, which has the advantage of making it easier for developers to find the names used in a project (both to name them and to call them) and to collaborate more easily when a code is written with several people. In all cases, it is advisable not to use accents or special characters (except in special cases, such as the jQuery framework which uses the dollar symbol "$" to name its main class).

The Camel case

Convention: words are linked without spaces. Each word begins with a capital letter with the exception of the first.

Examples: myVariableName, myUrl

It is probably the most widely used convention. It is available in JavaScript, Java, C++, C# and many more. It is also the most common form in Twitter hashtag. This convention is also used by some brands to display their membership in the digital world as is the case for eBay and iPhone. When using acronyms (URL, CSS, HTML, etc...) in Camel Case, only the first letter of the latter are to be capitalized.

The Pascal case

Convention: words are linked without spaces. Each word begins with a capital letter.

Examples: MyVariableName, MyUrl

This convention is used in the Pascal programming language or to name classes in PHP.

As for the Camel Case, only the first letter of the acronyms should be capitalized. This convention is also used by some brands to communicate an innovative aspect such as PlayStation, QuickTime or MasterCard.

The Kebab case or Spinal case

Convention: the words are in lower case and are linked by hyphens (-).

Examples: my-variable-name, my-url

The kebab case is recommended for writing URLs as well as naming images, PDFs and other files for the web. In programming, it is used, for example, to name classes and IDs in HTML and CSS code.

The name Kebab case actually refers to skewers much more than to the kebabs themselves, like a skewer of words made of dashes. As for Spinal case, it refers to the spinal column.

The Underscore case or Snake case

Convention: the words are in lower case and are linked by undescores (underscore: _).

Examples: my_variable_name, my_url

The underscore case, also called snake case, is used in PHP, Ruby or Phyton. There is a variant of this convention. Named screaming snake case, which consists in capitalizing all words, always separated by underscore (Example: MY_CONSTANT_NAME). This form is found in the names of constants in PHP or to name exceptions in ADA.

Programming conventions in WordPress

You can find the conventions and best practices of programming for the themes, the pluginsand the core WordPress documented in the codex.

Julien MA Jacob
WordPress Developer
Julien MA JACOB - WordPress Developer
Passionate about the web and programming with always many projects in mind
  Discussion around the article
avatar
1 Comment threads
1 Thread responses
0 Subscribers
 
Comment with the most reactions
The most popular comment
2 Commentary Authors
Julien MA JacobGUY Jérôme Recent commentators
  Subscribe to the newsletter  
most recent oldest one most popular
Notify to
GUY Jérôme
Guest
GUY Jérôme

Good article!
A clarification on Camel Casing and Pascal Casing:
- What is presented here under Camel Casing is what corresponds to Lower Camel Casing
- Pascal Casing is actually Upper Camel Casing

Julien MA Jacob
Guest
Julien MA Jacob

Hello Jérôme,
Thank you for these clarifications.
I will see to eventually add them to the article:)