際際滷

際際滷Share a Scribd company logo
YAGNI
You Aint Gonna Need It
YAGNI
YAGNI = You Aint Gonna Need It
Emerged as one of the key principles of Extreme Programming
Always implement things when you actually need them, never when you just think that
you may need them
Do the Simplest Thing That Could Possibly Work
YAGNI Principle and Clean Code
YAGNI
Reasons why this principle exists:
 Prevents waste of time with unnecessary work
 Improves the developer productivity and product simplicity
 Remember: features are expensive, both to develop and maintain
 Product changes requirements, all the time!
YAGNI
Every line of code we dont write is dollars we didnt spend, and time on the calendar
we get back for free.  Tim Evans-Ariyeh
The cheapest, fastest, and most reliable components of a computer system are those
that arent there.  Gordon Bell
YAGNI
The cost of build: all the effort spent on analyzing, programming, and testing this now
useless feature.
 More code to compile
 More code to maintain
 More chances to cause bugs
 Confuse developers. Whats this code for?
YAGNI
The common reason why people build presumptive features is because they think it will
be cheaper to build it now rather than build it later.
Cost of delay: put a full storm risks feature into production and be generating revenue
only months earlier.
cost of carry: the presumptive feature adds some complexity to the software, this
complexity makes it harder to modify and debug that software, thus increasing the cost
of other features.
YAGNI
Yagni is only a viable strategy if the code is easy to change, so expending effort on
refactoring isn't a violation of yagni because refactoring makes the code more
malleable.
It actually requires malleable code.
Clean Code
Clean Code
Code that is easy to understand and easy to change
It is not enough for code to work!
"Any fool can write code that a computer can understand.
Good programmers write code that humans can understand."
- Martin Fowler
Robert C. Martin
Clean code
You should name a variable using the same care with which you name a first-born
child.
It is not the language that makes programs appear simple. It is the programmer that
make the language appear simple!
Of course bad code can be cleaned up. But its very expensive.
Code, without tests, is not clean. No matter how elegant it is, no matter how readable
and accessible, if it hath not tests, it be unclean
If you're good at the debugger it means you spent a lot of time debugging. I don't want
you to be good at the debugger.
Robert C. Martin
Clean code - Meaningful Names
Variables
int count; // elapsed time in days;
int = elapsedTimeInDays;
Classes
Represent "things" - should be nouns, avoid verbs
For example: Customer, WikiPage, Account, and AddressParser
Methods
Do things - should have verb or verb phrase names
For example: convert(), delete(), or save().
Clean code - Arguments
A function shouldnt have more than 3 arguments. Keep it as low as possible.
How to solve it?
When a function seems to need more than two or three arguments, it is likely that some
of those arguments ought to be wrapped into a class of their own.
Reducing the number of arguments by creating objects out of them may seem like
cheating, but its not.
Clean code - Methods or functions
The first rule of functions is that they should be small. The second rule of functions is
that they should be smaller than that - Robert Martin
Do one thing!
 Methods should not have more than an average of 20 code lines
 If needed, extract it to another method with a proper name that does a single thing
It's always better read one method containing 20 lines calling 10 different methods,
than method containing 400 lines unnamed logic and twisted commentary.
Clean code - Classes
Rather than count lines, count responsibilities - Single Responsibility Principle
Many small classes is better
Large, multipurpose classes force us to scroll through code that we dont need to know
about right now.
OCP, Open Close Principle
Classes should be open for extension but closed for modifications
Ideally, we add new functionality by extending the system, not modifying the existing code.
Clean code - Classes
Classes should have a small number of instance variables
High cohesion is when you have a class that does a well defined job. Low cohesion is when a class does a lot of
jobs that don't have much in common.
Methods should affect as many variables in the class as possible to achieve high
cohesion
When variables arent used by many methods, those are probably begging for a new
class
When classes lose cohesion, its time to split them up.
Clean code - DRY principle
Dont Repeat Yourself (DRY)
Write Every Time (WET)
The biggest benefit of using DRY is maintainability.
 Readability
 Reuse
 Cost
 Testing
