Clean Code @Agileworks Romania 2013 05 23

18
Clean Code

description

 

Transcript of Clean Code @Agileworks Romania 2013 05 23

Page 1: Clean Code @Agileworks Romania 2013 05 23

Clean Code

Page 2: Clean Code @Agileworks Romania 2013 05 23

Clean Code

Adi Boboacă

@adibolb

Alex Bolboacă

@alexboly

Page 3: Clean Code @Agileworks Romania 2013 05 23

Clean Code

Page 4: Clean Code @Agileworks Romania 2013 05 23

Clean Code

Code is more often read than written

www.mozaicworks.com

Page 5: Clean Code @Agileworks Romania 2013 05 23

Clean Code – Environment

Build Requires One StepBuild time is manageable

Tests Execution Requires One StepAlways Use Source ControlHave Continuous Integration

Page 6: Clean Code @Agileworks Romania 2013 05 23

Code Smell

SniffableEasy to spot

Does not always indicate a problem

www.mozaicworks.com

Page 7: Clean Code @Agileworks Romania 2013 05 23

Code Smell

A code smell is a hint that shows you might have a problem in your system. '

www.mozaicworks.com

Page 8: Clean Code @Agileworks Romania 2013 05 23

Coding Smells - Design

Misplaced ResponsibilityCode at Wrong abstraction Level

Fields Define Temp VariablesHidden Temporal Coupling

Over-engineeringUsage of Singleton / Statics / newInterface Has Too Many Methods

Page 9: Clean Code @Agileworks Romania 2013 05 23

Clean Code - Design

Be PreciseDon't Be Arbitrary

Keep Configuration at High LevelsPrefer Polymorphism Over conditionalsPrefer Composition Over Inheritance

S.O.L.I.D.

Page 10: Clean Code @Agileworks Romania 2013 05 23

Coding Smells – Naming

There Are Several Naming StandardsMore Names Mean The Same Concept

Someone Needs To Explain You The Code

Page 11: Clean Code @Agileworks Romania 2013 05 23

Clean Code – Naming

Use Standards For The LanguageNames Use Domain LanguageNames Describe The Intention

Names Do Not Use Hungarian NotationNames Do Not Contain Encodings

Page 12: Clean Code @Agileworks Romania 2013 05 23

Coding Smells - Methods

Method Has More Than 3 IndentsMethod Uses Getters From Other Classes

There Are Static MethodMethods & Ctors Have More Than 3 Args

Arguments Have out Or ref

Page 13: Clean Code @Agileworks Romania 2013 05 23

Clean Code - Methods

Have Only One ResponsibilityUse Only Internal State (No Feature Envy)

Avoid StaticHave Maximum Two Arguments

Do Not Pass Reference As Arguments

Page 14: Clean Code @Agileworks Romania 2013 05 23

Coding Smells - Variables

You see a, i, bla, etc. As VariablesYou see string, int, float, In ClassesThere Are Static Variables In Classes

Use Integers for Currency

Page 15: Clean Code @Agileworks Romania 2013 05 23

Clean Code - Variables

Use Explanatory VariablesAlways Encapsulate Primitives

Avoid StaticsUse Appropriate Types

Page 16: Clean Code @Agileworks Romania 2013 05 23

Clean Code - General

Boy Scout RuleKeep It Simple, Stupid (KISS)Delete Commented Code

Delete Unused CodeMinimize Duplication

Page 17: Clean Code @Agileworks Romania 2013 05 23

Clean Code

http://www.mozaicworks.com

Extend your mentoring & training capacity

Accelerate learning through communities of practice

Grow your functional leaders and top talents

@alexboly @adibolb

Page 18: Clean Code @Agileworks Romania 2013 05 23

Clean Code

Q&A,Beer

& More...

www.mozaicworks.com