Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There’s a difference between “there’s some gaps” and “you can drive a bus through it.”

Lots of languages other than Rust have static types, some more complete than others.



Trouble is that if there are gaps then the types become redundant. Consider error handling. Rust helps ensure you handle the error, but it doesn't ensure you handle the error correctly. For that, you must write tests. But once you've written tests to prove that you've handled the error correctly, you've also proven that you handled the error, so you didn't really need the type to begin with. You're really no better off than someone using PHP or JavaScript.


> But once you've written tests to prove that you've handled the error correctly, you've also proven that you handled the error

Hardly. Suppose all caught errors in a particular module of code bubble up to a call site which (say) retries with exponential back-off. If the compiler can guarantee that I handle every error, I only need one test that checks whether the exponential back-off logic works. With no error handling guarantee, I'd need to test that every error case is correctly caught—otherwise my output might be corrupted.


The chief reason software fails is because programmers are insufficiently aware of all of the reasons the software can fail. Sure you need a test to make sure that you handle the error correctly, but if the function signature doesn't indicate the possibility of an error occurring, why would you write that test in the first place?


By the same reasoning, if the function signature doesn't indicate what specific errors can occur, why would you write a test in the first place?

No matter how you slice it you have to figure out what the software you are calling upon does and how it is intended to function. Which is, too, why you are writing tests: So that your users have documentation to learn that information from. That is what tests are for. That is what testing is all about! That it is also executable is merely to prove that what is documented is true.


> if the function signature doesn't indicate what specific errors can occur, why would you write a test in the first place?

All languages with exceptions enter the chat


All languages with exceptions...?

Let us introduce you to the concept of checked exceptions. That is one of the few paradigms we've seen in actually-used languages (namely Java) where communicating which specific errors will occur has been tried.

Why is it that developer brains shut off as soon as they see the word "error"? It happens every time without fail.


I'm aware of checked exceptions in Java. What I'm not aware of is a language which has checked exceptions as the only exception mechanism, which would be the only way to have exceptions always reflected in the function definition.


Types require opt-out and automatically extrapolate onto new code. Tests require opt-in.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: