by quanticle · 10y ago · 0 comments
I'd get comments like "wouldn't it be better if you made this (only used
once and very trivial) line of code a separate function?" "could you use
more classes?"
The trouble is that there is a cargo-cult belief in unit testing in the Java (and .Net) worlds. Everything must have a full suite of unit tests, even if it's a one-off script. Therefore, in order to enable the mock objects needed for unit testing, you can't have "just" a class. You have to have an interface, which that class then implements. If you have any non-trivial piece of functionality, it must be encapsulated into its own method, otherwise, how are you going to test it in isolation.My belief is that it all stems from the fact that Java doesn't have a REPL, so programmers use "test-driven development" to get the same level of interactivity from their code.
Pretty interesting when you think about it - java hasn't moved that conceptually far from C preprocessor statements.
It was built around lambdas in Smalltalk long before that.
Simula (about 4 years older) had a more typical class-based OO with vtables and a proper subtyping already. Long before any C.
What library was this?
It's not the same thing though. REPL gives you fast feedback once. Unit tests you build by following TDD are there to stay.