this post was submitted on 28 Nov 2024
452 points (88.2% liked)

Programmer Humor

32692 readers
293 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 7 points 2 weeks ago (1 children)

Yeah, the alternative to static typing is to write tons of unit tests, which definitely adds a lot more code to your codebase.

[–] [email protected] 0 points 2 weeks ago (1 children)

That's not an alternative, you always need tests

[–] [email protected] 1 points 2 weeks ago

Right, so this is the part where I get to sound like a smart ass, because I snuck a "tons of" into there.

What you do always need, is tests serving as a specification of the intended behavior, to document it for your team members and your future self.
But the thing that static typing is an alternative to, is integration tests for many code paths. For example, in dynamic languages you have no reassurance that a call to your database library still works, unless you have an integration test which actually calls into the database. Similarly, you hardly know whether the many error-handling code paths are working, unless you write tests for those, too.
In static languages, we don't test this stuff outside of the specification-like integration tests, because the database library and the error handling library are already separately tested, and the type system ensures that we interface with them correctly.