SlideShare una empresa de Scribd logo
1 de 46
A Sweet Taste of Clean Code &
Software Design
Kfir Bloch, Developer
linkedin/in/blochkfir github.com/kfiron@kfirondevkfirb@wix.com http://kfiron.com
Hi.
I am Kfir.
coding, open source
software, cooking
HOBBIES
Lithuania
Ukraine
Vilnius
Kyiv
Dnipro
Wix Engineering Locations
Israel
Tel-Aviv
Be’er Sheva
As software engineers,
we try to...
As software engineers,
we try to...
Develop / deliver fast
Have a software which is
easier to change
Clean Code and Software Design
Can help us do it.
Clean Code
in a Nutshell
Software code that is formatted in a modularized and systematic manner so that
another coder can easily interpret or modify it.
Wikipedia
Clean Code
Clean Code
“You can call it beautiful code when the code also makes it look like the language
was made for the problem.”
Ward Cunningham
Clean Code
“Clean code always looks like it was written by someone who cares.”
Michael feathers
“You can call it beautiful code when the code also makes it look like the language
was made for the problem.”
Ward Cunningham
Clean Code
“Clean code always looks like it was written by someone who cares.”
Michael feathers
“Clean code is about recognizing that your audience isn't just a computer, it's real-
live humans!”
Cory House
“You can call it beautiful code when the code also makes it look like the language
was made for the problem.”
Ward Cunningham
Clean Code should be like your car’s dashboard.
A sneak preview gives you all the information you need.
Solving a problem
fast isn’t enough.
Solving a problem
fast isn’t enough.
Organizing things
for yourself
isn’t enough.
Solving a problem
fast isn’t enough.
Organizing things
for yourself
isn’t enough.
Others need to
make sense of it
too.
Indentations, White spaces, Tabs
Naming! reveals intent
Small functions
Length of lines
Number of arguments
When to break lines
Structured packages and folders
DRY – don’t repeat yourself
Declarative and expressive
And more…
Clean Code
Characteristics
Indentations, White spaces, Tabs
Naming! reveals intent
Small functions
Length of lines
Number of arguments
When to break lines
Structured packages and folders
DRY – don’t repeat yourself
Declarative and expressive
And more…
Clean Code
Characteristics
It’s all about
paying
attention to
the details.
Can you tell what this function does?
def send(userId: String, to : String, cc : String, body: String) ={
if(cc != null && !cc.contains("@") && !cc.contains(".")){
Failure(new InvalidEmailException("invalid email"))
} else {
if(to != null && !to.contains("@") && !to.contains("."))
Failure(new InvalidEmailException("invalid email"))
else{
bi.logEmailSent(userId, System.currentTimeMillis())
Success(mail.sendEmail(userId, to, cc, body)
)
}
}
}
def sendEmail(emailMessage: EmailMessage): Try[Id] = Try {
validateEmail(emailMessage.to)
validateEmail(emailMessage.cc)
bi.logEmailSent(emailMessage.userId, System.currentTimeMillis())
mail.sendEmail(emailMessage)
}
def validateEmail(email: String): Unit =
if (email != null &&
!email.contains("@") &&
!email.contains(".")) {
throw new InvalidEmailException(s"the email: [$email] is invalid")
}
// OK
"Dog service" should {
"add dog" in {
dogHouse.addDog(defaultDog.copy(age = 25)) must beSuccessfulTry
dogHouse.dogsByAge(20, 30) must contain(defaultDog.copy(age = 25))
}
}
// Excellent
"Dog house" should {
"Add dog with age 25 and returns with dogByAgeInMonths()" in {
val dog = defaultDog.withAgeInMonths(25)
dogHouse.addDog(dog) must beDogAdded
dogHouse.dogsByAgeInMonths(from = 20, to = 30) must haveDog(dog)
}
}
As your software grows,
it becomes less readable.
It’s all about
paying
attention to
the details.
Design
in a Nutshell
Make code easier to change
Find where to change
Know fast what to change
Fast reaction to pain, hiding pains
Do not bypass layers, avoid leaky abstractions
Focus about ‘why’ and not ‘how’
Our goals in
design
Software Design
Abstraction
Refinement
Modularity
Data Structure
Software Procedure
Information Hiding
Software Architecture
Control Hierarchy
Structure Partitioning
Four rules of simple
design:
1. Tests Pass
2. Expresses intent
3. No duplication (DRY)
4. Small
Kent Beck
Domain Driven Design (DDD)
- Domain focus, Domain expert
- Bounded contexts
- Building blocks (Entities, Repositories,
Domain event, services)
Eric Evans
Approaches for design lifecycles
Big Design Up-Front
Waterfall
Well defined process
Architects culture
UML
Big Design Up-Front
Long process
Documents becomes stale
In any case software is changed
and will be changed
Narrows the world of a developer
Waterfall
Well defined process
Architects culture
UML
Approaches for design lifecycles
TDD – Beginner’s mind
Code from the first day and make
changes along the way
Don’t care about architecture or
platforms/cloud envs
Approaches for design lifecycles
Evolutionary Design
Persistent might be completely
different
Domain might change
dramatically
We expose API which is wrong
but need to be supported
We don’t think about our
consumers
Moving to be eventual consistent
might break everything
Approaches for design lifecycles
Evolutionary Design
TDD – Beginner’s mind
Code from the first day and make
changes along the way
Don’t care about architecture or
platforms/cloud envs
If we pay attention to design principles
we’ll be able to change everything.
But we can do better.
Obviously, there is large spectrum
between the 2 approaches.
Evolutionary
Design
Big
Design
Up-Front
Evolutionary
Design
Big
Design
Up-Front
There’s no one coherent solution.
We’re engineers!
Like doctors, we need to look for a good fit.
Tools for determining where your
project is on the spectrum
#1 | Size Matters
#1 | Size Matters
Big project:
We need some
up-front design
Smaller
project:
Beginner’s
mind might
work
#2 | Lifecycle Matters
Kent Beck
#2 | Lifecycle Matters
Beginner’s mind
Should be done with
design, and we gain info
already
#3 | Consumers Matter
Are we exposing internal APIs?
Are we exposing external APIs?
Are we producing / consuming
events from queue?
It is always a good
idea to design the
domain and API
with your consumers
Walking skeleton is great, but not enough.
You need to actually develop the obvious
on the first day – Sunny day with minimum.
#4 | Fill in the obvious
Filling in the obvious
gets you into the
domain, feel the pain
and address it.
There are more unknown pains that you be
able to discover only when start coding
#5 | YAGNI is no excuse to deliver bad design
Sometimes, taking the time to think in advance
about design details is a good thing.
You’re an engineer, you get paid to think.
#5 | YAGNI is no excuse to deliver bad design
Sometimes, taking the time to think in advance
about design details is a good thing.
You’re an engineer, you get paid to think.
#6 | TDD is not Test-Driven Design
It’s not enough that your tests pass.
Your software can still suck.
TDD is a tool that gives you confidence in design.
Clean Code Design
Takeaways
You wake up in the morning to deliver,
sustainable delivery.
Clean Code Design
Takeaways
You wake up in the morning to deliver,
sustainable delivery.
Even though you code for the machine,
it needs to be read as a story for humans.
Clean Code Design
Takeaways
You wake up in the morning to deliver,
sustainable delivery.
Even though you code for the machine,
it needs to be read as a story for humans.
Find the balance between
up-front design and evolutionary design.
Clean Code Design
Takeaways
You wake up in the morning to deliver,
sustainable delivery.
Even though you code for the machine,
it needs to be read as a story for humans.
Find the balance between
up-front design and evolutionary design.
You get paid to make hard and ???
decisions.
Thank You
linkedin/in/blochkfir github.com/kfiron@kfirondevkfirb@wix.com http://kfiron.com

