←back to thread

Parse, Don't Validate (2019)

(lexi-lambda.github.io)
389 points melse | 1 comments | | HN request time: 0.001s | source
Show context
kortex ◴[] No.27642049[source]
This principle is how pydantic[0] utterly revolutionized my python development experience. I went from constantly having to test functions in repls, writing tons of validation boilerplate, and still getting TypeErrors and NoneTypeErrors and AttributeErrors left and right to like...just writing code. And it working! Like one time I wrote a few hundred lines of python over the course of a day and then just ran it... and it worked. I just sat there shocked, waiting for the inevitable crash and traceback to dive in and fix something, but it never came. In Python! Incredible.

[0] https://pydantic-docs.helpmanual.io/

replies(8): >>27642308 #>>27642664 #>>27643276 #>>27643474 #>>27644758 #>>27645737 #>>27646367 #>>27647141 #
jimmaswell ◴[] No.27642664[source]
I've found this to be simply a matter of experience, not tooling. As the years go by I find the majority of my code just working right - never touched anything like pydantic or validation boilerplate for my own code, besides having to write unit tests as an afterthought at work to keep the coverage metric up.
replies(5): >>27642800 #>>27642869 #>>27643369 #>>27643588 #>>27644097 #
cortesoft ◴[] No.27642869[source]
Tests aren't to make sure your code works when you write it, it is to make sure it doesn't break when you make changes down the line.
replies(1): >>27644709 #
exdsq ◴[] No.27644709[source]
How do you know your code works when you write it if you don't test it?
replies(3): >>27645375 #>>27645643 #>>27646387 #
syngrog66 ◴[] No.27645375[source]
you run it. look at the results or output. like the stdout, or a file it changed, or in a REPL or debugger. depends on situation
replies(2): >>27645480 #>>27646224 #
chrisandchris ◴[] No.27645480[source]
Yeah I‘m not sure that‘s how software engineering should work.

Tests should prove a desired behaviour. Sometimes it‘s not possible to fully run code until late in some staging, just because there are a lot of dependencies and conplexity. That‘s what tests are for (on various lebels of abstraction).

replies(1): >>27645651 #
1. cortesoft ◴[] No.27645651[source]
I think it depends on the task. Some code we write is so simple and only used a few times that you don’t need tests.