DEV Community

Cover image for Practicing YAGNI - Show me the code

Practicing YAGNI - Show me the code

Jason McCreary on January 29, 2018

After my Practicing YAGNI post, many asked to see what practicing YAGNI looks like in code. As a quick recap - YAGNI is a principle of eXtreme Pro...
Collapse
 
dserodio profile image
Daniel Serodio

I'm familiar with the "As a $ROLE, I want $FEATURE so that $BUSINESS_BENEFIT" user story template, but I'd never seen it combined with "Given ... And ... Then". Do you have any useful links about this use story template? Thanks.

Collapse
 
leojpod profile image
leojpod

You might be interested in checking out the Cucumber project (cucumber.io/).
It has implementation in many languages (I personally use cucumber-js) and it lets you test your app based on these user stories.

in short: you keep a folder where all your stories (cucumber call that features) are described in these terms (Given ... When ... And ... Then ...) then another folder keeps all the implementations of these steps (e.g. Given that user goes to /home) and it runs tests based on that. It's pretty neat to use.

Collapse
 
dserodio profile image
Daniel Serodio

Nevermind, I found it myself :) "What's in a Story", by Dan North: dannorth.net/whats-in-a-story/

Collapse
 
gonedark profile image
Jason McCreary

Awesome. I didn't know the exact source either. Just always wrote them that way.

Collapse
 
leojpod profile image
leojpod

Hi Jason!
That was a nice read.

How do you approach YAGNI with framework? I can see how I would do it with Elm and to some extend I try to approach it that way. But what about the build system or the introduction of a framework? Do you start with it right away or wait until you feel the need for it?

Maybe it's a dump question and YAGNI isn't incompatible with a framework, you just start going with YAGNI once the framework installation is completed.

Collapse
 
gonedark profile image
Jason McCreary

YAGNI is really framework agnostic. One might argue you could call YAGNI on the use of a framework. However, I try not to call YAGNI on tooling - common tech among a team. That’s not to say their use should never be challenged, but YAGNI shouldn’t be the only motivation.

So, yes, YAGNI is something you practice regardless of tooling. In the case of a framework, you could use YAGNI as a motivation to stick closely with the conventions of the framework and not try to customize it too much.

Collapse
 
leojpod profile image
leojpod

YAGNI must work well with something like Sails.js then.
Thanks!

Collapse
 
doug7410 profile image
Doug Steinberg

I saw your talk this weekend at Sunshine PHP. I really loved the examples and the humor. You did an excellent job at getting the message across. Thanks for posting this. I'm sharing with all my coworkers.

Collapse
 
onkarjanwa profile image
Onkar Janwa

Hi Jason,
That is a nice post.

It looks like most of the mvc frameworks already follow YAGNI, implement logic in models, send response through helpers and put all series of actions in controller.

Collapse
 
gonedark profile image
Jason McCreary

Thanks.

What you describe is more design and architecture. YAGNI may have lead to these decisions. But where things go is not focus of YAGNI. YAGNI is about implementing things when you actually need them, never when you just foresee that you need them.

Collapse
 
webwizo profile image
Asif Iqbal

Quite interesting!
I'm gonna try to find more about YAGNI which I have heard first time.

Thanks mate.

Collapse
 
gonedark profile image
Jason McCreary

Thanks. I would recommend watching my talk to give you more of the motivation behind YAGNI.