Clean code - Comments
If you are writing comments to prove your point, you are doing mistake!
Our code should explain everything. Be DRY
Correct naming can prevent comments.
Comments tend to be obsolete
*Legal and copyright comments are a different situation, they are necessary
Conclusion
Clean code means benefits: pleasant work, less stress, unit tests, easy debugging
and better quality.
You are reducing the cost of maintenance of the application you are writing.
You are making it easier to estimate the time needed for new features.
You are making it easier to fix bugs.
Essentially you are making the life easier for everyone involved in the project.
Thank you!
luanmalaguti@gmail.com
www.linkedin.com/in/luanmalaguti
Luan Malaguti Reffatti
Java Developer

More Related Content

What's hot (20)

Pair Programming
Pair ProgrammingPair Programming
Pair Programming
Siriwat Jithunsa
Unit Test Your Database
Unit Test Your DatabaseUnit Test Your Database
Unit Test Your Database
David Wheeler
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database clusterGrokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking VN
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
John Ferguson Smart Limited
Logging with log4j v1.2
Logging with log4j v1.2Logging with log4j v1.2
Logging with log4j v1.2
Kamal Mettananda
React Tech Salon
React Tech SalonReact Tech Salon
React Tech Salon
Chenguang ZHANG
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
Shaul Rosenzwieg
Clean code
Clean codeClean code
Clean code
Alvaro Garc鱈a Loaisa
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101
MongoDB
Clean code
Clean codeClean code
Clean code
ifnu bima
Deep Dive on Amazon DynamoDB
Deep Dive on Amazon DynamoDBDeep Dive on Amazon DynamoDB
Deep Dive on Amazon DynamoDB
Amazon Web Services
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
Kent Huang
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
YeurDreamin'
Go lang
Go langGo lang
Go lang
Suelen Carvalho
More mastering the art of indexing
More mastering the art of indexingMore mastering the art of indexing
More mastering the art of indexing
Yoshinori Matsunobu
Nodejs
NodejsNodejs
Nodejs
Prem Sanil
Clean code
Clean codeClean code
Clean code
Arturo Herrero
How to go about testing in React?
How to go about testing in React? How to go about testing in React?
How to go about testing in React?
Lisa Gagarina
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
Edureka!
Unit Test Your Database
Unit Test Your DatabaseUnit Test Your Database
Unit Test Your Database
David Wheeler
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database clusterGrokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking VN
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
Logging with log4j v1.2
Logging with log4j v1.2Logging with log4j v1.2
Logging with log4j v1.2
Kamal Mettananda
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101
MongoDB
Clean code
Clean codeClean code
Clean code
ifnu bima
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
Kent Huang
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
YeurDreamin'
More mastering the art of indexing
More mastering the art of indexingMore mastering the art of indexing
More mastering the art of indexing
Yoshinori Matsunobu
How to go about testing in React?
How to go about testing in React? How to go about testing in React?
How to go about testing in React?
Lisa Gagarina
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
Edureka!

Similar to YAGNI Principle and Clean Code (20)

