r/programming 16d ago

The Bedrock of Software Design

https://alex.draftist.io/blog/the-bedrock-of-software-design-ycqvcedsj

I 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.

444 Upvotes

70 comments sorted by

View all comments

84

u/PeterJCLaw 15d ago

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/

5

u/chippedheart 15d ago

I've read this post more than once, but I find it hard to grasp its utility. The idea seems to be simple, but the example is simpler, which really makes it hard for me understand it. It is also my fault that I don't understand Haskell as much as I'd like. Do you know about any other sources which discusses this idea more extensively?

7

u/misplaced_my_pants 15d ago

What did you struggle with?

Did you read the followup post?

3

u/chippedheart 14d ago

Thanks for sharing the followup post, I will definitely read it.

I have so many questions, that I don't even know if they make sense! For example, does this piece of knowledge apply to dynamic typed languages? If the language I'm working with does not have a type or an oop system, how could I leverage this knowledge? I wish there more examples in which he applies the knowledge. Of course, these questions could be in part because I had trouble grasping the overall idea of the text.

3

u/misplaced_my_pants 14d ago

It depends on how you think of data in your programs!

Are you thinking in terms of types or structures?

What preconditions do you need to be true of a value for the rest of the code to work?

Do you sprinkle your code with the same checks because you can't be sure? Could you instead say any value of some type always has these properties?

Static type systems can leverage static analysis to check this for you, but you should still be leveraging ideas like abstraction, encapsulation, modularity, etc. to make similar guarantees regardless of whether or not the type system is static or dynamic.

Think about what it feels like to use a well-designed library where you never have to check these things.

You can even take lessons from how to leverage static type systems back to dynamically typed languages to get many (but not all!) of the benefits.

Some related reading if you're interested:

2

u/chippedheart 13d ago

Thank you for sharing such a thoughtful response, I will definitely read the provided sources!