3 ms·
Although I disagree with some of the details, I think this type of approach to domain modeling is some of the most valuable work software engineers can do; in f
by feoren 3y ago
Although I disagree with some of the details, I think this type of approach to domain modeling is some of the most valuable work software engineers can do; in fact it's the type of analysis and rigor that justifies the word "engineer" in the title of "software engineer". But I do have two important points to add:
1. Don't restrict yourself to "common" types when you're thinking this way -- all of domain modeling can be approached this way. Working on a Pizza Ordering app? Think about the properties of various operations in your domain and how they are related to mathematical structures. Are they commutative, well-orderable, equatable, multiplicative, scalar, groups/rings/fields, monoids? Are there changes you can make that would allow your operations to have desirable properties? This stuff genuinely does pay off down the road when you want to expand your ideas or re-use your code on something else.
But be careful: not all useful mathematical structures have names or show up in textbooks! The goal is not to map your domain to things that mathematicians have named, it's just to understand it at this level (and get your code to understand it at this level too). If you find yourself arguing over whether it's actually a vector space, a tensor space, or an affine space, then stop worrying about external definitions and re-focus on the properties of your domain. Arguments about how your domain works are good; arguments about exactly what other mathematicians have written are bad.
2. This post is focused on getting the compiler to understand these concepts, but there's still a lot of value in explicitly modeling them in code even if it's "runtime checked" instead of compile-time checked. Many of these techniques end up requiring higher-kinded types to really get the compiler on board, which unfortunately most languages today don't support. But that doesn't mean you should change the abstraction, it just means you get a lower (or later) level of checking.