Hey Guys 🙂 As a Developer We all know that There are multiple ways to create a Project. The Language, Code Style and Even Syntax can vary. A Massive or Large variety of Code leads to Wildly Codebases.
We know it very well that a Single project is not the responsibility of a single Developer Rather Its a Responsibility of an Entire Team But We also Know that Different Developers have different Ways of Styling the Code. Its not important that they follow the Same Coding Style.
Now The Problem Arises here ?
Suppose Guys We are Twenty Developers Working on the Same Project and of course Everyone needs to create the variables, Constants, Functions and many more in PHP. Imagine You needs to Create a variable in php to store the User first Name then
How would you name it?
And how would your teammate name it? You Don't know. Right! and Twenty Developers are working on that project, now imagine Guys After Completion the Project, How Your Project Will look... The Project will become Inconsistent, ambiguous, Which'll consists a lot of Confusions, Errors and many more. Am I Right ?
Okay Just tell me One thing - Why Your Project would not become Consistent and Clear ?
If I would say in Simple words, then my Answer will be the Lack of Coding Standards. Guys if we want our Project to be Clear, Consistent, Unambitious we need every developer to follow the same Coding Standards.
So What are Coding Standards ?
Coding Standards are nothing guys it's just some Important guidelines or you can say that Coding Standards are the rules which Every Developer needs to follow while Working on the Project especially while all developers are working on the same Project. I hope this is very simple definition of Coding Standards and You understand it! 🙂
Why Have Coding Standards or Why we need Coding Standards ?
- Readability improves understanding; that further improves maintainability.
- Any member of a development should be able to read the code of another member.
- If you are planning to contribute to WordPress core, you need to familiarize yourself with these standards, as any code you submit will need to comply with them.
A Look at the Coding Standards :
First of all, Whenever we start our Project or any Program Commenting Should be Provided.
So let' s have a small look on Commenting:
- Commenting is necessary for maintaining any program.
- Without Commenting, the program is not complete.
- Do not assume that the other person who reads this program will understand it clearly.
- If commenting is not done at the beginning, it is forgotten.
- If any Program or any project you starts, You need to commenting at the top:
- At the top of the Program -> Header Comments should be provided.
- What the Program achieves.
- Who Coded on that day.
E.g. We need to create a Class that is Employee so we can provide the comments :
// this class is used to manage all information of employees.
Naming Conventions :
- Variables Should Be In Lowercase.
- Constants Should Be In Uppercase.
See the Example of Declaring the Variables:
See the Example of defining the Constants:
No Shorthand PHP Tags:
Your indentation should always reflect logical structure.Use real tabs and not spaces,as this allows the most flexibility across clients.
Benefits of Coding Standards:
- Code Integration.
- Team Member Integration.
- Minimizes Communication.