3 ms·
Are java programmers the most egregious abusers of the Gang of Four? Twice now, I've been faced with a metric crap-ton of Java source files for reading / writi
by lrobb 15y ago
Are java programmers the most egregious abusers of the Gang of Four?
Twice now, I've been faced with a metric crap-ton of Java source files for reading / writing to a device.
Anything you could possibly imagine, gets defined as a class. There's dozens of classes, and more SLOC than I can count.. Meanwhile, an equivalent C program comes in at 2k SLOC, and 4 files.
You().Can('not').Do(any(thing)).Concise().In(java())!
When I was primarily doing C++, I gradually switched to generic programming once visual studio supported STL... And then when I started using Perl I found I didn't need to write classes at all.
Reminds me of this Paul Graham quote:
"This practice is not only common, but institutionalized. For example, in the OO world you hear a good deal about "patterns". I wonder if these patterns are not sometimes evidence of case (c), the human compiler, at work. When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I'm using abstractions that aren't powerful enough-- often that I'm generating by hand the expansions of some macro that I need to write."
http://www.paulgraham.com/icad.html http://www.paulgraham.com/icad.html
- omaranto 15y agoYou might enjoy Steve Yegge making fun of this aspect of Java culture, if you haven't this particular post before: http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...
- lrobb 15y agoI had not seen that! Explains so much... In the neighboring programming-language kingdoms, taking out the trash is a straightforward affair, very similar to the way we described it in English up above. As is the case in Java, data objects are nouns, and functions are verbs. But unlike in Javaland, citizens of other kingdoms may mix and match nouns and verbs however they please, in whatever way makes sense for conducting their business. For instance, in the neighboring realms of C-land, JavaScript-land, Perl-land and Ruby-land, someone might model taking out the garbage as a series of actions — that is to say, verbs, or functions. Then if they apply the actions to the appropriate objects, in the appropriate order (get the trash, carry it outside, dump it in the can, etc.), the garbage-disposal task will complete successfully, with no superfluous escorts or chaperones required for any of the steps. There's rarely any need in these kingdoms to create wrapper nouns to swaddle the verbs. They don't have GarbageDisposalStrategy nouns, nor GarbageDisposalDestinationLocator nouns for finding your way to the garage, nor PostGarbageActionCallback nouns for putting you back on your couch. They just write the verbs to operate on the nouns lying around, and then have a master verb, take_out_garbage(), that springs the subtasks to action in just the right order.
- hackinthebochs 15y ago>The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least This is just so wrong. The shape of your program should reflect your understanding of the problem, and the clearest way to communicate that to other humans. Patterns will be a part of this, as it reduces the amount of mental effort required to understand the solution. It is true that writing too much boilerplate to create a pattern is a sign that your language is lacking necessary abstractions. But patterns themselves will always be a part of good software. I swear this entire thread is just trying to rationalize bad programming practices.
- barrkel 15y agoMy biggest problem with Perl is trying to track and remember what dictionaries contain what. I end up with massive comments and ludicrous variable names just so it's clear when I come back to the code 5 years later. Dictionaries and lists of things don't relieve you from the job of naming and encapsulating the data you're dealing with. But full on classes are usually only needed when behaviour needs dispatching from polymorphic locations, and that isn't too often.
- brown9-2 15y agoI disagree with this. It's possible to write concise code in Java, although probably not as concise as in Python, since everything still needs to be a class (you can emulate modules with functions-only with all public static methods, but it seems like a bad idea). It's the OO and design pattern culture that results in much of the Java code you describe as over-engineered. But you can write bad code in any language.