Main menu

Pages

Clean Code -T1- CODE SHOULD BE EASY TO UNDERSTAND

 

KEY NOTE

you write code for humans not machines, so code should be easy to understand.

You might think that i write code for myself and i'm not working with others and this is the first fault you did when writing code because there is may a chance another developer will join with you later or you deliver project and add new features to it after period and you will forget all of this code.

1- Is Smaller Code Always Better? 

you might think smaller lines of code better than long lines and this is correct , read 1000 lines of code better than read 3000 lines, but it's not correct in all times.

Example:-

assert((!(bucket = FindBucket(key))) || !bucket->IsOccupied());

this line of code take long time to understand than this 2 lines code

bucket = FindBucket(key);

if (bucket != NULL) assert(!bucket->IsOccupied()); 

so try to write a code that always readable for you and others even though created many lines of code.

reactions

Comments