[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay Da Nang
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
Knoldus Inc.
Clean code quotes - Cita巽探es e provoca巽探es
Clean code quotes - Cita巽探es e provoca巽探esClean code quotes - Cita巽探es e provoca巽探es
Clean code quotes - Cita巽探es e provoca巽探es
Andr辿 de Fontana Ignacio
Most valuable software design principles
Most valuable software design principlesMost valuable software design principles
Most valuable software design principles
Jeroen Hildering
Code quality
Code quality Code quality
Code quality
Sunil Prasad
Put to the Test
Put to the TestPut to the Test
Put to the Test
Kevlin Henney
Clean code
Clean codeClean code
Clean code
Simon S旦nnby
Coding Standards
Coding StandardsCoding Standards
Coding Standards
Jeevitesh Ms
WordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPressWordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPress
mtoppa
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
Metin Ogurlu
Best pratice
Best praticeBest pratice
Best pratice
Eugenio Romano
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
Bill Buchan
The View - 30 proven Lotuscript tips
The View - 30 proven Lotuscript tipsThe View - 30 proven Lotuscript tips
The View - 30 proven Lotuscript tips
Bill Buchan
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
John Choi
9-Coding.ppt
9-Coding.ppt9-Coding.ppt
9-Coding.ppt
KomalSinghGill
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
jexp
Managing and evolving JavaScript Code
Managing and evolving JavaScript CodeManaging and evolving JavaScript Code
Managing and evolving JavaScript Code
Jean Carlo Emer
Clean Code Software Engineering
Clean Code Software Engineering Clean Code Software Engineering
Clean Code Software Engineering
Inocentshuja Ahmad
Are You a SOLID Coder?
Are You a SOLID Coder?Are You a SOLID Coder?
Are You a SOLID Coder?
Steve Green
[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay Da Nang
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
Knoldus Inc.
Clean code quotes - Cita巽探es e provoca巽探es
Clean code quotes - Cita巽探es e provoca巽探esClean code quotes - Cita巽探es e provoca巽探es
Clean code quotes - Cita巽探es e provoca巽探es
Andr辿 de Fontana Ignacio
Most valuable software design principles
Most valuable software design principlesMost valuable software design principles
Most valuable software design principles
Jeroen Hildering
Coding Standards
Coding StandardsCoding Standards
Coding Standards
Jeevitesh Ms
WordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPressWordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPress
mtoppa
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
Metin Ogurlu
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
Bill Buchan
The View - 30 proven Lotuscript tips
The View - 30 proven Lotuscript tipsThe View - 30 proven Lotuscript tips
The View - 30 proven Lotuscript tips
Bill Buchan
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
John Choi
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
jexp
Managing and evolving JavaScript Code
Managing and evolving JavaScript CodeManaging and evolving JavaScript Code
Managing and evolving JavaScript Code
Jean Carlo Emer
Clean Code Software Engineering
Clean Code Software Engineering Clean Code Software Engineering
Clean Code Software Engineering
Inocentshuja Ahmad
Are You a SOLID Coder?
Are You a SOLID Coder?Are You a SOLID Coder?
Are You a SOLID Coder?
Steve Green

Recently uploaded (20)

AI-Powered Chatbots for Employee Support
AI-Powered Chatbots for Employee SupportAI-Powered Chatbots for Employee Support
AI-Powered Chatbots for Employee Support
AutomationEdge Technologies
Elastic Search Engineer Certification - Virtual
Elastic Search Engineer Certification - VirtualElastic Search Engineer Certification - Virtual
Elastic Search Engineer Certification - Virtual
Gon巽alo Pereira
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
Ava Isley
Account Cash Flow Statement Report Generate in odoo
Account Cash Flow Statement Report Generate in odooAccount Cash Flow Statement Report Generate in odoo
Account Cash Flow Statement Report Generate in odoo
AxisTechnolabs
Adobe After Effects Crack latest version 2025
Adobe After Effects Crack latest version 2025Adobe After Effects Crack latest version 2025
Adobe After Effects Crack latest version 2025
saniasabbba
Minitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free DownloadMinitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free Download
v3r2eptd2q
Metaverse Meetup: Explore Mulesoft MAC Project
Metaverse Meetup: Explore  Mulesoft MAC ProjectMetaverse Meetup: Explore  Mulesoft MAC Project
Metaverse Meetup: Explore Mulesoft MAC Project
GiulioPicchi
Wondershare Filmora Crack Free Download
Wondershare Filmora  Crack Free DownloadWondershare Filmora  Crack Free Download
Wondershare Filmora Crack Free Download
zqeevcqb3t
EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]
bhagasufyan
Instagram Feed Snippet, Instagram posts display in odoo website
Instagram Feed Snippet, Instagram posts display in odoo websiteInstagram Feed Snippet, Instagram posts display in odoo website
Instagram Feed Snippet, Instagram posts display in odoo website
AxisTechnolabs
salesforce development services - Alt digital
salesforce development services - Alt digitalsalesforce development services - Alt digital
salesforce development services - Alt digital
Alt Digital Technologies
AutoDesk Revit Crack | Revit Update 2025 free download
AutoDesk Revit Crack | Revit Update 2025 free downloadAutoDesk Revit Crack | Revit Update 2025 free download
AutoDesk Revit Crack | Revit Update 2025 free download
anamaslam971
Why Hire Python Developers? Key Benefits for Your Business
Why Hire Python Developers? Key Benefits for Your BusinessWhy Hire Python Developers? Key Benefits for Your Business
Why Hire Python Developers? Key Benefits for Your Business
Mypcot Infotech
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber ScaleAI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
Alluxio, Inc.
Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9
Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9
Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9
Yann-Ga谷l Gu辿h辿neuc
SolidWorks 2025 Crack free Download updated
SolidWorks 2025 Crack  free Download updatedSolidWorks 2025 Crack  free Download updated
SolidWorks 2025 Crack free Download updated
sanasabaa73
Hire Odoo Developer OnestopDA Experts.
Hire Odoo Developer  OnestopDA Experts.Hire Odoo Developer  OnestopDA Experts.
Hire Odoo Developer OnestopDA Experts.
OnestopDA
A Brief Introduction About Raman Bhaumik
A Brief Introduction About Raman BhaumikA Brief Introduction About Raman Bhaumik
A Brief Introduction About Raman Bhaumik
Raman Bhaumik
SE- Lecture 5 SE for easy understanding.ppt
SE- Lecture 5 SE for easy understanding.pptSE- Lecture 5 SE for easy understanding.ppt
SE- Lecture 5 SE for easy understanding.ppt
theworldimagine985
AVG Antivirus Crack With Free version Download 2025 [Latest]
AVG Antivirus Crack With Free version Download 2025 [Latest]AVG Antivirus Crack With Free version Download 2025 [Latest]
AVG Antivirus Crack With Free version Download 2025 [Latest]
haroonsaeed605
Elastic Search Engineer Certification - Virtual
Elastic Search Engineer Certification - VirtualElastic Search Engineer Certification - Virtual
Elastic Search Engineer Certification - Virtual
Gon巽alo Pereira
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
Ava Isley
Account Cash Flow Statement Report Generate in odoo
Account Cash Flow Statement Report Generate in odooAccount Cash Flow Statement Report Generate in odoo
Account Cash Flow Statement Report Generate in odoo
AxisTechnolabs
Adobe After Effects Crack latest version 2025
Adobe After Effects Crack latest version 2025Adobe After Effects Crack latest version 2025
Adobe After Effects Crack latest version 2025
saniasabbba
Minitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free DownloadMinitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free Download
v3r2eptd2q
Metaverse Meetup: Explore Mulesoft MAC Project
Metaverse Meetup: Explore  Mulesoft MAC ProjectMetaverse Meetup: Explore  Mulesoft MAC Project
Metaverse Meetup: Explore Mulesoft MAC Project
GiulioPicchi
Wondershare Filmora Crack Free Download
Wondershare Filmora  Crack Free DownloadWondershare Filmora  Crack Free Download
Wondershare Filmora Crack Free Download
zqeevcqb3t
EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]
bhagasufyan
Instagram Feed Snippet, Instagram posts display in odoo website
Instagram Feed Snippet, Instagram posts display in odoo websiteInstagram Feed Snippet, Instagram posts display in odoo website
Instagram Feed Snippet, Instagram posts display in odoo website
AxisTechnolabs
salesforce development services - Alt digital
salesforce development services - Alt digitalsalesforce development services - Alt digital
salesforce development services - Alt digital
Alt Digital Technologies
AutoDesk Revit Crack | Revit Update 2025 free download
AutoDesk Revit Crack | Revit Update 2025 free downloadAutoDesk Revit Crack | Revit Update 2025 free download
AutoDesk Revit Crack | Revit Update 2025 free download
anamaslam971
Why Hire Python Developers? Key Benefits for Your Business
Why Hire Python Developers? Key Benefits for Your BusinessWhy Hire Python Developers? Key Benefits for Your Business
Why Hire Python Developers? Key Benefits for Your Business
Mypcot Infotech
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber ScaleAI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
Alluxio, Inc.
Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9
Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9
Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9
Yann-Ga谷l Gu辿h辿neuc
SolidWorks 2025 Crack free Download updated
SolidWorks 2025 Crack  free Download updatedSolidWorks 2025 Crack  free Download updated
SolidWorks 2025 Crack free Download updated
sanasabaa73
Hire Odoo Developer OnestopDA Experts.
Hire Odoo Developer  OnestopDA Experts.Hire Odoo Developer  OnestopDA Experts.
Hire Odoo Developer OnestopDA Experts.
OnestopDA
A Brief Introduction About Raman Bhaumik
A Brief Introduction About Raman BhaumikA Brief Introduction About Raman Bhaumik
A Brief Introduction About Raman Bhaumik
Raman Bhaumik
SE- Lecture 5 SE for easy understanding.ppt
SE- Lecture 5 SE for easy understanding.pptSE- Lecture 5 SE for easy understanding.ppt
SE- Lecture 5 SE for easy understanding.ppt
theworldimagine985
AVG Antivirus Crack With Free version Download 2025 [Latest]
AVG Antivirus Crack With Free version Download 2025 [Latest]AVG Antivirus Crack With Free version Download 2025 [Latest]
AVG Antivirus Crack With Free version Download 2025 [Latest]
haroonsaeed605

