by panic · 9y ago · 0 comments
They're especially useful when you are writing libraries for use by somebody else.
I'd do the same thing in most languages - in fact, I'd end up doing way way way more of it in C because it's very weakly typed.
I think type theorists would disagree.
> Placing a small number of sanity checks on border code is not any kind of argument for static typing.
Yes it is if any of those checks are for types.
> I'd do the same thing in most languages - in fact, I'd end up doing way way way more of it in C because it's very weakly typed.
C doesn't have type checks, unless you're using some runtime type system (like GObject) on top of it. At any rate, C may not be completely type safe, but it's better than dynamic languages which are completely type unsafe; even if you could do type assertions, you would do them far less frequently in C than, say, Python. Further, C is not the canonical statically typed language, and you would be laughed out your workplace if you proposed adding a runtime type check on your function parameters.
Even if you're using Python (assuming you have the good fortune to use a modern version), you can just use type annotations and the static type checker rather than littering the code and slowing your program. Albeit your point stands about writing library code for another's consumption.