This first post is about counting sheeps, with a design-by-contract twist.
Let me know what you guys think, it's my first blog at all, so I'm a taker for all matters of feedback, as long as it comes from the heart that is ;)
I didn't see a link to DBC, is that in there? Or some other use of contracts that is hard via just asserts, like in test amplification?
We are always looking for ways to improve our Python codebase, and I hadn't expected to see modern investment here!
I was hoping something like a more modern https://dl.acm.org/doi/10.1145/581478.581484
What is the performance hit like? I could see these getting pretty expensive (but correctness is invaluable). Seems like it would be great for something like aws lambda in python where you have already decided performance isn't an utmost priority and scrutability is difficult, so any correctness you can bolt on is a boon.
This approach ensures only a single point of validation, a lower mental overhead as you are certain it is valid everywhere, and fast failure when it's not - by contract, even.
There are a few places where this concept is discussed, but the most concise phrase is: “Parse, don’t validate.”
Zod (TypeScript) is a good example of a library like this, as it is oriented around types. I’m not sure if Python has something similar.
However, overvalidation can make your code overly verbose, which is something I’ve fallen into before. Use it sparingly.
Unfortunately, people don't know they are made to be stripped in prod with `-OO` so that the perf hit is zero. This means you can never be sure a 3rd party lib you depend on is not using an assert somewhere for a very important check you are going to disable.
https://www.bitecode.dev/p/the-best-python-feature-you-canno...
[1] https://en.wikipedia.org/wiki/Eiffel_(programming_language)