6 ms·
You do write tests, don’t you?
by emoII 1y ago
You do write tests, don’t you?
- fyrn_ 1y agoYeah, that will really help with the auto complete and keystroke by keystroke checking?? What?
- ninetyninenine 1y agoDon't understand why people find tests important but not types. There's two popular ways to verify your programs. Types and tests. Types are EASIER then tests and types COVER more then tests. The ideal thing is to use both, but why spend so much time on unit tests over types is beyond me. Note that integration tests are a different beast. Why? Because you need to test things that aren't covered by either unit tests or types. In unit tests you mock out things that are external like IO, databases, and the like. In integration tests you need to test all of those things. Integration tests are THE most important thing to use to verify your program because it's an actual test to see if your code works. But unit tests vs. types? Types win. When I code. I never write a single unit test. Just types, and integration or end 2 end tests. It doesn't hurt to write a unit test and it's actually better. But the fact that I'm confident my code works without it shows the level of importance.
- gleenn 1y agoIf you do it right, your tests cover the thing you care about and are less work usually because you write the test for the part of code that has the interesting part you want to verify works correctly. Types, especially on fully typed languages, make only guarantees about the type of values and they make you do it in places you might not care about. Types also only catch certain classes of errors that I personally find less helpful that tests. So to me, tests are less work, focus on thebimportant parts, and give better error messages. Obviously you can also write bad tests and do things like effectively just check the types in pmaces and you are back to square one. Testing is more of an art but the effort/economics of time are far better to me.
- the_af 1y ago> types [...] make only guarantees about the type of values What do you think "type of values" means and encodes, and why do you think it's different from your handwritten tests? I assume you do know that type checking is more than simply validating you're passing a string to a function that expects a string argument? > Types also only catch certain classes of errors Which classes of errors? Why do you think manually written unit tests are more complete?
- AnimalMuppet 1y agoDepending on your language, some things may not be easy to encode in types. "Verify that the function handles gracefully the situation where the map it's passed doesn't contain that one magic entry." That won't be easy to encode in a type...
- the_af 1y agoOf course not everything can be encoded in types, and also YMMV regarding the specific language you're using. But you now why I asked the question: people who make claims like "types make only guarantees about the type of values" usually don't understand what modern type-checking can do or what can be encoded in types. People making these claims often believe type-checking is limited to validating that you only pass strings to a function expecting a string argument, or some minor variation of that.
- gleenn 1y agoThe fact remains that your type system can be turing-complete and still not validate the actual logic that I need checked/tested.
- the_af 1y agoThe same can be said of tests. Types are just tests. By removing all the mindless, repetitive tests you write, typechecking can free you up to write the actual meaningful tests that you truly need to write. It's not "pick one", it's "use type checking to help you only write the unit tests that matter".
- MoreQARespect 1y agoLike tests, types can be more hassle than theyre worth if you dont use them correctly. Before mypy came along I was pretty disciplined at A) testing and B) ruthlessly clamping down on primitive obsession. I use types a lot now but I didnt see enormous quality or productivity gains when I started using them. I suspect people who let compilers catch their bugs were always A) pretty lax testers and B) probably often let primitive obsession get the better of them. There are only a few types of tests where I think that types actually serve as an appropriate substitute.
- theLiminator 1y ago> When I code. I never write a single unit test. Just types, and integration or end 2 end tests. It doesn't hurt to write a unit test and it's actually better. But the fact that I'm confident my code works without it shows the level of importance. Imo this might be true if you're writing a lot of glue code. But I think unit tests are extremely valuable for testing pure functions that are pure logic/computation. For glue code/ensuring everything is hooked up correctly, types easily beat tests, but for pure logic tests (ideally property based testing if you can swing it) works great.
- ninetyninenine 1y agoGame developers work with more purity then web devs as web devs always funnel pure computations to external resources (usually the database). The weird thing is Game developers don't unit test stuff. Why? Because it's mostly not that effective. I know a lot of people say stuff like game devs are cowboys that don't follow best practices but that's not true. A lot of game devs know their shit inside and out. Here's the reason why Game devs don't unit test. There's no point. They run the program themselves a couple of times on their own computer and their good. The problem with web dev is that all their code is so Tied with IO they can't even run the code on their computer. So in order to test their logic they have to write mocks and then unit test their code with mocks in place. But why even do this when you can cover it all with an integration test? Hence I don't unit test. My integration tests and type checking covers it all.
- 90s_dev 1y agoTDD and BDD are security blankets for enterprises and clients. They add disproportionately little value, and significantly increase the cost of evolving an app in any direction.
- jamil7 1y agoThe person you're responding to only mentioned tests, not TDD or BDD.
- 90s_dev 1y agoPeople who think like that commenter implied, are almost always indoctrinated into "if you don't write tests and use TDD or at least BDD, you're literally Satan."
- MoreQARespect 1y agoTDD and BDD teaching and tutorials are almost universally terrible so people inevitably do them badly and then moan about the results, which can be worse than not using them at all. Usually the primary mistake is either using cucumber (which is awful) or surrounding the wrong interfaces with tests (usually at too low a level). Done well they are like a mini superpower.
- 90s_dev 1y agoI've learned from the so-called experts for years. I studied directly under them. I spent so many years trying to find the perfect way to do TDD and BDD. I saw their own code and their own solutions up close. They're frauds. It was all a sham.
- MoreQARespect 1y agoI'd be shocked if it wasnt because they also led you to make the two primary mistakes i refered to above.
- 1y ago
- toolslive 1y ago"unit tests are a poor man's compiler" (NN)