DEV Community

Discussion on: You ain't gonna need it

Collapse
 
eljayadobe profile image
Eljay-Adobe

Could leave yourself a breadcrumb for work not done, that maybe wasn't needed, maybe will never be needed.

Picking JavaScript today, rather than my usual C++.

// YagniError - something was not done yet because it wasn't needed yet.
// Appears to be needed now.  Happy fun time is over.
class YagniError extends Error {
    constructor(to_do) {
        super("YAGNI: " + to_do)
    }    
}

// print_value - print the word for the number.
// We'll yeet a YagniError for the unhandled cases.
function print_value(value) {
    if (value === 0) console.log("zero")
    else if (value === 1) console.log("one")
    else throw new YagniError("print(value:"+value+")")
}

try {
    print_value(3)
} catch (err) {
    console.error(err.toString())
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
linajelincic profile image
Lina Jelinčić

I like the idea of leaving breadcrumbs! It's self-documenting and pretty straightforward.