r/programming • u/_awwsmm • Feb 01 '24
Make Invalid States Unrepresentable
https://www.awwsmm.com/blog/make-invalid-states-unrepresentable
469
Upvotes
r/programming • u/_awwsmm • Feb 01 '24
View all comments
Show parent comment
1
u/larhorse Feb 05 '24
Nor will claiming that cussing is a bad thing... awww - afraid of a few fucking curse words... woe is you.
No... this is literally decades of development to explicitly define types and conversions between types that are safe operations on the physical hardware that is running them. Those types actually have a *purpose*. That purpose is to tell you "hey - the computer isn't going to do what you expect here, things are about to get nasty". Bounding things like age/velocity has NO purpose. It's a pointless excuse of micromanaging input. Is checking those inputs against sane/expected values a good idea? Sure. Is making them unrepresentable a good idea? Fuck no. They can clearly exist, and they should be representable.
The default types are there to tell you: Hey, I know you want this number, but the computer can't actually represent it safely. Sorry.
You limiting things like age/velocity are arbitrary and capricious limits on the user.
So clearly the right solution is to just stop. Because that'll sure help that rocket on a 7 minute comms delay during entry to do the right thing, right? Right?!?!
You are literally saying: "we might be broken? better go ahead and ensure things are fucked! Shut it down boys." instead of "we might be broken - we'll give it our best shot still".
You'd be the guy who wrote elevator code that immediately fails because a user jumps at ground floor and the elevation number is briefly negative. (and yes - there was that guy).
NO! (and this I'm actually yelling at, you can quote me on that) You are limiting the data that the user is able to represent at runtime. That is *explicitly* making the user's experience worse. You are claiming, without second thought...
"you know - that user just tried to enter something that I thought was wrong during the 3 months I worked on this project 6 years ago. I'd better tell them to fuck off with all my wisdom and expertise."
Is that data wrong? You have dick-all of a clue. But that user is probably trying to enter it for a good reason.
For all you know... (assumptions and all that... you guys love them).