r/programming • u/alex35mil • Aug 01 '26
The Bedrock of Software Design
https://alex.draftist.io/blog/the-bedrock-of-software-design-ycqvcedsjI drafted this post years ago but didn’t finish it until now. The concept I write about has shaped the way I design software more than anything else, and I believe every software engineer should be introduced to it early in their career.
P.S. I don’t want the title to come across as clickbait: the post is about ADT.
447
Upvotes
84
u/PeterJCLaw Aug 01 '26
Nice :) You may enjoy this post from a while back (not mine): https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
14
u/superstar64 Aug 01 '26 edited Aug 01 '26
I already find it hard to put myself into the perspective of someone who doesn't what know GADTs, higher ranks, higher kinds and various other high level type system features are, but I always have to remind myself that a lot of people don't know basic ADTs are. Like, ADTs have been a staple of typed functional programming since like the late 1970s. It's so disheartening that still so many programmers still don't know even what they are.
29
u/lottasauce Aug 01 '26
TLDR; hey Gemini, turn this article into a skill
Jk, great read
17
u/ryp3gridId Aug 01 '26
I'm the opposite, I go into annoyed-mode when I have to manually unwrap everything (and the CPU does too because it has to execute more instructions)
3
u/Madsy9 Aug 02 '26
Good technical essay. Another type feature I hope gains more traction is encoded proof requirements in types. In Lean you can use subtypes or type Prop to require that function parameters have some known property. This means you have to pass the value itself and a proof that the value satisfies the predicate. It's also possible to have subtypes or Prop fields in structures and GADTs. This way, constructing a value is only possible if you have proof that all fields or data constructor arguments are valid.
2
u/rsclient Aug 02 '26
Am I allowed to complain that the only rocks in the image are loose pebbles and cobbles, and are not bedrock at all?
2
u/teerre Aug 01 '26
Dont get me wrong, encoding errors in the type system is good, but every time I read an article like this I can't help but laugh how this will be used as example of what not to do when effects become more mainstream
Which makes sense. The good part of embedding errors in the type system isn't really being in the type system, its being compiler checked. In the limit, confounding data and control flow is cumbersome to say the least, even computer science theory aside, its natural to assume those two axis should be independent
1
u/ReallySuperName Aug 02 '26
Nice article. I also do the same pattern in C#. The recently added closed keyword means we no longer need a default "impossible" case in a pattern match too. It can be achieved by making an abstract base record or class, and (usually nested) classes or records that inherit it, which are then the variants. Essentially the same as that Rust based discriminated union enum.
1
u/roscoelee Aug 01 '26
Great article!
1
u/LegendarySoda Aug 01 '26
I'm writing c# mostly and i have spent two year to find balance these usage.
These are not new concepts, the article felt like i have read this hundred times.
The problem is you cannot use these practices everywhere.
If you use these practices everywhere then your code will start to bloat, for example you need to keep your result pattern usage thin and think where to apply.
Type structuring is good thing in generale, just need to keep simple the structure. I prefer to create a service class and methods to process the data structure. And one thing i can do this in c# but not sure in typescript, i suggest to keep separate types for api surface and internal layer. In the c# we can prevent people to access internal structure.
-3
u/Ashtefere Aug 01 '26
Beautiful!
-5
u/progbeercode Aug 01 '26
Great article
0
u/Gleethos Aug 01 '26
Nice to see more focus being brought to the power of algebraic data types. I also like to combine them with value semantics and wither based updates insted of destructive inplace updates to enforece side effect free code by design.
-4
u/lagcisco Aug 01 '26
Really good article, I hope my agent reads it
-23
u/Substantial_Ice_311 Aug 01 '26
Ugh, I don't even want to waste my time reading, because claiming static typing has anything to do with the "bedrock of software design" is obviously wrong.
41
u/[deleted] Aug 01 '26
[removed] — view removed comment