Transcript

CLEAN CODE AND ENGINEERING PRACTICESRuth Sperer – Tech Lead and EP ChampionAT&T Israel

OVERVIEW▪ Clean code principles

▪ Code Review

▪ TDD

▪ Refactoring

▪ SCM, SCA, CI and other abbreviations

▪ Being a good programmer

WHAT DO YOU CONSIDER CLEAN CODE?▪ Readable

▪ Error free

▪ Elegant

▪ Testable

▪ Efficient

MEANINGFUL NAMES▪ For class, method or variable, name should suggest

▪ Why is exists

▪ What it does

▪ How it is used

▪ Don’t include type info▪ Why?

▪ Be honest▪ No side effects

▪ So what about comments?

WHAT MAKES A GOOD FUNCTION?▪ Short

▪ Efficient

▪ Does one thing

▪ Reusable

▪ Few variables

▪ No side effects

CODE REVIEW - MOTIVATIONDefinition: The analysis of source code in order to find defects

▪Early bug detection

▪Knowledge sharing

▪Code improvements

▪Social communication

▪Understanding

* Expectations vs. Actual

CODE REVIEW – PRACTICAL GUIDE▪ Let the tools work for you:

▪ Formatter

▪ Lint

▪ Find problems, not solutions

▪ As a reviewer – be nice

▪ As a reviewed – leave you ego in the drawer

▪ Don’t skip it (no valid excuses)

TDD

REFACTORING▪ Why ?

▪ Cost of owning a mess*:

▪ Don’t make it to “The grand re-design”*

▪ Code that smells▪ Duplicate code▪ Longs methods▪ Deep nesting▪ Too many variables in a method

* Rober C Marting – “Clean Code..”

REFACTORING TIPS▪ Valid changes – let your IDE work for you

▪ Renaming

▪ Extract variable

▪ Extract method

▪ Move

▪ Introduce parameter

▪ Unit tests coverage is your friend

SCM – SOFTWARE CONFIGURATION MANAGEMENT▪ Track and control changes in software

▪ Confidence in change - Can always go back

▪ When to start using it?

▪ Git – free and open source

▪ Github – host

▪ Other free/commercial tools – CVS, SVN, ClearCase

SCA – STATIC CODE ANALYSIS▪ Analyzing code without executing it

▪ Common Errors detectible by SCA▪ Buffers and arrays underflows \ overflows

▪ Resource leaks

▪ Potential null references

▪ Lack of initialization

▪ Common tools: Sonar, FindBugs, Checkstyle

CI – CONTINUOUS INTEGRATION▪ is the practice of merging all developer working copies with a

shared mainline several times a day

▪ Considered an XP (extreme programming) habit

▪ Possibly dozens of “commits” every day

▪ Prevent “Integration Hell”

▪ Automated unit tests in build server

▪ Next step: CD – Continuous Delivery

BEING A GOOD PROGRAMMER▪ Respect your ancestors

▪ The Netscape rewrite story

▪ Acknowledge your successors▪ Meaningful names, Comments

▪ Avoid code duplications

▪ “Leave the camp ground cleaner than you found it”

RECOMMENDED READINGS▪ "Clean Code: A Handbook of Agile Software Craftsmanship“ by Robert

C. Martins

▪ “The Pragmatic Programmer” by Dave Thomas and Andy Hunt

▪ Effective <fill in your language>

top related