SlideShare a Scribd company logo
YAGNI
You Ain’t Gonna Need It
YAGNI
YAGNI = You Ain’t 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 don’t write is dollars we didn’t 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 aren’t 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. What’s 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 it’s 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 shouldn’t 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 it’s 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 don’t 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 aren’t used by many methods, those are probably begging for a new
class
When classes lose cohesion, it’s 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

PPTX
PDF
Clean code
PPTX
Code Review Best Practices
PPTX
Code review
PDF
How to go about testing in React?
ODP
Clean code
PPTX
Exception handling in ASP .NET
PDF
Introduction to E2E in Cypress
Clean code
Code Review Best Practices
Code review
How to go about testing in React?
Clean code
Exception handling in ASP .NET
Introduction to E2E in Cypress

What's hot (20)

PPT
JavaScript - An Introduction
PPTX
clean code book summary - uncle bob - English version
PPTX
Jasmine framework
PPSX
PPTX
The Clean Architecture
PDF
What is Web Testing?
KEY
Clean Code
PPTX
The history of selenium
PDF
Swift Programming Language
PPT
Code coverage
PPTX
ReactJS presentation.pptx
PPTX
Clean code: SOLID
PPT
Clean Code summary
PDF
Java 8 features
PPTX
Introduction of stress testing
ODP
Best practices in Java
PDF
Mutation Testing
PDF
TDD Flow: The Mantra in Action
PPT
SOLID Design Principles
PDF
Code Refactoring
JavaScript - An Introduction
clean code book summary - uncle bob - English version
Jasmine framework
The Clean Architecture
What is Web Testing?
Clean Code
The history of selenium
Swift Programming Language
Code coverage
ReactJS presentation.pptx
Clean code: SOLID
Clean Code summary
Java 8 features
Introduction of stress testing
Best practices in Java
Mutation Testing
TDD Flow: The Mantra in Action
SOLID Design Principles
Code Refactoring
Ad

Similar to YAGNI Principle and Clean Code (20)

PPTX
Principled And Clean Coding
PPTX
Clean code presentation
PDF
Clean Code
PDF
Clean code-v2.2
PDF
Clean code and code smells
PDF
Most valuable software design principles
PDF
Clean Code V2
PPTX
Robert martin
PPSX
Clean code
PPTX
Clean code
PDF
Clean Code .Net Cheetsheets
PPTX
Clean Code
PPTX
Clean Code Part III - Craftsmanship at SoCal Code Camp
PPTX
Clean code - DSC DYPCOE
PDF
Clean Code
PPTX
Clean code quotes - Citações e provocações
PDF
Basics of writing clean code
PDF
Naming Things (with notes)
PDF
Agileee Developers Toolkit In The Agile World
PDF
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
Principled And Clean Coding
Clean code presentation
Clean Code
Clean code-v2.2
Clean code and code smells
Most valuable software design principles
Clean Code V2
Robert martin
Clean code
Clean code
Clean Code .Net Cheetsheets
Clean Code
Clean Code Part III - Craftsmanship at SoCal Code Camp
Clean code - DSC DYPCOE
Clean Code
Clean code quotes - Citações e provocações
Basics of writing clean code
Naming Things (with notes)
Agileee Developers Toolkit In The Agile World
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
Ad

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Introduction to Artificial Intelligence
PPTX
Transform Your Business with a Software ERP System
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
L1 - Introduction to python Backend.pptx
PDF
System and Network Administration Chapter 2
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ai tools demonstartion for schools and inter college
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
history of c programming in notes for students .pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Operating system designcfffgfgggggggvggggggggg
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Introduction to Artificial Intelligence
Transform Your Business with a Software ERP System
Upgrade and Innovation Strategies for SAP ERP Customers
Odoo Companies in India – Driving Business Transformation.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Wondershare Filmora 15 Crack With Activation Key [2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Odoo POS Development Services by CandidRoot Solutions
L1 - Introduction to python Backend.pptx
System and Network Administration Chapter 2
How to Migrate SBCGlobal Email to Yahoo Easily
ai tools demonstartion for schools and inter college
Internet Downloader Manager (IDM) Crack 6.42 Build 41
history of c programming in notes for students .pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx

YAGNI Principle and Clean Code

  • 2. YAGNI YAGNI = You Ain’t 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 don’t write is dollars we didn’t 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 aren’t 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. What’s 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 it’s 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 shouldn’t 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 it’s 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 don’t 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 aren’t used by many methods, those are probably begging for a new class When classes lose cohesion, it’s 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.