YAGNI Principle and Clean Code

  • 2. YAGNI YAGNI = You Aint Gonna Need It Emerged as one of the key principles of Extreme Programming Always implement things when you actually need them, never when you just think that you may need them Do the Simplest Thing That Could Possibly Work
  • 4. YAGNI Reasons why this principle exists: Prevents waste of time with unnecessary work Improves the developer productivity and product simplicity Remember: features are expensive, both to develop and maintain Product changes requirements, all the time!
  • 5. YAGNI Every line of code we dont write is dollars we didnt spend, and time on the calendar we get back for free. Tim Evans-Ariyeh The cheapest, fastest, and most reliable components of a computer system are those that arent there. Gordon Bell
  • 6. YAGNI The cost of build: all the effort spent on analyzing, programming, and testing this now useless feature. More code to compile More code to maintain More chances to cause bugs Confuse developers. Whats this code for?
  • 7. YAGNI The common reason why people build presumptive features is because they think it will be cheaper to build it now rather than build it later. Cost of delay: put a full storm risks feature into production and be generating revenue only months earlier. cost of carry: the presumptive feature adds some complexity to the software, this complexity makes it harder to modify and debug that software, thus increasing the cost of other features.
  • 8. YAGNI Yagni is only a viable strategy if the code is easy to change, so expending effort on refactoring isn't a violation of yagni because refactoring makes the code more malleable. It actually requires malleable code.
  • 10. Clean Code Code that is easy to understand and easy to change It is not enough for code to work! "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler
  • 12. Clean code You should name a variable using the same care with which you name a first-born child. It is not the language that makes programs appear simple. It is the programmer that make the language appear simple! Of course bad code can be cleaned up. But its very expensive. Code, without tests, is not clean. No matter how elegant it is, no matter how readable and accessible, if it hath not tests, it be unclean If you're good at the debugger it means you spent a lot of time debugging. I don't want you to be good at the debugger. Robert C. Martin
  • 13. Clean code - Meaningful Names Variables int count; // elapsed time in days; int = elapsedTimeInDays; Classes Represent "things" - should be nouns, avoid verbs For example: Customer, WikiPage, Account, and AddressParser Methods Do things - should have verb or verb phrase names For example: convert(), delete(), or save().
  • 14. Clean code - Arguments A function shouldnt have more than 3 arguments. Keep it as low as possible. How to solve it? When a function seems to need more than two or three arguments, it is likely that some of those arguments ought to be wrapped into a class of their own. Reducing the number of arguments by creating objects out of them may seem like cheating, but its not.
  • 15. Clean code - Methods or functions The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that - Robert Martin Do one thing! Methods should not have more than an average of 20 code lines If needed, extract it to another method with a proper name that does a single thing It's always better read one method containing 20 lines calling 10 different methods, than method containing 400 lines unnamed logic and twisted commentary.
  • 16. Clean code - Classes Rather than count lines, count responsibilities - Single Responsibility Principle Many small classes is better Large, multipurpose classes force us to scroll through code that we dont need to know about right now. OCP, Open Close Principle Classes should be open for extension but closed for modifications Ideally, we add new functionality by extending the system, not modifying the existing code.
  • 17. Clean code - Classes Classes should have a small number of instance variables High cohesion is when you have a class that does a well defined job. Low cohesion is when a class does a lot of jobs that don't have much in common. Methods should affect as many variables in the class as possible to achieve high cohesion When variables arent used by many methods, those are probably begging for a new class When classes lose cohesion, its time to split them up.
  • 18. Clean code - DRY principle Dont Repeat Yourself (DRY) Write Every Time (WET) The biggest benefit of using DRY is maintainability. Readability Reuse Cost Testing
  • 19. Clean code - Comments If you are writing comments to prove your point, you are doing mistake! Our code should explain everything. Be DRY Correct naming can prevent comments. Comments tend to be obsolete *Legal and copyright comments are a different situation, they are necessary
  • 20. Conclusion Clean code means benefits: pleasant work, less stress, unit tests, easy debugging and better quality. You are reducing the cost of maintenance of the application you are writing. You are making it easier to estimate the time needed for new features. You are making it easier to fix bugs. Essentially you are making the life easier for everyone involved in the project.