Más contenido relacionado

La actualidad más candente

Building the right team | Ralf C. Adam
Building the right team | Ralf C. AdamBuilding the right team | Ralf C. Adam
Building the right team | Ralf C. AdamRalf C. Adam
 
top developer mistakes
top developer mistakes top developer mistakes
top developer mistakes Hanokh Aloni
 
Moving from boxed title Game Development to F2P | Ralf C. Adam
Moving from boxed title Game Development to F2P | Ralf C. AdamMoving from boxed title Game Development to F2P | Ralf C. Adam
Moving from boxed title Game Development to F2P | Ralf C. AdamRalf C. Adam
 
WeActuallyBuildStuff - Extreme Programming Live
WeActuallyBuildStuff - Extreme Programming LiveWeActuallyBuildStuff - Extreme Programming Live
WeActuallyBuildStuff - Extreme Programming LiveJohannes Brodwall
 
Seven Lies my Project Manager told me | Ralf C. Adam
Seven Lies my Project Manager told me | Ralf C. AdamSeven Lies my Project Manager told me | Ralf C. Adam
Seven Lies my Project Manager told me | Ralf C. AdamRalf C. Adam
 
Extreme Programming (XP): Revisted
Extreme Programming (XP): RevistedExtreme Programming (XP): Revisted
Extreme Programming (XP): RevistedMike Harris
 
