by Leon Rosenshein

Dogma

Dogma (n): a principle or set of principles laid down by an authority as incontrovertibly true.

        – Oxford Languages

That’s one definition of dogma. The problem I have with dogma is the incontrovertible part. Because even if something was absolutely true once, that doesn’t mean it’s true now. Or will be in the future.

And what happens when your dogma disagrees with itself? It’s not usually existence ending, but it can be confusing. Consider this bit of code

package main

import (
    "fmt"
)

const TWO = 2

func scaleList(numbers []int, scaleFactor int) []int {
    scaled := make([]int, len(numbers))
    for i, e := range numbers {
        scaled[i] = e * scaleFactor
    }
    return scaled
}

func doubleList(numbers []int) []int {
    return scaleList(numbers, TWO)
}

func main() {
    n1 := []int{1, 2, 3, 4}
    d := doubleList(n1)
    fmt.Println(d)
    n2 := []int{4, 2, 1, 3}
    fmt.Println(doubleList(n2))
    fmt.Println(doubleList(d))
}

It’s DRY. There’s no repetition of code. There are no magic hard-coded constants in functions. Functions do what they say they do. But is it YAGNI? KISS? Not really. Of course it’s a contrived example, but there’s no need for the scaleList function. There’s barely a need for doubleList, and a constant called TWO with a value of 2 is just added cognitive load.

Which is not to say that DRY, KISS, and YAGNI can’t live together. They can and they should. But it’s a balance. And the only bit of dogma I have is “It Depends”