Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
{Clean Code}
The fundamental of high quality software
presented by Arif Akbarul Huda (twitter @omayib)
Interesting Quotes
“Writing code is more like write a book. An other pepople will read and
use it. Keep it human readible ...
Problem state
Are you worried after publish your
application to the store?
did you found any side effect after
do refactoring?
Oh no! We have a spaghety code
Let’s make our code cleaner than
before.
1. Meaningful names
Use descriptive name
This is bad:
protected $d; // elapsed time in days
This is good:
protected $elapsedTimeInDays;
protec...
Use pronounceable name
This is bad:
public $genymdhms;
public $modymdhms;
This is good:
public $generationTimestamp;
publi...
Use namespaces instead of prefixing names
This is bad:
class Part {
private $m_dsc;
} 
This is good:
class Part {
private ...
Don't be cute
This is bad:
$program­>whack();
This is good:
$program­>kill();
Use one word per one concept.
This is Bad :
void LoadSingleData()
void FetchDataFiltered()
Void GetAllData()
This is Bette...
Use meaningful names in their self context
This is bad :
string addressCity;
string addressHomeNumber;
string addressPostC...
2. Better Function
The smaller the better
A function should only do one thing
public void purchase(List<Item> items){
    if(user.getAge>17 &...
public void purchase(List<Item> items){
    if(user.isAllowed()){
        try {
            user.purcashe(items);
        ...
Less arguments are better
More than three arguments are evil. For example:
Circle makeCircle(Point center, double radius);...
3. Comment
Don’t comment bad code, rewrite it
If code is readable you don’t need
comments
This is bad:
// Check to see if the employee is eligible for full benefits
if ...
Explain your intention in comments :
// if we sort the array here the logic 
// becomes simpler in calculatePayment() 
// ...
Emphasis important points in comments :
// the trim function is very important, in 
// most cases the username has a trail...
4. S.O.L.I.D. Priciple
S – Single-responsiblity principle
O – Open-closed principle
L – Liskov substitution principle
I – Interface segregation p...
Recommended Books
Upcoming SlideShare
Loading in …5
×

clean code for high quality software

381 views

Published on

clean code is the fundamental to build a high quality software. a sharing session in "startup-talk" , 4th march 2017 at Incubator Universitas Amikom Yogyakarta.

Published in: Software
  • Be the first to comment

clean code for high quality software

  1. 1. {Clean Code} The fundamental of high quality software presented by Arif Akbarul Huda (twitter @omayib)
  2. 2. Interesting Quotes “Writing code is more like write a book. An other pepople will read and use it. Keep it human readible instead of mechine readible.” @omayib (6/2/2017) “Buat aplikasi itu juga harus mikir gimana caranya bisa didebug dengan gampang. Ndak kayak gini juga. Edan” @linklunx (25/1/2017) Software quality & Productivity are realted. Better quality leads to enhanced productivity” @_ericelliot (4/12/2016)
  3. 3. Problem state
  4. 4. Are you worried after publish your application to the store?
  5. 5. did you found any side effect after do refactoring?
  6. 6. Oh no! We have a spaghety code
  7. 7. Let’s make our code cleaner than before.
  8. 8. 1. Meaningful names
  9. 9. Use descriptive name This is bad: protected $d; // elapsed time in days This is good: protected $elapsedTimeInDays; protected $daysSinceCreation; protected $daysSinceModification; protected $fileAgeInDays;
  10. 10. Use pronounceable name This is bad: public $genymdhms; public $modymdhms; This is good: public $generationTimestamp; public $modificationTimestamp;
  11. 11. Use namespaces instead of prefixing names This is bad: class Part { private $m_dsc; }  This is good: class Part { private $description; } 
  12. 12. Don't be cute This is bad: $program­>whack(); This is good: $program­>kill();
  13. 13. Use one word per one concept. This is Bad : void LoadSingleData() void FetchDataFiltered() Void GetAllData() This is Better : void SetDataToView(); void SetObjectValue(int value)
  14. 14. Use meaningful names in their self context This is bad : string addressCity; string addressHomeNumber; string addressPostCode; This is better : class Address{ string city; string homeNumber; string postCode; } https://blog.goyello.com/2013/05/17/express-names-in-code-bad-vs-clean/
  15. 15. 2. Better Function
  16. 16. The smaller the better A function should only do one thing public void purchase(List<Item> items){     if(user.getAge>17 && database != null ){         database.connect();         boolean status = database.save(items);         if(status==true){             textLabel.setText("purchase succeed");         }     } }
  17. 17. public void purchase(List<Item> items){     if(user.isAllowed()){         try {             user.purcashe(items);         } catch (Exception e) {             e.printStackTrace();         }     } }
  18. 18. Less arguments are better More than three arguments are evil. For example: Circle makeCircle(Point center, double radius); Is better than Circle makeCircle(double x, double y, double radius);
  19. 19. 3. Comment
  20. 20. Don’t comment bad code, rewrite it
  21. 21. If code is readable you don’t need comments This is bad: // Check to see if the employee is eligible for full benefits if ($employee­>flags && self::HOURLY_FLAG &&  $employee­>age > 65)  This is good: if ($employee­>isEligibleForFullBenefits())
  22. 22. Explain your intention in comments : // if we sort the array here the logic  // becomes simpler in calculatePayment()  // method Warn of consequences in comments : // this script will take a very long time  // to run 
  23. 23. Emphasis important points in comments : // the trim function is very important, in  // most cases the username has a trailing  // space Noise comments are bad : /** The day of the month. */ private $dayOfMonth;
  24. 24. 4. S.O.L.I.D. Priciple
  25. 25. S – Single-responsiblity principle O – Open-closed principle L – Liskov substitution principle I – Interface segregation principle D – Dependency Inversion Principle TOBE CONTINUE >>
  26. 26. Recommended Books

×