How'd we get here? A guide to Architectural Decision Records
How'd we get here? A guide to Architectural Decision RecordsHow'd we get here? A guide to Architectural Decision Records
How'd we get here? A guide to Architectural Decision RecordsRafael Dohms
 
Experience Agile Programming - Kiev
Experience Agile Programming - KievExperience Agile Programming - Kiev
Experience Agile Programming - KievJohannes Brodwall
 

La actualidad más candente (11)

Building the right team | Ralf C. Adam
Building the right team | Ralf C. AdamBuilding the right team | Ralf C. Adam
Building the right team | Ralf C. Adam
 
Make a better with clean code
Make a better with clean codeMake a better with clean code
Make a better with clean code
 
top developer mistakes
top developer mistakes top developer mistakes
top developer mistakes
 
Moving from boxed title Game Development to F2P | Ralf C. Adam
Moving from boxed title Game Development to F2P | Ralf C. AdamMoving from boxed title Game Development to F2P | Ralf C. Adam
Moving from boxed title Game Development to F2P | Ralf C. Adam
 
WeActuallyBuildStuff - Extreme Programming Live
WeActuallyBuildStuff - Extreme Programming LiveWeActuallyBuildStuff - Extreme Programming Live
WeActuallyBuildStuff - Extreme Programming Live
 
Scaling july 2014 4.key
Scaling july 2014 4.keyScaling july 2014 4.key
Scaling july 2014 4.key
 
Emperors new clothes_jab
Emperors new clothes_jabEmperors new clothes_jab
Emperors new clothes_jab
 
Seven Lies my Project Manager told me | Ralf C. Adam
Seven Lies my Project Manager told me | Ralf C. AdamSeven Lies my Project Manager told me | Ralf C. Adam
Seven Lies my Project Manager told me | Ralf C. Adam
 
Extreme Programming (XP): Revisted
Extreme Programming (XP): RevistedExtreme Programming (XP): Revisted
Extreme Programming (XP): Revisted
 
How'd we get here? A guide to Architectural Decision Records
How'd we get here? A guide to Architectural Decision RecordsHow'd we get here? A guide to Architectural Decision Records
How'd we get here? A guide to Architectural Decision Records
 
Experience Agile Programming - Kiev
Experience Agile Programming - KievExperience Agile Programming - Kiev
Experience Agile Programming - Kiev
 

Similar a A sweet taste of clean code and software design

Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkTaming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkJoseph Yoder
 
Code Quality Makes Your Job Easier
Code Quality Makes Your Job EasierCode Quality Makes Your Job Easier
Code Quality Makes Your Job EasierTonya Mork
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureThomas Jaskula
 
WordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPressWordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPressmtoppa
 
Are Agile Projects Doomed to Half-Baked Design?
Are Agile Projects Doomed to Half-Baked Design?Are Agile Projects Doomed to Half-Baked Design?
Are Agile Projects Doomed to Half-Baked Design?theinfonaut
 
Agile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovAgile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovSvetlin Nakov
 
Writing Code for Humans, not Computers
Writing Code for Humans, not ComputersWriting Code for Humans, not Computers
Writing Code for Humans, not ComputersRené Cacheaux
 
Clean code is not the goal - working software is
Clean code is not the goal - working software isClean code is not the goal - working software is
Clean code is not the goal - working software isEdorian
 
Agile Methodologies And Extreme Programming
Agile Methodologies And Extreme ProgrammingAgile Methodologies And Extreme Programming
Agile Methodologies And Extreme ProgrammingUtkarsh Khare
 
