Programmers only!

#EvanPoll #poll

Which of these three software designs is best?

----

class Noun {
/* ... */
}

function verb(noun) {
/* ... */
}

let noun = new Noun()

let result = verb(noun)

----

class Noun {
/* ... */
verb(noun) {
/* ... */
}
}

let noun = new Noun()

let result = noun.verb()

----

class Noun {
/* ... */
}

class Verber {
/* ... */
verb(noun) {
/* ... */
}
}

let noun = new Noun()
let verber = new Verber()

let result = verber.verb(noun)

@evan verber. part can be made implicit with trait / tyoeclass resolution, then it's strictly better than option 1, which is better in this case than option 2 because the notion of making verbs out of other language classes isn't limited to nouns and its subtypes!

@evan oh no! I only just realised that when you say "Noun" you mean that types are sort of like nouns and terms of the types are sort of like names, whereas functions over types are sort of like verbs and interfaces are sort of like "verbers"!

I thought that we're taking about language processing related domain!

If we aren't, then I'm heavily in "it depends" camp. There is , so while picking tools to encode your problem domain, you have to pick the closeness of extending "nouns" with more "verbs" or allowing a "verb" to work on more "nouns" based on the problem domain. There's no right answer and no reasonable way to prefer one over the other.

But from the standpoint of ease of understanding, facilitated the most by , I would pick option 1 because it doesn't rely on traits, is explicit and separates "algorithms" (verb) and "data structures" (Noun) so that people can understand them independently.

Sign in to participate in the conversation
Doma Social

Mastodon server of https://doma.dev.