Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clean Code 101

Avatar for Melvin Melvin
January 28, 2019

Clean Code 101

In this talk we will be talking about how developers can indirectly help one another or their future-selves by writing and maintaining clean understandable code.

Avatar for Melvin

Melvin

January 28, 2019
Tweet

More Decks by Melvin

Other Decks in Programming

Transcript

  1. Why this talk? • Because we are not doing it

    (clean code). • Why should we do it - refresher • How can we improve on doing it.
  2. Refresher • “I like my code to be elegant and

    efficient. The logic should be straightforward to make it hard for bugs to hide...” - Bjarne Stroustrup.. • “Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control. ” - Grady Booch. • “Clean code can be read, and enhanced by a developer other than its author.” - Dave Thomas. • “You know you are working on clean code when each routine you read turns out to be pretty much what you expected...” - Ward Cunningham
  3. Refresher - Why should we do it. • Developers change

    jobs every 2-3 years (on average)
  4. Another quote “Indeed, the ratio of time spent reading versus

    writing code is well over 10 to 1. We are so constantly reading old code as part of the effort to write new code. …[therefore,] making it easy to read makes it easier to write. ” - Robert C. Martin.
  5. Why are we not doing it. BLAME the project Managers??

    Or just blame devs • Devs “never” have time for clean code • Tight deadlines as well as lots of “we’ll refactor later”
  6. ...Just do it. 2. Use intention-revealing names. int d; //

    elapsed time in days VS Int elapsedTimeIndays; Int daysSinceCreation;
  7. ...Just do it. 3. Make meaningful distinctions. Avoid noise words

    getActicveAcoount V getActiveAccountInfo(), customerInfo V customer.
  8. ...Just do it. 4. “First rule of functions is that

    they should be small. The second rule of functions is that they should be smaller than that.” But how small is small ? Functions should do one thing. They should do it well. They should do it only.
  9. ...Just do it. 6. Boys scout rule - Leave you

    code better than you found it.