News for hackers. Stuff that matters.
Re:Tests aren’t enough: Case study after adding type hints t... by sseagull on Monday October 18, 2021 @01:56PM (#28908540)
I came very close to writing almost this exact code just the other day (except it was username or user id for me), but came to my senses. It's just so tempting in a dynamic language...

In a static language, you either can't do it, have to really go out of your way to do it, or at least do function overloading (which is a bit cleaner)

Re:Tests aren’t enough: Case study after adding type hints t... by fiddlerwoaroof on Tuesday October 19, 2021 @12:05AM (#28914751)
Calling a function like this “ensureUser” is pretty idiomatic and useful, in lisp-style code bases. I think it’s a pattern related to “parse, don’t validate” in static-type lands: rather than _checking_ what the type is and throwing an error, you define a function that knows how to turn various representations of your type into its canonical shape.