What is YAGNI coding rule, and why it helps?
YouTube Viewers YouTube Viewers
15.1K subscribers
6,317 views
0

 Published On Oct 23, 2020

Useless work is the worst! And it's especially expensive in programming. Avoid useless work at all cost, and reduce the scope whenever you can - this is your #QuickAnswer for today!

#programming #tech #softwaredevelopment #developer #sde

Clean Code (R. Martin) - US: https://amzn.to/3jVUEDU | UK: https://amzn.to/2Iij4Jz
Best Practices for Programmers - US: https://amzn.to/2SPRSEg | UK: https://amzn.to/2Fr2h6e

What is YAGNI coding rule, and why it matters?

You Aren't Gonna Need It - that’s what YAGNI stands for. Simple but effective acronym - invented as part of Extreme Programming (or XP for short) by Ron Jeffries. He said on his blog: Always implement things when you actually need them, never when you just foresee that you need them.
Imagine that you’re writing a class to store some records, and you’re asked to write a method called getAll(). You might think: well, since I’m doing this I might as well write a method called getById() and maybe getByName(), but hey: YAGNI. That’s not what the doctor ordered, don’t put yourself in that situation.
This may seem like an obvious thing to do: don’t write software unless you were asked for it. My experience shows that in many cases programmers try to futureproof the code and add features that they think their customers are going to use. Hardly ever that is the case, and the code ends up being kept in the repository for years until someone decides it’s about time to remove it.
Another equally possible scenario is: requirements change, and code that was prepared to be used later - actually has to go, meanwhile hours spent on writing, testing, reviewing and discussing these precious lines could go elsewhere. Maybe they could be spent in the break room, playing games or drinking coffee. Some might say that you could actually develop some other much needed code with that time - who knows?
As programmers we optimise our code trying to do all the required work with a minimal amount of CPU cycles, but somehow we often fail to realise how our mental cycles are wasted. Invoking YAGNI during meetings can be very powerful - both to deny doing things that aren’t really needed, and to prevent useless code from entering the repository.
And remember: the cheapest software is the one that you didn't write. You aren't gonna need it! Subscribe, and I’ll see you in the next one, cheers!

show more

Share/Embed