Clean Code

22
CLEAN CODE SIRAR SALIH .NET CONSULTANT

description

 

Transcript of Clean Code

Page 1: Clean Code

CLEAN CODE

SIRAR SALIH

.NET CONSULTANT

Page 2: Clean Code

08.04.2023

In theory, it’s about...

SOLID

/ 2

Page 3: Clean Code

08.04.2023

In theory, it’s about...

/ 3

SOLID

ingle responsibility principle

pen/closed principle

iskov substitution principle

nterface segragation principle

ependency inversion principle

Page 4: Clean Code

08.04.2023

In practice, it’s all about... RTM

/ 4

ReadabilityTestability

Maintainability

Page 5: Clean Code

08.04.2023

Readable Code

/ 5

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

Page 6: Clean Code

08.04.2023

Readable Code

/ 6

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

From http://www.osnews.com

Page 7: Clean Code

08.04.2023

Readable Code

/ 7

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

From Pluralsight

Page 8: Clean Code

08.04.2023

Readable Code

/ 8

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

• 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!

Page 9: Clean Code

08.04.2023

Readable Code

/ 9

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

Bad

Better

Page 10: Clean Code

08.04.2023

Testable Code

/ 10

• Making it testable, is making it clean• Isolation• Decoupling• Separation of concerns• TDD• Design• Clean is the side effect of testable

Page 11: Clean Code

08.04.2023

Testable Code

/ 11

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

Page 12: Clean Code

08.04.2023

Testable Code

/ 12

Bad Good

Page 13: Clean Code

08.04.2023

Maintainable Code

/ 13

Page 14: Clean Code

08.04.2023

Maintainable Code

/ 14

• Easy to extend• A change requires one change, not ten• Easy to understand• Unbrittle• Test coverage• Spreads optimism• Importance level: Readable > maintainable

Page 15: Clean Code

08.04.2023

Bad Code

/ 15

Page 16: Clean Code

08.04.2023

Good Code

/ 16

Page 17: Clean Code

08.04.2023

The Evil Cycle

/ 17

From http://blog.codeclimate.com/

Page 18: Clean Code

08.04.2023

Be an Agent of Change

/ 18

Page 19: Clean Code

08.04.2023

Fight Code Smells and Anti-Patterns

/ 19

• Comments• Duplication• Global objects• Magic numbers• Circular dependency• Coupling• Nesting• Dead code

Page 20: Clean Code

08.04.2023

Make it Routine

/ 20

Page 21: Clean Code

08.04.2023

Recommended Books

/ 21