Dominik Veselý - Vše co jste kdy chtěli vědět o CI a báli jste se zeptat
Dominik Veselý - Vše co jste kdy chtěli vědět o CI a báli jste se zeptatDominik Veselý - Vše co jste kdy chtěli vědět o CI a báli jste se zeptat
Dominik Veselý - Vše co jste kdy chtěli vědět o CI a báli jste se zeptatmdevtalk
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional ProgrammerDave Cross
 
How to Do Kick-Ass Software Development
How to Do Kick-Ass Software DevelopmentHow to Do Kick-Ass Software Development
How to Do Kick-Ass Software DevelopmentJosiah Renaudin
 
From dev to ops and beyond - getting it done
From dev to ops and beyond - getting it doneFrom dev to ops and beyond - getting it done
From dev to ops and beyond - getting it doneEdorian
 
Software Craftsmanship @ Ntnu
Software Craftsmanship @ NtnuSoftware Craftsmanship @ Ntnu
Software Craftsmanship @ Ntnugoeran
 
Planning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teamsPlanning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teamsChristian Heilmann
 
The Architect's Two Hats
The Architect's Two HatsThe Architect's Two Hats
The Architect's Two HatsBen Stopford
 

Similar a A sweet taste of clean code and software design (20)

Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkTaming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
 
Code Quality Makes Your Job Easier
Code Quality Makes Your Job EasierCode Quality Makes Your Job Easier
Code Quality Makes Your Job Easier
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
WordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPressWordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPress
 
Are Agile Projects Doomed to Half-Baked Design?
Are Agile Projects Doomed to Half-Baked Design?Are Agile Projects Doomed to Half-Baked Design?
Are Agile Projects Doomed to Half-Baked Design?
 
Agile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovAgile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin Nakov
 
Writing Code for Humans, not Computers
Writing Code for Humans, not ComputersWriting Code for Humans, not Computers
Writing Code for Humans, not Computers
 
Clean code is not the goal - working software is
Clean code is not the goal - working software isClean code is not the goal - working software is
Clean code is not the goal - working software is
 
Raising the Bar
Raising the BarRaising the Bar
Raising the Bar
 
Agile Methodologies And Extreme Programming
Agile Methodologies And Extreme ProgrammingAgile Methodologies And Extreme Programming
Agile Methodologies And Extreme Programming
 
Dominik Veselý - Vše co jste kdy chtěli vědět o CI a báli jste se zeptat
Dominik Veselý - Vše co jste kdy chtěli vědět o CI a báli jste se zeptatDominik Veselý - Vše co jste kdy chtěli vědět o CI a báli jste se zeptat
Dominik Veselý - Vše co jste kdy chtěli vědět o CI a báli jste se zeptat
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
How to Do Kick-Ass Software Development
How to Do Kick-Ass Software DevelopmentHow to Do Kick-Ass Software Development
How to Do Kick-Ass Software Development
 
From dev to ops and beyond - getting it done
From dev to ops and beyond - getting it doneFrom dev to ops and beyond - getting it done
From dev to ops and beyond - getting it done
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
Software Craftsmanship @ Ntnu
Software Craftsmanship @ NtnuSoftware Craftsmanship @ Ntnu
Software Craftsmanship @ Ntnu
 
Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)
 
Planning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teamsPlanning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teams
 
The Architect's Two Hats
The Architect's Two HatsThe Architect's Two Hats
The Architect's Two Hats
 
Ad505 dev blast
Ad505 dev blastAd505 dev blast
Ad505 dev blast
 

Más de Kfir Bloch

Increasing velocity via serless semantics
Increasing velocity via serless semanticsIncreasing velocity via serless semantics
Increasing velocity via serless semanticsKfir Bloch
 
TDD For Mortals
TDD For MortalsTDD For Mortals
TDD For MortalsKfir Bloch
 
Design pattern-refactor-functional
Design pattern-refactor-functionalDesign pattern-refactor-functional
Design pattern-refactor-functionalKfir Bloch
 
Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Kfir Bloch
 
Scala from the Trenches - Java One 2016
Scala from the Trenches - Java One 2016Scala from the Trenches - Java One 2016
Scala from the Trenches - Java One 2016Kfir Bloch
 
Scala from the Trenches
Scala from the Trenches Scala from the Trenches
Scala from the Trenches Kfir Bloch
 
