3 ms·
Although he's correct at a high level, I'd say this should be handled more like the advice given to programmers on optimization: Optimization for beginners: Do
by commandlinefan 6y ago
Although he's correct at a high level, I'd say this should be handled more like the advice given to programmers on optimization:
Optimization for beginners: Don't optimize
Optimization for experts: Don't optimize - yet.
What I've observed, over and over (for the past 20 years of Java development) is that beginning programmers don't really see much point in object-oriented design, and default to static functions (Java's equivalent of "free functions"), but they also end up needing some shared state... so they make the shared state static, too (Java's equivalent of a global variable). Every "enterprise" Java project I've worked on since about 2002 has been "designed" this way: almost all the data is public static (e.g. the "singleton" abomination) so you can't run any of it without running all of it.
On the other hand, if developers just defaulted to designing objects even if they don't really get why, they'll end up with a composable, testable system by accident.
- jbay808 6y agoComposable maybe, but testable, not necessarily. If the function doesn't read or modify a global state, it can be much easier to test in isolation than a class, which might e.g. throw an exception in the constructor causing your test to fail before you even get to run your method. If it does touch a global state, it's probably instead better as part of a class.