Improve coding standard with Developer’sDesk!


Hey Friends,

Hope you all are safe! Today, I will give you some tips which will improve your coding standards.

To write a code can be easy, but to write meaningful code can be difficult for some developers. Good coding standard will easy your work and save your time.

Let’s Improve the coding standard and make a healthy code……

Lets go in depth!

1. Create Document.

You should create a document first of your requirements. It will clear you to the requirements, Estimation hours for tasks and in your work plan.

Document will help you for future reference for you and your client also.

2. Give meaningful name

Your code must have a meaning full declaration. Some of developer gives variable name,

 Ex. $a = 0;

It will create a confusion for other developer who read the code or work on that code. it will also difficult for you also when you come to this code after long time. Because you will forgot why you use $a.

Instead of this, If we use

$response = 0; 

then you can understand it well.

3. Useful Comments

Ex.

/** * Get / set the specified configuration value. 
* If an array is passed, It will convert it to string
* @param array|string|null $key 
* @param mixed $default 
* @return mixed */
function testCodeStandard($key){}

One thing need to keep in mind, do not add meaning less comment in code, It can create confusion for others.

4. Optimise the code

This is the most important point. Because it can easy your work and save your time.

When You write a code and you seems that it can be useful for other function also. then you can write it separately to use it for other function also. In this type of case, you just need to import your written function. no need to repeat the code.

Ex.

public function calculat($val1, $val2){
      $sum = $val1 + $val2;
}

function age_sum(){
        $fahter_age = 30;
        $son_age = 2;
        return calculate($father_age, $son_age);
}

function total_run(){
        $first_inning = 350;
        $second_inning = 460;
        return calculator($first_inning, $second_inning);
}

5. Format the code

To format code will help you to read the code clearly. It will easy for you to catch the structure of code. Also it will helpful for you to debug the code. To catch bug will be easy in formatted code.

Ex.

public function get_eligible_voters($data){
      if(!empty($data)){
            foreach($data as $key=>$value){
                $name = $value->name;
                $address = $value->address;
                $city = $value->city;
            }
      }
}

6. Use Exception Handling

To use try. throw, catch, is one of the habit of a good developer. It should be in your code. And if you are working on a big project then no need to take a chance. you must use try catch.

It will help you to avoid error. and also it will help you to catch the bug.

Ex.

try{
      if($number > 1){
            echo "Allow to come";
      }
}catch(Exception $e){
      echo $e->errorMessage();
}


7. Use inbuilt tools

If you need to add some external functions to your project, then first search for “Is your framework provides it built in or not”. It will help you to reduce project size and do not need to use external resources. It will also reduce loading time.

Ex.
If you wanna use facebook login, then use your frameworks inbuilt tool. Do not import from external source.

8. Use Test Cases

To write test cases is a best practice for programmer. It will help you to achieve your result.

To write test cases can be headache for new test case users. but it will really helpful in future and for your good coding standard. Once you habituated with test cases, then it will easy for you to work ahead in a big project smoothly.


I hope this tricks will help you to improve your coding standard.

Stay Safe!

Happy Coding!

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started