What Is Clean Code?
There is not the “ultimate” definition of what clean code really is.
Bjarne Stroustrup (inventor of C++), Dave Thomas (godfather of the Eclipse strategy) and Ward Cunningham (inventor of Wiki) give different definitions:
Best Practices
Some good practices have proven to be very useful and helpful in the past:
? Use Pronounceable Names
? Use Searchable Names
? Use Descriptive Names
? Avoid Encodings
? “Functions should do one thing. They should do it well. They should do it only.”
? Legal Comments
? Informative comments
领英推荐
? Avoid useless comments
? Don’t comment out old code (history is in git/SVN)
? Add TODOs
? Avoid bad, redundant or misleading comments
? Single letter names except i, j, k which are traditional
? Clarity is king!
? Classes and object should have noun or noun phrase names like Customer, WikiPage, Account
? Should have verb or verb phrase names like postPayment, deleteAccount or save
? Accessors, mutators and predicates should be named for their value and prefixed with get, set, is
String name = employee.getName();
customer.setName(“Tom”);
If (paycheck.isPosted()))…