Counting Sheeps with Contracts in Python

11 pointsposted 4 days ago
by Leo_Germond

6 Comments

kortex

40 minutes ago

Cool stuff! Might be fun to integrate with a type validation library like Pydantic or Msgspec to provide in-line coercion/assertion.

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.

Leo_Germond

4 days ago

Hello everyone, I'm starting a new blog where I'm trying to mix my passion and experience for safe programming in critical contexts, and my (over)use of Python, and other techs that are used in... less safe contexts. The "investment hypothesis" if you will is that pieces of tech used daily in critical systems could see a broader use if they stopped being hidden behind mumbo jumbo, bad UX, and general lack of consideration for the common developper. In this blog I'll try to go and discuss fuzzing, contracts, why not some amount of lightweight proofing... and to mix them with application that are hopefully fun and nice to study.

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 ;)

djoldman

2 hours ago

This isn't meant as a dig, I'm genuinely curious: how is this not simply imposing static typing in python?

GrantMoyer

an hour ago

The pre and post conditions are checked at runtime. Also, typically static type sytems are not expressive enough to statically check more than relatively basic pre and post conditions, even in languages with advanced type systems like Haskell or Scala.

bofaGuy

an hour ago

At this point just use Java instead.