JMHoffmann.com

Guard Style — No Discussion!

Guardstyle is a way of writing proceduaral programms. It focuses on how the flow inside of fuctions is structured.

The assumption is that there is a single or at least very few successful paths through a function. The successful path shall go to the very end while all failure exit points branch off early.

function myfn() {
    a = fn_a()
    b = fn_b(a)
    if (!b) {
        return error
    }
    c = fn_c(b)
    return c
}

This keeps indentation to a minimum and