4 ms·
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
by quanticle 11y ago
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.
- rtpg 11y agoa bigger culprit is a lack of first-class functions. Objects in Java basically exist to be structs and to hold onto methods.
- Chris2048 11y agoIn my early days - I once found a Tuple library for Java, and added it to the codebase. Senior devs soon instructed me to remove it - Back to a multitude of container objects...
- gravypod 11y agoWouldn't using a tuple in Java be like using inserting things into a Object[] and pulling them back out casting to the object you want to use? What library was this?
- Chris2048 11y agohttp://www.javatuples.org/ http://www.javatuples.org/
- V-2 11y agoHard to say without knowing more context, but they could have been right. Personally I'd prefer clearly named, domain-specific container objects with adequately named properties than having to deal with "anonymous" Tuples all over the codebase, and being forced to remember what the first element was, what the second one was etc.
- Chris2048 11y agoWhat makes a container object domain-specific? If I just have to pass data through the application, the anonymity may be appropriate.
- jaggederest 11y agoIf you look at the history of object orientation, it starts as slots for function pointers in structs in C, with some preprocessor statements to make it easier to use. Literally the object is just a struct which holds data and function pointers. Pretty interesting when you think about it - java hasn't moved that conceptually far from C preprocessor statements.
- reycharles 11y agoC++ isn't the start of object orientation.
- sklogic 11y ago> it starts as slots for function pointers in structs in C 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.
- V-2 11y ago> 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. It's not the same thing though. REPL gives you fast feedback once. Unit tests you build by following TDD are there to stay.