Main menu

Pages

Clean Code Techniques That Every Coder Should Know

in real world scenarios you will be working as a team of programmers to build any specific application; therefore, it is important to keep your code clean and understandable because you are not the only one working on them.

let’s look at the different ways to write clean code, regardless of what programming language you are working on.

1-Keep It Simple

the most basic tip, is to keep your code simple and readable as possible. Don’t get fancy if you don’t have to, and don’t over-complicate problems,
By keeping it simple you can produce higher quality code, solve problems faster, work better in developer groups and have a more flexible code base.

2-Understand Your problem that wants solve with code

The most basic tip is to keep your code as simple and readable as possible. Don’t get fancy if you don’t have to, and don’t over-complicate problems,
By keeping it simple you can produce higher quality code, solve problems faster, work better in developer groups, and have a more flexible code base.

3-Comments Is your best friend

Adding comments to your code is a tip that spans every programming language. It makes updating, debugging, analysis and other post-programming activities easier and more efficient. Further, if you are working as a team, having comments in the code makes it convenient for the other members to understand your idea of the code.
 

4. Don’t Repeat Yourself (DRY)

The DRY principle, produced by Any Hunt and Dave Thomas in The Pragmatic Programmer.
is the use of functions, classes and instances to allow you to avoid retyping code that has already been written once. This fundamental principle allows developers to avoid duplication to produce much cleaner code and testable code that will be tested once and will not raise bugs after it tested.
 

5. Indent Your Code

imagine that you are in a supermarket and searcing for milk and you found that supermarket is not organized and milk is in clothes section and meat in milk sections what u will be thinking about this market?
same as code organize and indent your code is very important to help you understand your code and find bugs and parts you are searching for.
use same spaces for variables declarations and methods calls.
 
Example:
 
//Objects
User user = new User();
List<Student> students = [];
//Variables.
int usersCount = 10;
String pageTitle = "Users Info";
//GUI
TextView userNameTextView; 
 

6. Naming Convention & Consistent naming

use naming convention in your code and e consistent in this naming because it's a contract between you and other developers will read or complete your work.
 
Example:
1-use camelCase for naming variables or use lowerCase with underscore but if you choose one of this convention don't change it.
 
2-use PascalCode for naming classes and never name a class with a lowercase to prevent yourself and others from thinking what is this class mean, you must write code that is consistent and don't make developers thinking of it.
 

7-Explore & Download Open Source code

one of the best learning techniques is download github projects that other developers created and learn from this projects and enhance it's code and architectures to enhance your coding skills.
also try to contribute in open source projects that will force naming convention and code organize technique that that team applies. 
 
 
 
 

reactions

Comments