CLEAN CODE
SIRAR SALIH
.NET CONSULTANT
In theory, it’s about...

SOLID

16.01.2014

/

2
In theory, it’s about...

S ingle responsibility principle
O pen/closed principle
L iskov substitution principle
I nterfac...
In practice, it’s all about... RTM

Readability
Testability
Maintainability

16.01.2014

/

4
Readable Code

«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth

16.01....
Readable Code

«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth
From ht...
Readable Code

«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth

From P...
Readable Code
• Readable code is understandable code
• Naming
 Class names
 Context specific
 Method names
 Say exactl...
Readable Code

Bad

«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth

B...
Testable Code
•
•
•
•
•
•
•

Making it testable, is making it clean
Isolation
Decoupling
Separation of concerns
TDD
Design...
Testable Code

«You know you should be unit testing, so
why aren’t you doing it?» - Roy Osherove

16.01.2014 /

11
Testable Code
Bad

Good

16.01.2014 /

12
Maintainable Code

16.01.2014 /

13
Maintainable Code
•
•
•
•
•
•
•

Easy to extend
A change requires one change, not ten
Easy to understand
Unbrittle
Test co...
Bad Code

16.01.2014 /

15
Good Code

16.01.2014 /

16
The Evil Cycle

From http://blog.codeclimate.com/

16.01.2014 /

17
Be an Agent of Change

16.01.2014 /

18
Fight Code Smells and Anti-Patterns
•
•
•
•
•
•
•
•

Comments
Duplication
Global objects
Magic numbers
Circular dependency...
Make it Routine

16.01.2014 /

20
Recommended Books

16.01.2014 /

21
Thank you  / Questions

Blog: http://sirars.com/
• sirar.salih@itera.no / sirars@gmail.com
• @SirarSalih
Upcoming SlideShare
Loading in...5
×

Clean Code

994

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
994
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Single responsibility principlethe notion that an object should have only a single responsibility.Open/closed principlethe notion that “software entities … should be open for extension, but closed for modification”.Liskov substitution principlethe notion that “objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”. Interface segregation principlethe notion that “many client specific interfaces are better than one general purpose interface.”Dependency inversion principlethe notion that one should “Depend upon Abstractions. Do not depend upon concretions.”[5]Dependency injection is one method of following this principle.
  • Clean Code

    1. 1. CLEAN CODE SIRAR SALIH .NET CONSULTANT
    2. 2. In theory, it’s about... SOLID 16.01.2014 / 2
    3. 3. In theory, it’s about... S ingle responsibility principle O pen/closed principle L iskov substitution principle I nterface segragation principle D ependency inversion principle 16.01.2014 / 3
    4. 4. In practice, it’s all about... RTM Readability Testability Maintainability 16.01.2014 / 4
    5. 5. Readable Code «Programming is the art of telling another human what one wants the computer to do.» - Donald Knuth 16.01.2014 / 5
    6. 6. Readable Code «Programming is the art of telling another human what one wants the computer to do.» - Donald Knuth From http://www.osnews.com 16.01.2014 / 6
    7. 7. Readable Code «Programming is the art of telling another human what one wants the computer to do.» - Donald Knuth From Pluralsight 16.01.2014 / 7
    8. 8. Readable Code • Readable code is understandable code • Naming  Class names  Context specific  Method names  Say exactly what they do • The don’ts  Don’t confuse  Don’t hide  Don’t joke  Don’t be informal • Tell a story! «Programming is the art of telling another human what one wants the computer to do.» - Donald Knuth 16.01.2014 / 8
    9. 9. Readable Code Bad «Programming is the art of telling another human what one wants the computer to do.» - Donald Knuth Better 16.01.2014 / 9
    10. 10. Testable Code • • • • • • • Making it testable, is making it clean Isolation Decoupling Separation of concerns TDD Design Clean is the side effect of testable 16.01.2014 / 10
    11. 11. Testable Code «You know you should be unit testing, so why aren’t you doing it?» - Roy Osherove 16.01.2014 / 11
    12. 12. Testable Code Bad Good 16.01.2014 / 12
    13. 13. Maintainable Code 16.01.2014 / 13
    14. 14. Maintainable Code • • • • • • • Easy to extend A change requires one change, not ten Easy to understand Unbrittle Test coverage Spreads optimism Importance level: Readable > maintainable 16.01.2014 / 14
    15. 15. Bad Code 16.01.2014 / 15
    16. 16. Good Code 16.01.2014 / 16
    17. 17. The Evil Cycle From http://blog.codeclimate.com/ 16.01.2014 / 17
    18. 18. Be an Agent of Change 16.01.2014 / 18
    19. 19. Fight Code Smells and Anti-Patterns • • • • • • • • Comments Duplication Global objects Magic numbers Circular dependency Coupling Nesting Dead code 16.01.2014 / 19
    20. 20. Make it Routine 16.01.2014 / 20
    21. 21. Recommended Books 16.01.2014 / 21
    22. 22. Thank you  / Questions Blog: http://sirars.com/ • sirar.salih@itera.no / sirars@gmail.com • @SirarSalih
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×