Remix.run Logo
airstrike 4 days ago

Except now you're writing and maintaining twice the amount of code instead of relying on the compiler and/or type checker to help you catch those errors

jlarocco 4 days ago | parent [-]

Sorry, but I don't agree that static typing is a replacement for unit tests. I can see static languages having fewer unit tests, but it's not going to eliminate them.

alternatex 4 days ago | parent | next [-]

Static typing is a replacement for unit tests aimed to catch type bugs. Also, no one has 100% code coverage so might as we get some guarantees for granted.

I understand that statically typed code doesn't mean bug-less code, but I always find it odd that dynamic language enthusiasts feel like they need to stretch the benefits. Dynamic languages are great for many things. Strictness is not one of them and that's fine.

esafak 4 days ago | parent [-]

It's obviously not a replacement. You can get the types right but the values wrong due to faulty logic.

MrJohz 4 days ago | parent [-]

Sure, but only some of the unit tests are about values. Others, at least in my experience, are any handing various aspects of the implied types of values, and those can largely be removed.

Moreover, a good type system can also force the values to be right by enforcing certain invariants directly in the type system. For example, let's say I have a function `deleteProjectAs(user, project)` that deletes a project, but it only works if the user is an admin, otherwise it throws an error. I can write a bunch of tests that validate that this function checks that the user is an admin in all sorts of different cases, but with a type system I can write something like `deleteProjectAsUser(user: Admin, project: Project)`, and this guarantees at the type level that no non-Admin user can delete a project.

The point here is not that types can replace all tests, but that well-designed types can get rid of a lot of them.

esafak 4 days ago | parent [-]

I agree. My post was unnecessary; I did not realize the response was talking specifically about type bugs.

pdimitar 3 days ago | parent | prev [-]

You're tearing down a straw man. Your parent poster did not say it eliminates tests. He said static typing mean less tests. He didn't say static typing is a replacement for tests either.

Why are you doing double misrepresentation?

More honest discussion tactics, please.