The art of decomposing monoliths
The art of decomposing monolithsThe art of decomposing monoliths
The art of decomposing monolithsKfir Bloch
 

Más de Kfir Bloch (8)

Increasing velocity via serless semantics
Increasing velocity via serless semanticsIncreasing velocity via serless semantics
Increasing velocity via serless semantics
 
Rest is bad
Rest is badRest is bad
Rest is bad
 
TDD For Mortals
TDD For MortalsTDD For Mortals
TDD For Mortals
 
Design pattern-refactor-functional
Design pattern-refactor-functionalDesign pattern-refactor-functional
Design pattern-refactor-functional
 
Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)
 
Scala from the Trenches - Java One 2016
Scala from the Trenches - Java One 2016Scala from the Trenches - Java One 2016
Scala from the Trenches - Java One 2016
 
Scala from the Trenches
Scala from the Trenches Scala from the Trenches
Scala from the Trenches
 
The art of decomposing monoliths
The art of decomposing monolithsThe art of decomposing monoliths
The art of decomposing monoliths
 

Último

Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 

Último (20)

Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 

A sweet taste of clean code and software design

  • 1. A Sweet Taste of Clean Code & Software Design Kfir Bloch, Developer linkedin/in/blochkfir github.com/kfiron@kfirondevkfirb@wix.com http://kfiron.com
  • 2. Hi. I am Kfir. coding, open source software, cooking HOBBIES Lithuania Ukraine Vilnius Kyiv Dnipro Wix Engineering Locations Israel Tel-Aviv Be’er Sheva
  • 4. As software engineers, we try to... Develop / deliver fast Have a software which is easier to change
  • 5. Clean Code and Software Design Can help us do it.
  • 6. Clean Code in a Nutshell
  • 7. Software code that is formatted in a modularized and systematic manner so that another coder can easily interpret or modify it. Wikipedia Clean Code
  • 8. Clean Code “You can call it beautiful code when the code also makes it look like the language was made for the problem.” Ward Cunningham
  • 9. Clean Code “Clean code always looks like it was written by someone who cares.” Michael feathers “You can call it beautiful code when the code also makes it look like the language was made for the problem.” Ward Cunningham
  • 10. Clean Code “Clean code always looks like it was written by someone who cares.” Michael feathers “Clean code is about recognizing that your audience isn't just a computer, it's real- live humans!” Cory House “You can call it beautiful code when the code also makes it look like the language was made for the problem.” Ward Cunningham
  • 11. Clean Code should be like your car’s dashboard. A sneak preview gives you all the information you need.
  • 12. Solving a problem fast isn’t enough.
  • 13. Solving a problem fast isn’t enough. Organizing things for yourself isn’t enough.
  • 14. Solving a problem fast isn’t enough. Organizing things for yourself isn’t enough. Others need to make sense of it too.
  • 15. Indentations, White spaces, Tabs Naming! reveals intent Small functions Length of lines Number of arguments When to break lines Structured packages and folders DRY – don’t repeat yourself Declarative and expressive And more… Clean Code Characteristics
  • 16. Indentations, White spaces, Tabs Naming! reveals intent Small functions Length of lines Number of arguments When to break lines Structured packages and folders DRY – don’t repeat yourself Declarative and expressive And more… Clean Code Characteristics It’s all about paying attention to the details.
  • 17. Can you tell what this function does? def send(userId: String, to : String, cc : String, body: String) ={ if(cc != null && !cc.contains("@") && !cc.contains(".")){ Failure(new InvalidEmailException("invalid email")) } else { if(to != null && !to.contains("@") && !to.contains(".")) Failure(new InvalidEmailException("invalid email")) else{ bi.logEmailSent(userId, System.currentTimeMillis()) Success(mail.sendEmail(userId, to, cc, body) ) } } }
  • 18. def sendEmail(emailMessage: EmailMessage): Try[Id] = Try { validateEmail(emailMessage.to) validateEmail(emailMessage.cc) bi.logEmailSent(emailMessage.userId, System.currentTimeMillis()) mail.sendEmail(emailMessage) } def validateEmail(email: String): Unit = if (email != null && !email.contains("@") && !email.contains(".")) { throw new InvalidEmailException(s"the email: [$email] is invalid") }
  • 19. // OK "Dog service" should { "add dog" in { dogHouse.addDog(defaultDog.copy(age = 25)) must beSuccessfulTry dogHouse.dogsByAge(20, 30) must contain(defaultDog.copy(age = 25)) } } // Excellent "Dog house" should { "Add dog with age 25 and returns with dogByAgeInMonths()" in { val dog = defaultDog.withAgeInMonths(25) dogHouse.addDog(dog) must beDogAdded dogHouse.dogsByAgeInMonths(from = 20, to = 30) must haveDog(dog) } }
  • 20. As your software grows, it becomes less readable. It’s all about paying attention to the details.
  • 22. Make code easier to change Find where to change Know fast what to change Fast reaction to pain, hiding pains Do not bypass layers, avoid leaky abstractions Focus about ‘why’ and not ‘how’ Our goals in design
  • 23. Software Design Abstraction Refinement Modularity Data Structure Software Procedure Information Hiding Software Architecture Control Hierarchy Structure Partitioning
  • 24. Four rules of simple design: 1. Tests Pass 2. Expresses intent 3. No duplication (DRY) 4. Small Kent Beck
  • 25. Domain Driven Design (DDD) - Domain focus, Domain expert - Bounded contexts - Building blocks (Entities, Repositories, Domain event, services) Eric Evans
  • 26. Approaches for design lifecycles Big Design Up-Front Waterfall Well defined process Architects culture UML
  • 27. Big Design Up-Front Long process Documents becomes stale In any case software is changed and will be changed Narrows the world of a developer Waterfall Well defined process Architects culture UML Approaches for design lifecycles
  • 28. TDD – Beginner’s mind Code from the first day and make changes along the way Don’t care about architecture or platforms/cloud envs Approaches for design lifecycles Evolutionary Design
  • 29. Persistent might be completely different Domain might change dramatically We expose API which is wrong but need to be supported We don’t think about our consumers Moving to be eventual consistent might break everything Approaches for design lifecycles Evolutionary Design TDD – Beginner’s mind Code from the first day and make changes along the way Don’t care about architecture or platforms/cloud envs
  • 30. If we pay attention to design principles we’ll be able to change everything. But we can do better.
  • 31. Obviously, there is large spectrum between the 2 approaches. Evolutionary Design Big Design Up-Front
  • 32. Evolutionary Design Big Design Up-Front There’s no one coherent solution. We’re engineers! Like doctors, we need to look for a good fit.
  • 33. Tools for determining where your project is on the spectrum
  • 34. #1 | Size Matters
  • 35. #1 | Size Matters Big project: We need some up-front design Smaller project: Beginner’s mind might work
  • 36. #2 | Lifecycle Matters Kent Beck
  • 37. #2 | Lifecycle Matters Beginner’s mind Should be done with design, and we gain info already
  • 38. #3 | Consumers Matter Are we exposing internal APIs? Are we exposing external APIs? Are we producing / consuming events from queue? It is always a good idea to design the domain and API with your consumers
  • 39. Walking skeleton is great, but not enough. You need to actually develop the obvious on the first day – Sunny day with minimum. #4 | Fill in the obvious Filling in the obvious gets you into the domain, feel the pain and address it. There are more unknown pains that you be able to discover only when start coding
  • 40. #5 | YAGNI is no excuse to deliver bad design Sometimes, taking the time to think in advance about design details is a good thing. You’re an engineer, you get paid to think.
  • 41. #5 | YAGNI is no excuse to deliver bad design Sometimes, taking the time to think in advance about design details is a good thing. You’re an engineer, you get paid to think. #6 | TDD is not Test-Driven Design It’s not enough that your tests pass. Your software can still suck. TDD is a tool that gives you confidence in design.
  • 42. Clean Code Design Takeaways You wake up in the morning to deliver, sustainable delivery.
  • 43. Clean Code Design Takeaways You wake up in the morning to deliver, sustainable delivery. Even though you code for the machine, it needs to be read as a story for humans.
  • 44. Clean Code Design Takeaways You wake up in the morning to deliver, sustainable delivery. Even though you code for the machine, it needs to be read as a story for humans. Find the balance between up-front design and evolutionary design.
  • 45. Clean Code Design Takeaways You wake up in the morning to deliver, sustainable delivery. Even though you code for the machine, it needs to be read as a story for humans. Find the balance between up-front design and evolutionary design. You get paid to make hard and ??? decisions.