3 ms·
Tests are not proofs, types provide proofs. Tests demonstrate that the exact conditions being tested actually work. That's not a bad thing but when working with
by jghn 10y ago
Tests are not proofs, types provide proofs. Tests demonstrate that the exact conditions being tested actually work. That's not a bad thing but when working with static typing and robust type systems the need for unit testing goes down tremendously compared to dynamic languages.
- bluejekyll 10y agoWhile I agree with you to an extent, I'm a huge Rust fan, longtime C/C++ and Java engineer, I disagree that a strongly typed language allows you to not write unit tests. Unit tests verify logic, the compilers only guarantee syntax. Which yes, handles a huge set of issues that in a dynamic language would require 100% test coverage, you still need to check the logic of the code. Thus, unit tests are still a huge benefit. One reason I love Rust is the build in #[test] feature. Builtin tests from the ground up, awesome.
- jghn 10y agoI didn't say not write tests but that it reduces the volume of tests needed for largely the reasons you stated
- rubber_duck 10y agoTypes provide semantic information as well so checking verifies semantics as well (extent depends on the strength of the type system). Saying you're a Rust fan and then saying compilers only guarantee syntax when the entire point of that language is to have a constrained subset in which types guarantee no data races/leaks at compile time doesn't make sense to me.
- bluejekyll 10y agoI didn't mean to imply that rust doesn't provide more than just syntax. You are correct that rust provides a huge number of guarantees around semantics, but honestly, I think it's not a traditional compiler, it provides a ton of features that you don't find in C compilers for example. Rust is the greatest thing since sliced bread, my comment was only about statically typed and compiled languages in general. I think you read more into my comment than I intended.
- majewsky 10y agoOf course it's a compiler. A compiler verifies that its input conforms to the syntax and semantics of its own language, and generates machine code (or some other language) equivalent to the input. The only difference is that Rust's semantics is waaayyy more strict than C's.
- tracker1 10y agoI'd counter that with dynamic language, easy modularization and the ability to create single function modules that are composable, and written as such, that code is more easily understood and doesn't require the same type of testing as more complex systems in static language, that lend to layers of indirection and complexity for the sake of testability. I'm not saying that testing isn't needed in either place, but a lot of the times "enterprise" practices that leak into scripted environments make code far more complicated and difficult to understand than it needs to be.
- majewsky 10y agoWhy do you assume that modules in a statically-typed language are necessarily more complex? (Except for the type annotations, of course.) Not every statically-typed language is Java. ;)
- tracker1 10y agoTrue, it does depend on the language... C#, for example is limited to Namespaces and Classes, you can't write a simple function without a lot of wrapper... partial & static classes help, but it's not the same. Though, I will say writing tests against and with a dynamic language tends to be far easier when things are written with modularity in mind.