



































Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!




































Contents 1.Clean code 2.Naming 3.Functions 4.Comments 5.Error handling 6.Classes
What is clean code? Bjarne Stroustrup , inventor of C++ “I like my code to be elegant and efficient.” “The logic should be straightforward to make it hard for bugs to hide.” “Clean code does one thing well.”
What is clean code? Grady Booch , author of Object Oriented Analysis and Design with Applications “Clean code is simple and direct.” “Reads like well-written prose.”
What is clean code? Michael Feathers , author of Working Effectively with Legacy Code “Clean code always looks like it was written by someone who cares.”
What is clean code? Ward Cunningham , inventor of Wiki, inventor of Fit, coinventor of eXtreme Programming. Motive force behind Design Patterns. Smalltalk and OO thought leader. “On clean code, each routine you read turns out to be pretty much what you expected.”
How to measure code quality?
Consequences of bad code
Naming
Naming - Intention revealing names Bad public List< int []> getThem() { List< int []> list1 = new ArrayList< int []>(); for ( int [] x : theList) if (x[ 0 ] == 4 ) list1.add(x); return list1; }
Naming - Pronounceable names class Customer { private Date generationTimestamp ; private Date modificationTimestamp ; private final String recordId = "102" ; }; class DtaRcrd102 { private Date genymdhms ; private Date modymdhms ; private final String pszqint = "102" ; }; Bad Good
Naming - Avoid encodings private String description ; PhoneNumber phone ; private String m_dsc ; PhoneNumber phoneString ; // name not changed when type changed! Bad Good