Author Archives: Youans Ezzat

Youans Ezzat

Code quality, is to write code with the ultimate goal in mind; which is customer satisfaction. Thus, anything you write with high quality will make that goal easy to reach.

 

So, what are the rules of writing high-quality code?

  1. Agile perspective

 

  1. Other Rules

Although Agile defines its own code quality rules, some other rules are defined and known by community. It may meet the Agile definition or may not and here are these rules:

1.   Re-usability

The power of using code more than once, e.g., Utility class is a very good example of code reusability.

class Uploader{

public static void uploadImage(String src,String dist)

{……// common image uploading code}

}

 

I won’t write code every time to upload image.

         

To increase code reusability you have to use good frameworks, design patterns or even libraries.

2.   Testability
This section is covered by Agile and gives it a very high rank of importance, which consequently helps in:
- Making sure that the code is acting correctly.
- Making the code easier to update
Examples of unit testing for platforms we use:
Java : JUnit : http://junit.org/
PHP  : PHPUnit : http://phpunit.de/
C#   :  Microsoft unit test framework : http://msdn.microsoft.com/en-us/library/ms182532.aspx
 

3.   Reliability
Reliability is to make a failure-free software. Yes, you got it, try&catch!
So to write high-quality code, you strongly need to know about handling failures.
Repeat after me: SOFTWARE MUST NOT CRASH
ex:
try{// connect to internet}
catch(NoElectricityException | HardwareException | ISPException | DonotHaveInternet x){}
J

4.   Performance
Performance is the backbone of the code quality. Imagine the following
for(int i=0; i<5;i++){
   if(i==3){continue;}

   else{x=i*i;}
}

Seems good? Let’s make it wonderful:

for(int i=0; i<5 && i!=3 ;i++){

      x=i*i;
}

 

See the difference? Fewer lines, same output with enhanced performance by omitting "if & else".

Since most of us are web developers, you should concentrate on the performance.

Heavy code on the server side is like feeding a duck too much that makes it hard for it to move.

5.   Readability

As the title tells, simply Readability is: How readable your code is to others? Increasing readability is done in two ways:

First, the hard way: you finished your wonderful code and BAM you have to document the code.

What ?!

Yes document the code. Extra heavy work, but it increases your own readability and helping people understanding your brilliant code.

Feelin smarter that’s the spirit ;)

Example:

/**

 * The HelloWorldApp class implements an application that

 * simply displays "Hello World!" to the standard output.

 */

class HelloWorldApp {

    public static void main(String[] args) {

        System.out.println("Hello World!"); //Display the string.

    }

}

Second, naming convention: How can I understand the variable, object, class or method benefit without good indicators?

Example:

String photoPath; // good

String profilePhotoPath;// Perfect

 

Code Quality: is so important, but at the time it depends mainly on the one writing it and somewhat argumentative - you can’t find some book telling you not to use 10 variables and use array instead. However, as a developer you know the language and this is your crystal ball that you need to handle skillfully. In short, focusing on code quality daily and continuously will help you become the PROFESSIONAL developer you aspire to be.