Bitter Java 427
Bitter Java: The lessons taught by server-side Java Antipatterns | |
author | Bruce A. Tate (with help from Braden R. Flowers) |
pages | |
publisher | Manning |
rating | 8 |
reviewer | Peter Wayner |
ISBN | 1-930110-43-X |
summary | A collection of bad habits to avoid for server developers using Java. |
Writing and reading technical books is both a pleasure and a chore. Programming computers can be great fun, but doing the job well requires almost impossible amounts of discipline, attention to detail, and pure drive. The machines churn through billions of operations per second and a mistake in just one can send everything tumbling out of control. Most authors tend to gloss over the difficulty by tossing in a spoonful of Mary Poppins because it does little good to grouse. It's just so simple and straight-forward to toss in optimistic words like "simple" and "straight-forward."
Tate's approach is looks a bit different. He wants to follow in the tradition of Frederick Brook's Mythical Man Month and talk about software development with an honest voice. Microsoft executives, Objective C devotees, and assembler lovers will be disappointed because the title is a bit misleading. He's not really bitter about Java in the way that Princess Diana was bitter about the British Royalty, he's just had a few bad experiences and he wants to help us learn from them.
In fact, he's not even writing about Java in the general sense. The book concentrates on the problems that often arise with most popular and complicated applications for the technology like servlets and enterprise Java beans. If you're building a web site based on Java, then you might want to read through this book.
The structure itself is devoted to uncovering antipatterns , a term Tate uses because it plays off the way that Sun offered Java patterns to help programmers use the new tools efficiently. Most of the chapters show the wrong way to build something and then show how to correct it.
Chapter 8, for instance, demonstrates a bulletin board that seems to be well-designed on the surface. The parts of the data structure are broken up into suitable objects and every object comes with a collection of methods that act as gatekeepers for the data inside the object. It all looks elegant, but it performs badly especially on large installations when the objects live on different servers. Suddenly, all of the extra well-meaning object-oriented engineering starts jamming the flow. Wrapping every object with so much glue code is like hiring more workers to speed up a bureaucracy. Tate shows how to aggregate the calls and speed things up dramatically by cutting through the misapplied object-oriented concepts.
If you step back a bit and think about the book from a distance, the right title starts to look like "Bitter Object-Oriented Programming". Most of the problems in the book emerge when seemingly good uses of OOP turn out to be terribly slow when implemented. While all of the problems are practical hurdles awaiting Java programmers, they must have cousins in the world of C++ and the other OOP languages. Splitting things up into many objects is plenty of fun at the beginning, but when the messages start flowing, the code becomes a swamp.
After a few chapters it becomes clear that object-oriented programming is starting to reach practical limits. The theory may be elegant, but programmers can only make it work if they use guidebooks like Tate's. The object-oriented toolkits are too easy to use dangerously. So what is the solution?
This kind of guidebook filled with antipatterns may be the best we can do for now. Tate himself says that the book is filled with "merc talk", the kind of chatter about hair raising experiences he says that mercenaries trade when they're sitting around the fire. This is an apt description. If you're a hired codeslinger creating J2EE applications or servlets, then this is a good book for your shelf.
Peter Wayner's latest two books are Translucent Databases , an exploration of how to create ultra-secure databases, and Disappearing Cryptography: Information Hiding, Steganography and Watermarking , a book about mathematical parlour tricks, sleights-of-hand, and subversive things you can do with bits. You can purchase Bitter Java at bn.com, and you can join Peter in reviewing books by submitting reviews after reading the book review guidelines.
All I want to know is.. (Score:2, Funny)
Re:All I want to know is.. (Score:3, Insightful)
Re:All I want to know is.. (Score:2)
What does this mean?
Re:All I want to know is.. (Score:2)
What has Java got to do with islands in the South Pacific?
"Ontong Java" is part of the Solomon Islands.
Re:All I want to know is.. (Score:2, Funny)
Development Processes be damned.. (Score:5, Insightful)
Development prowess and productivity is determined by how well your code works, not how many widgets you can crank out and connect together in "internet time". It's knowing how things work, and if they'll work together well or not. It's knowing when it's better to write the damn thing yourself, instead of spending 2-3x more time and resources gluing off the shelf components together..
I'm heading off to buy the book, if not just for the reason to support the author courageous enough to go against the grain and give this topic a voice.
Re:Development Processes be damned.. (Score:3, Interesting)
The only programmers using design patterns are C++ and Java programmers. Do you know why? Because the "patterns" are meant to overcome language hurdles that dont occur in lisp and strictly functional languages.
How many language designers besides Stroustrop constantly defend their language on usenet by appealing to C's popularity? He's a brilliant guy, but that argument is a crock.
Re:Development Processes be damned.. (Score:2)
As you can see from the discussion of the Visitor pattern, design patterns are native to languages; Lisp removes the need for the Visitor pattern with CLOS's multiple dispatch. However, by doing that Lisp doesn't reduce the total number of design patterns available to it; instead, it makes higher-level design patterns easier to express.
So in a sense some of the DPs you see in the book are meant to cover language weaknesses -- but before you get to proud about not having _those_ weaknesses, remember Godel's principle: you also have weaknesses. C++ is not a weaker language simply because it needs the Visitor design pattern; it's weaker for many other reasons, involving complexity and impetuous design (or lack of design).
Consider before you assume that DPs are signs of weakness: Smalltalk also uses DPs, and Smalltalk is _far_ from being a weak language.
-Billy
Re:Development Processes be damned.. (Score:2, Insightful)
Uhh yeah. Now let's see how easy it is to maintain and upgrade your amazing functional language code over the next 10 years. Man, people who hate OO languages are funny. They just don't like OO cause they can't figure out how to program OO.
Re:OO and functional (Score:5, Insightful)
Lisp has a full-blown object system called CLOS (Common Lisp Object System), which frankly blows C++'s object system out of the water, in terms of flexibility, power, and syntactic cleanliness, just for starters. Lisp programmers aren't scared of OO. It's C++ programmers who are scared of Lisp, although why anyone would be less scared of C++ is a mystery to me.
OO doesn't magically mean "easy to maintain." It may mean "easy to find drones who think they learned the language from a book in 21 days, so they put in on their resume" which I think was your real point.
To address the original issue, functional designs tend to be much more "factored" than procedural designs, because things are designed to use functional abstraction rather than interactions between different bits of code and variables. This tends to make them much more robust and maintainable.
Re:Development Processes be damned.. (Score:2)
Re:Development Processes be damned.. (Score:4, Funny)
For some functional languages, it seems you can use any design pattern you want - as long as it's recursion.
Re:Development Processes be damned.. (Score:3, Insightful)
and i thought design patterns were just typical ways other people code stuff so you can 1, learn more quickly, and 2, not have to re-think through all that. are you saing that every lisp program you come across has a completely different design? (i'm not familiar with that language).
Re:Design patterns and Lisp (Score:5, Insightful)
One is the pervasive nature of intrinsic typing. Variables are not typed, values are. Object-oriented methods, of course, explicitly mention classes, but non-OO code does not need to explicitly type variables, except to improve performance. The flexibility of many built-in Lisp operators helps deal with multiple types transparently. For instance, length of array, length of a string, and length of a list all use the same function: LENGTH.
Another source of flexibility is Lisp macros, which can use the full power of the Lisp programming language to rearrange and process Lisp macro calls into Lisp code. If there is some design pattern that Lisp does not natively support, you can use Lisp macros to create a Lisp "dialect" that cleanly expresses the design.
Paul Graham [paulgraham.com], in his books, demonstrates, for instance, that if Lisp did not already have CLOS to express object-oriented concepts, that in about a hundred lines of pretty clean Lisp macrology, you can add single-dispatch methods to the language, and it looks just like "real" Lisp, and mixes with the base language transparently.
It took Stroustrup a large effort (cfront) to add objects and methods to C, and it requires explicitly invoking a compiler program to do the translation, with name-mangling and everything else. In Lisp, you would write Lisp macros to do the same thing, and you would still be working in true Lisp. You can also add macros on macros: cfront is basically a monolith, but Lisp macros can work together; you can continuously "build up" from the language foundation, and the various layers can be overlapped.
Any time you find yourself repeating a pattern, it suggests a Lisp macro. If you have an example of the pattern already written, it is pretty much cut-and-paste to create the general macro from the specific pattern instance.
That kind of flexibility, which allows the programmer to mold the language to fit his (and his tasks) needs, is really what makes Lisp great to work with.
It's something like the difference between working with Legos and clay. If you're missing a Lego part to serve a particular function, you're pretty much stuck, unless you want to injection-mold your own custom blocks. Therefore, Lego models tend to use "design patterns" where the standard blocks or parts fit together a certain way that solves a certain class of problems. Lego models, although they can be amazing achievements, all tend to look like Lego models.
With clay, however, the medium is fluid. You can mold it to just about any shape you want. Sculptures usually look like their subject, not like clay.
Re:Design patterns and Lisp (Score:2)
With clay, however, the medium is fluid. You can mold it to just about any shape you want. Sculptures usually look like their subject, not like clay.
However, it's also worth remembering that while silver flutes tend to look the same, so do clay flutes. They don't need to, but then neither do silver flutes. They tend to. And it's the silver flutes that have, e.g., keys, and a multi-octave range.
Also, though small sculptures can be made from clay, large ones require stone (or, I grant you, cement or metal). And moulded sculputers tend to look like sculpted sculputes. But not like welded sculptures.
The nature of the medium always both liberates and constrains. Squeak cannot be made stable enough for business applications, without making it quite difficult for even the original programmer to fix things. Python is slow. C is fast, but rigid. C++ is
Patterns in the use of dynamic languages are significantly different than those of static languages. But they still exist. Just don't expect the same ones to be important. (Or they may be so basic that they are built into the language, and thus tend to escape notice.)
Re:Design patterns and Lisp (Score:2)
Re:Design patterns and Lisp (Score:4, Informative)
Lisp does have patterns, but Lisp hackers tend to implement them as macros, automating their application rather than forcing everyone to know and re-enter them to use them. That's the difference between:
// Please forgive any Java errors here
// I don't use this pattern enough to get it right
// without a compiler to check it...
try {
FileInputStream myfile = new FileInputStream(filename);
}
finally {
myfile.close();
}
and
(with-open-file (myfile filename)
)
They do the same thing - guarantee that myfile gets closed no matter what - but the Lisp way requires less typing and is less prone to errors.
Re:Design patterns and Lisp (Score:3, Informative)
I just fininished reading Modern C++ Design [awprofessional.com] by Andrei Alexandrescu, which explains all sorts of cool hacks you can do with templates in C++. Or to put it in more sober language, how to implement reusable design patterns using C++'s templates and compile-time polymorphism.
It's a great read and really demonstrates just how powerful C++'s templating system is. It shows how to do just what you say - create a general macro from a specific pattern instance - for example making reusable templates to efficiently implement multiple dispatch and the Visitor pattern. And C++'s template specialization happens at compile time, which with a good optimizing compiler gives you performance as good as handwritten code. I haven't used Common Lisp so I can't compare C++ templates to CL macros - but you shouldn't underestimate C++'s macro-ing and code reuse abilities. The syntax is horrible, but there do exist people who don't like Lisp syntax either...
The fact that early C++ implementations were using the cfront preprocessor doesn't really say much about the language - just that it had an unwieldy first implementation. All current C++ compilers really do handle the language natively (g++ for one). You can find all sorts of reasons for saying C++ is unpleasant and ugly, but cfront is not one of them. OTOH, if you were saying that Lisp is more powerful than C because it is much easier to add objects to Lisp than to add them to C: well of course, everyone knew that already.
Re:C++ templates vs. Lisp macros (Score:3, Informative)
C++ templates share much of the power of Lisp macros, but they are somewhat more restricted in what they can do and express. They play an essential role in writing generic algorithms, which is a great thing. But once you've decided to write your C++ code using templates, you're committed to doing things in the template style. Lisp macros are completely transparent, in the sense that macro code and Lisp code look the same, and fit together.
I concede that the STL folks and Blitz++ folks have done amazing things with the template system. But C++ compilers still have issues with getting the STL to work consistently.
I think the way I would summarize it is that writing Lisp macros is continually improving the language, without narrowing the scope of your options. C++ templates feel to me like building a tower. Sure, each floor is higher than the one before, but soon, the only way to build is up. If you don't like the choices you made building the ground floor, you have to abandon the work built on top, as well.
CLOS *isn't* OO? (Score:3, Interesting)
Re:Design patterns and Lisp (Score:2)
Spanish has its own inherent sexism. For instance, a musician is "el musico" (inherently masculine). The word for music is "la musica" (inherently feminine). So what do you call a female musician in Spanish? "El musico mujer" ("the (inherently-masculine) musician woman").
I think it's a problem common to all romance languages. English has the benefit of not insisting that inanimate objects must have figurative penises or vaginas.
Re:Development Processes be damned.. (Score:2)
For lisp, probably not. Most lisp is peppered with imperative things, even the language itself supports sequenced stateful execution without requiring you to explicitly pass states around. For a functional language like haskell, definitely. It's hard to wrap one's brain around a client/server design being implemented as something like (in pseudocode):
function client(serverdata)
return server(clientdata)
function server(clientdata)
return client(serverdata)
And where clientdata and serverdata are infinitely large. Neat pattern when you finally get it tho...
Re:Development Processes be damned.. (Score:2)
Re:Development Processes be damned.. (Score:3, Informative)
The book was originally written with SmallTalk in mind. Maybe you should stick to just saying "object-oriented" (I suppose 99% of which are C++ and Java programmers, though VB is finally truly object oriented, so it applies to them too)
Do you know why? Because the "patterns" are meant to overcome language hurdles that dont occur in lisp and strictly functional languages.
Give me just one example so I can begin to take you seriously. There are just different hurdles. First off, let's be clear, lisp is not by any means a "strictly" functional language. Strictly functional means no side effects. At all. Which is fine if you want to wrap everything up into typeful states and pass them around with syntactic sugar ala monads, but guess what, you just implemented a pattern. One that has a bit more mathematical category theory behind it, but it's still a pattern, imposing a structure on your overall design that may or may not fit your needs.
Re:Development Processes be damned.. (Score:4, Insightful)
This process is obviously not super-productive. However, this individual simply does not have enough *real-world* experience. After getting lectured/fired a few times for not "putting out," he'll tune his skills to be able to make better decisions on how to apply his OO know-how.
Finally, it is my opinion that this type of programmer is overall better than simply a guy who knows how well his code works. I know a lot of hacker-types who know their code down to ++ inside the assignment wrapped in their if statement. What they produce works, however:
* Try to maintain it. Let me bring my lawn chair and a bag a popcorn and I'll watch.
* Try to add anything to it. This time I think I'll just have a tall glass of pink-lemonade.
* etc.
One the otherhand, if I was given the code written by the OO goon, I'd be more likely to understand it, and trim the fat.
Re:Development Processes be damned.. (Score:3, Funny)
Undoing that divison??? What about:
Employee
|
--------------
| . . . . _ . . . . |
Manager . . . . Slave
No need to undo anything. Processes that don't care about the division code to Employee's.
Plus, the managerial status may be temporary, fleating, or vague.
Associations may be better for temporary, fleeting or vague manager relationships (perhaps using a Project-class?). I really don't see why those relationships can't be properly managed in OO code.
Sun invented patterns? (Score:3, Funny)
The structure itself is devoted to uncovering antipatterns , a term Tate uses because it plays off the way that Sun offered Java patterns to help programmers use the new tools efficiently. Most of the chapters show the wrong way to build something and then show how to correct it.
And Al Gore invented the internet. Or was that Bill G again?
Some patterns to live by... (Score:3, Insightful)
"Keep it simple, stupid." - anonymous
"Limit temporary object creation." - any smart Java programmer
Java does a pretty good job of providing much more functionality for a little more overhead. There are areas in the Java libs which seem over-engineered and slower and bigger than they should be (Swing!). Don't throw out the baby with the bath water, though...Java is good and the crufty parts will evolve into something better.
Re:Simple, stupid but not efficient (Score:3, Informative)
No, the over-engineering of code with too many layers and overly complicated object heirarchies are much more likely to be the culprit.
Roger Session (COM and DCOM: Microsoft's Vision for Distributed Objects, Wiley, 1998) (OK, this is from the pre-C# days when MS was going to have you do your GUI in VB, your business logic in the MS Java dialect-du-jour) goes on about "object pools", about how you don't create a new taxi cab everytime you need a ride from the airport.
Yes, that is a good example where the Factory pattern along with object recycling is useful.
I always wondered, what is so expensive about object creation anyway, and in C++ with "auto" objects, it is just about free. Java object loading, however, is expensive because unlike C++, they do not use a static VTABLE but have to check character string names against what is in the object. Java object loading is what makes you sit there twiddling your thumbs when an good sized Java app fires up.
You are confusing 'class loading' with 'object creation'. Class loading typically happens once for many object creation events.
Auto objects in C++ come off the stack, whereas Java objects are always allocated from the heap. However, current Java implementations are very fast at object creation, and you never blow stack with Java objects. ;-)
So, to optimize a Java app, one has to leave clean, textbook OO behind and resort to tricks like OO's that "lazy load" classes as they are needed instead of at application start time, like the use of "object pools" to create object instances once and keep reusing them.
Um, that is 'textbook OO'. BTW, 'lazy loading' was around long before Java...it's been used for years in the VB community.
The word on the street is that Java is dog slow unless you optimize,
The word on the street is wrong, then. Modern Java is quite fast on typical 'first blush' code.
it is slow because of class loading,
Class loading mainly effects application startup time. It is a fallacy to confuse 'startup time' with 'execution time'. Many of my apps stay up for days at a time...startup time just isn't an issue.
and the way you optimize is that you use object creation sparingly in your inner loops, even if it makes your code look ugly.
Interestingly, this is also a good way to optimize C++. ;-)
Java != Slow (necessarily) (Score:2)
Having said that, my company is doing immersive 3D networked technology (which can include FPS games) in Java (with some OpenGL or DX) and we're capable of getting really respectable frame rates even with very busy systems. Part of it is because we allocate once where possible and recycle, rather than continually create and destroy objects. And we avoid some of the utility classes. And we THINK while designing to minimize things like thread counts, class counts, etc. to give quick loading of the app and good performance even on crappy hardware.
Good Java code is as fast as good C++. Good C might be a bit faster, but most C is mediocre and Java can compete with that. Slow Java code is a result of poorly educated programmers and designers doing unwise things (most of which are utterly avoidable).
Re:Java != Slow (necessarily) (Score:2)
javacoder2@yahoo.com
Thanks!
Re:Java != Slow (necessarily) (Score:2)
You need more RAM. Swing apps (like JBuilder and Forte) are very memory hungry. That's one reason Eclipse and SWT are interesting (another big one is accelerated graphics support). 256 MB should work OK for a development system. I think Eclipse would take less.
Out of curiosity, I wrote three "hello, world" apps, one in C++ using C-style printf, one in C++ using qt, and one in java. The java version came up with "Hello, World!" (just a single output statement) in two seconds. The other two came up instantaneously. I don't know how significant this is, but jeez, you know? Seems kind of slow.
Its not significant, unless your app is a tiny command-line app. Current Java implementations suffer from slow startup. JDK/JRE 1.5 is supposed to provide for better sharing between VMs and programs, so things like Swing only get loaded once per system instead of many times.
I would like to see a similar feature for Java that the CLR has on Windows - the ability to pre-compile the bytecode into native code at install time. Alternatively, 'freezing' the running program onto disk on exit would be fine, and would completely preserve the dynamic aspect of Java.
I just don't like the idea of wasting cycles on repeatedly optimizing the same code, run after run. Plus, static compilers can do fancier optimizations.
Re:Some patterns to live by... (Score:2)
Object creation performance has improved, but it is still much slower than recycling objects. Swing suffers from excessive temporary object creation. Also, even the short pauses from incremental GC can be problematic for some apps.
It is pragmatic to use an OO programming style that doesn't gratuitously throw away cycles. Interestingly, concise code is often also clearer code.
My Gripes about Java &tm; (Score:5, Funny)
I'm a first year programming student at a local community college school and I've just finished my Visual Basic classes. This term I'll be moving onto Java. However I've noticed some issues with Java that I'd like to discuss with the rest of the programming community. Please do not think of me as being technically ignorant. In addition to VB, I am very skilled at HTML programming, one of the most challenging languages out there!
Java is based on a concept known as Object Oriented Programming. In this style of programming (also known as OOPS in the coding community) a programmer builds "objects" or "glasses" out of his code, and then manipulates these "glasses". Since I'm assuming that you, dear reader, are as skilled at programming as I am, I'll skip further explanation of these "glasses".
Please allow me to make a brief aside here and discuss the origins Java for a moment. My research shows that this language is one of the oldest languages in existance, pre-dating even assembly! It was created in the early 70s when AT&T began looking for a new language to write BSD, its Unix Operation System (later on, other companies would "borrow" the BSD source code to build both Solaris and Linux!)
Back to the topic on hand, I feel that Java - despite its flaws - has been a very valuable tool to the world of computers. Unfortunately its starting to show its age, and I feel that it should be retired as C++, Python and Perl seem to have been. Recently I've become aquainted with another language that's quite recently been developed. Its one that promises to greatly simplify programming. This new language is called COBOL.
Although syntactically borrowing a great deal from its predecessor Ruby, C greatly simplifies things (thus its name, which hints at its simpler nature by striping off the klunky double-pluses.) Its biggest strength is that it abandons an OOPS-style of programming. No more awkward "objects" or "glasses". Instead C uses what are called structs. Vaguely similiar to a Java "glass", a struct does away with anachonisms like inheiritance, namespaces and the whole private/public/protected/friend access issues of its variables and routines. By freeing the programmer from the requirement to juggle all these issues, the coder can focus on implementing his algorithm and rapidly developing his application.
While C lacks the speed and robustness of Java, I think these are petty issues. Given the speed of modern computers, the relative sluggishness of C shouldn't be an issue. Robustness and stability will occur as C becomes more pervasive amongst the programming community and it becomes more fine-tuned. Eventually C should have stablity rivalling that of Java.
I'm hoping to see C adopted as the de facto standard of programming. Based on what I've learned of this language, the future seems very bright indeed for C! Eventually, many years from now, perhaps we'll even see an operating system coded in this langauage.
Thank you for your time. Your feedback is greatly appreciated.
Re:My Gripes about Java &tm; (Score:2, Funny)
Re:My Gripes about Java &tm; (Score:2)
Re:My Gripes about Java &tm; (Score:3, Insightful)
I was about to point out that C has GOTO when I realized that C programmers who use 'goto' in C code more than 3 times in a 2 month span invariably seem to wind up homeless and discombobulated. So, it's probably for the best that you didn't point this out
Re:My Gripes about Java &tm; (Score:2)
I saw it a couple of days ago on the thread about implementations of the C++ stl98 standard.
s/C++/Java/ doesn't make it on topic.
-a
So many books on java... (Score:5, Insightful)
For example, "We clinched the deal because we promised to use the J2EE/EJB framework" -- as opposed to, "Our product is good, and the guys liked our technical expertise and design." This is a "sort of" true story!
S
Re:So many books on java... (Score:2)
Oh, and if you need a C text, Deep C Secrets kicks much buttock as well.
Mm.... Bitter java... (Score:2)
Certainly problems arising from OOP are not specific to java. It's quite possible in C++ (and presumably other OOP languages) to write a class with an interface that would make Stroustrup proud but that runs like me before my morning coffee. One of the issues I've had with OOP is the extreme care needed in design, disproportionate to the benefits. Still, it does have benefits, so I use it.
Now while the reviewer relates the issues in the book to other languages, does the author? It sounds like it might be a good book for a non-java programmer, but it isn't clear that it is.
Re:Mm.... Bitter java... (Score:2)
It is pretty Java-specific (there's a chapter devoted to JSP, for example), but in the memory leak chapter ("Bitter Memories"), he covers the C++ memory model, as a comparison to the Java one.
If you are capable of understanding the meta-pattern, then "Bitter Java" is useful for non-Java developers. The JSP examples could certainly apply to any HTML scripting language (the horror of seeing bad ASP programmers converted into even worse JSP programmers is something that should be outlawed).
BTW, there is an associated web site: www.bitterjava.com.
-jon
mmmmm... Money.. (Score:2, Insightful)
Here's a book title... (Score:2, Funny)
Re:Here's a book title... (Score:2, Funny)
intersting book title, but it would get called POOP for short
Edited for the "for dummies" series: (Score:3, Funny)
Chapter 1
The joys of 0
Chapter 2
The joys of 1
Chapter 3
0 meets 1
Re:Here's a book title... (Score:2)
Examples, please! (Score:2, Interesting)
As someone who has used OO successfully for 10+ years, I'll have a hard time accepting these OO "antipatterns" without concrete examples.
-- Brian
Re:Examples, please! (Score:3, Funny)
The solution (Score:3, Insightful)
Of course, there is no magic bullet to make software suck less, but I would strongly encourage all developers to at least look at what FP offers.
Re:The solution (Score:2, Informative)
Go back to assembly! :-)
Re:The solution (Score:3, Insightful)
Object oriented is good when things are easily modeled by objects. When it's easy to think of them as physical models.
Functional programming is good when something is well described by goal states.
Procedural programming is good when the algorithm is the thing.
The remaining set of approaches are involved in making quick choices between options based on relative desireability. In a person one might describe this as "having a feel for the problem", but that is often confused with the modeling approach. This is more related to a ranking procedure or an emotional approach. At the moment, the best way that I know of getting this is via a neural net, but that's clearly not a desireable programming strategy. A hash table is an example of this approach in use (if not in design). But the actual methodology would need to stretch far beyond hash tables.
For a larger system, one would want to pick one of these approaches as a basis, and interface it with two of the other approaches. These in combination would be able to synthesize an attack on the fourth method problems. Then each problem would need to be solved using the api's relavant to the particular mode that handles that kind of problem best.
Re:You must be joking (Score:2)
There are a number of functional languages with quite respectable performance in good implementations, e.g. O'Caml, Standard ML (MLTon, smlnj), Scheme (bigloo, stalin for certain applications), and (though less functionally oriented) Common Lisp (CMUCL/SBCL, ACL),. They may not be quite as good as good C/C++ compilers, but they're not that far behind, either.
anti-antipatterns (Score:4, Interesting)
they speed up the development of a system
or
they speed up the execution of a system
This is, of course, one of the fundamental trade-offs that us computer programmers make all the time. The important part is choosing a pattern that is appropriate for the system. For example, the flyweight pattern is used to limit/reuse objects in a system. It is appropriate to use this pattern when top execution speed is necessary, but the price is the complexity of implementation.
The facade pattern, OTOH, is designed to make life simpler for programmers, potentially at the cost of execution speed.
It sounds to me like this guy has trouble picking the appropriate patterns from the start.
Re:anti-antipatterns (Score:2)
I don't really agree with this. In most systems I work on they do both- in different places. In one place speed isn't important (e.g. UI), in another it is (e.g. database lookups that are called from a zillion places).
It sounds to me like this guy has trouble picking the appropriate patterns from the start
No engineer always knows what pattern to use; for one thing the known requirements often change as you work towards delivery, and the patterns that best address these requirements often change with them.
I mean sure, a good pattern is along the lines of 'avoid having requirements that change', but that pattern is often inapplicable.
Antipatterns (Score:5, Informative)
Actually, "antipattern" is an accepted term in the pattern commnunity for describing a bad process or design that on the surface looks like a good idea. If a Pattern is a good practice distilled from the experiences of many good develoeprs, then an antipattern is a "gotcha" thathas been distilled from experience common to many good developers. This book describes it, but th ename really has nothing to do with Sun's practice of describing things in terms of patterns.
-Frums
Re:Antipatterns (Score:2)
the name really has nothing to do with Sun's practice of describing things in terms of patterns.
That's right. The AntiPattern is a well established idea, even marked by the publication of an AntiPatterns book [wiley.com] just a few years after the publication of Design Patterns [awprofessional.com] by the gang of four.
Antipatterns? (Score:2)
Anyways, the book shows a bad way, then corrects it. Much like any "optimizing" books of the 1980's. It seems that the book with a little effort could provide patterns instead, mainly by focusing on the solutions instead of the problems.
M.
Re:Mistaken? Nope (Score:2)
Patterns are about balancing and rearranging opposing forces in a design to achieve some wanted effect. All patterns have consequences. These usually must be dealt with by other patterns. And thus you have a pattern language. In this setting anti-patterns makes absolutely no sense at all.
M.
I hope more people read this... (Score:2)
Java is often pitched as being a breeze to learn. And it is relatively easy since things like memory management is taken care of for you and the libraries tidily abstract a lot of details for you.
But I've seen a lot of budding Java programmers program away with little awareness for what's going on in terms of efficiency and good system design, and this book seems to address these qualities well. Just because Java's slightly easier to program doesn't mean that programmers can be clueless.
In other words - programming is hard! (Score:2, Interesting)
So, if you write a system that runs across multiple servers you can end up with a poorly performing system if you don't know how to separate functionality out properly. From the Unix Hater's Handbook:
I would say that Java shortens the rope but then lets you hook it up to a power winch. Modern toolkits and languages are really powerful. Being able to write a distributed application so easily that YOU DIDN'T NOTICE HOW DAMN MANY CROSS SERVER CALLS YOU WERE MAKING is pretty amazing. On the last large project I did we used Java and I noted that Java made locking so easy that we swept right past the easy locking problems (like, did you remember to release the lock) and straight into the really nasty ones. I think that going beyond "Learn Java in 21 Days" into how to break your functionality out properly is a wonderful topic for a book but the gratuitous swipe a Java doesn't seem useful. Just remember, "Power tools for power fools."
Nothing more to see here. Move along. (Score:2)
Quoth the reviewer:
If you're a hired codeslinger creating J2EE applications, shouldn't you already know how to create a scalable application and whether or not Java beans/servlets is correct tool or methodology for the problem at hand? It seems that this book should be recommeded more for Java newbies (which is fine) than Java veterans.<DISCLAIMER>I am not a Java programmer, but I am a grizzled veteran</DISCLAIMER>
Re:Nothing more to see here. Move along. (Score:2)
The tone of the review was "Gee whiz, even if you use Java, you can still get it wrong!" That sort of book is very well suited for new programmers. Showing them the wrong way to do something is often as valuable as showing them the right way. But recommending it for "hired codeslingers" seems a bit, well, inappropriate.
Over-Design (Score:2, Insightful)
OO toolkits & templates (Score:2)
At least in the world of C++ you do have the STL - hard to use, but hard to use dangerously. I think that templates are a somewhat undervalued addition to OOP - they allow for an extra level of abstraction(?) without the penalty of slower code.
Re:OO toolkits & templates (Score:2)
Actually, STL (and to a large extent, templates themselves) represent a fundamentally different programming *paradigm* than OOP. It's called generic programming, and has quite a number of uses. And yes, I do agree that they make a good addition to OOP, but in reality they represent the inclusion of a whole other programming paradigm to C++. Personally, I think it's way cool and useful, albeit a bit complicated to use.
Re:OO toolkits & templates (Score:2)
Re:OO toolkits & templates (Score:2)
Uhm, compiler dependant?
Seriously, you *may* pay a penalty for the compilers lack of intelligence when dealing with templates, but that is more than made up for by the fact that the STL code itself is *damn* good and efficient. My point is that you could probably hand-code better performing stuff yourself (I like to think that I can, anyway :-), but it would likely either take a long time or miss one crucial feature in most OO languages - strict type rule enforcement. Using the STL you get proven implementations AND type safety thanks to the template system (and the compiler, mind you) doing the tedious bits. Kind of like a tiny part of the huge library in Java, but with type safety C++-style.
Occasionally, I roll my own templates - not too often, but it happens. Great modelling feature for something that is practically the same except for the type involved.
there was an island between Sumatra and Bali... (Score:4, Funny)
Danny (who plays gamelan [danny.oz.au] and is interested in Indonesia [dannyreviews.com]).
Thinking in Java (Score:5, Interesting)
While Mr. Eckel's book does covers the syntax of the language (java in this case) et. al, it also cover the meaning of the language and most of all, it covers how to think in the language (hence: the title).
Almost any developer can pickup a language and become knowledgeable with it by working on one or two projects. However, being *proficient* at your domain, and understanding coding-principles of the language for your domain, and understanding the business of being a programmer is much more difficult goal to achieve -- only time, experience, and dedication will ever get you there. It is this quality that I look for first, the knowledge of a language comes third.
Here is a link that I point people at to high-light my point: Chicken Soup for Your Modeling Soul [sdmagazine.com] -- I specially like item 21: "A fool with a tool is still a fool".
Also _Effective Java_ (Score:3, Informative)
It's definitely not a book for beginners; it's more of a style guide for API design in Java. It fills a gap between the very abstract world of patterns and the low-level syntax of the language. For example, it gives a several-page exposition of the contract of equals(), which was eye-opening even to this fairly experienced Java programmer.
And
Good things are hard to do (Score:2)
- JFK
Anti-patterns in 1998 (Score:5, Informative)
If folk are interested in the concept of modelling the "wrong" way to do things then I would also recommend reading Anti Patterns - Refactoring Software, Architectures and Projects in Crisis by William H Brown, Raphael C Malveau, Hays W "Skip" McCormick III & Thoma J Mowbray (ISBN 0-471-19713-0).
This takes a slightly higher level look at the whole management of coding projects (although a lot of the patterns that are desribed are equally applicable to the low-level coding structure) and looks at common fallacies that are used by many teams as the "correct" way to do things. A knowledge of common mis-conceptions that have been proven not to work in the past (except in certain clearly defined "special cases") is invaluable in being able to spot the nascent structures before the get set in stone and the cost of re-factoring the structures becomes higher than the cost of living with them.
Finally if people really want to get into this field I would also recommend Death March: The Complete Software Developer's Guide to Surviving 'Mission Impossible' Profects by Edward Yourdon which, if nothing else, serves as very reassuring purely from the fact that you know that many many other people have to deal with similar situations when project management goes really bad.
Finally as food for thought for those posters who stated above that patterns (and specifically design patterns) are not useful, I'll take the liberty of quoting the preface to Anti Patterns:-
Sample chapters (Score:4, Informative)
how about (Score:3, Insightful)
...bitter about people who keep buying into marketspeak?
...bitter about people who keep developing the same old language, but put some makeup on it so for it to seem different?
...bitter about methodologies, because they're set in stone?
...bitter about requirements, because they're set in water?
...bitter about business because you're just a "resource" to them?
...bitter about business programming because it's dull, insignificant, and someone should have already figured out a way to generate all this stupid code since it's been repeated some many times over?
Heh, whatever, I need to sleep.
Antipatterns are well-accepted... and useful. (Score:2)
More information (and some fun examples) can be found by starting at http://www.antipatterns.com/dev_cat.htm [antipatterns.com], where they list many specific antipatterns for development, management, and architecture. These pages aren't easy to find, which is too bad because they're a nice summary of specific antipatterns.
One example of an antipattern is vendor lock-in [antipatterns.com]. Their description of why vendor lock-in is an antipattern is both amusing and sobering, thankfully, nothing like that would ever happen in the real world :-) [sunbelt-software.com]. A full description of an anti-pattern needs to also describe a remedy/alternative; their recommendation for vendor lock-in (aka ``Pottersville'') is an isolation layer. It'd be easy to argue that open source software/free software (OSS/FS) [dwheeler.com] is an alternative solution, since OSS/FS also frees customers from absolute control by a single vendor and there's quantitative evidence for why, in many cases, you should use it [dwheeler.com].
Teaching it Every Week (Score:2)
I don't get Idiot's Guide or For Dummies. Why would anyone buy a book that insults their intelligence right on the cover? Unless people are really that stupid.
Re:Teaching it Every Week (Score:2)
Self-deprecating humor I can handle (I use it all the time in my classes, actually - nobody's a perfect coder, I'm clearly evidence of that). What I can't is obscuring information behind it. (Besides, how self-deprecating is it, really? The company is the one who named the book, not me.)
I teach out of a "bland and technical" manual. The secret to teaching is not making the students feel like they can't understand it (which is what calling someone an idiot does, idiot - see?), but making them feel like they can. I don't talk down to my students. I don't criticise their work. What I do is point them in the right direction. Introduce them to the ideas and then let them sort it out in code. Nudge here and there. The Dummies and Idiots books just hand you an answer (how) without trying to impart any sort of reason (why). How won't stick, because it's just rote memorization. Why will, because it imparts a deeper understanding, it sticks in your head better, it has stronger roots and more ways to tie in with your previous knowledge (a key to learning).
This is why Java for Dummies isn't on my reading list but Thinking in Java is. It gets to the why. Is Thinking in Java hard to read? I haven't found it so. My students haven't found it so. I've read Java for Dummies. I suppose it has it's moments. There are better books for beginner, better books for intermediate and better books for advanced, programmers.
Plus, I just can't bring myself to trust a "technical" reference published by a company that also makes Golf for Dummies and Parenting for Dummies. O'Reilly doesn't make Car Tuning in a Nutshell. I might look at Parenting for Dummies. But Dr. Spock's book is probably much better.
Alright, fine, my gripe isn't so much with the title as with the content, but that doesn't really make for a pithy comment, does it?
Take one of my classes sometime to see how I am with my student's code . . .
Thanks for the kind words. (Score:5, Interesting)
Real programming (Score:5, Insightful)
The hardest thing to get across to a Java/C++/VB zealot is that assembly is the most powerful language available. There is no computing algorithm, or programming paradigm that can't be expressed in assembly. I routinely write classes in assembly, and use runtime polymorphism - in fact, correct multiple inheritance is more easily implemented in asm than C++! (fewer lines, no assinine casting...) However, this doesn't mean that assembly language is the cure all for every programming problem. Some problems lend themselves to assembly (like device drivers, OS code), others to C++ (games, applications), and others to Java (web programs). What's hard is convincing people that if they understood the underlying computer science, they could write the code in the language which best suited the particular application, rather than being stuck writing in Java, or whatever HLL is popular at the time.
Incidentally, I like assembly because of the freedom and power it provides. But I still write in Java or C++ when the needs of the project dictate. Real computer science transcends the language used, as languages come and go. Soon, Java will be outdated, and those who only learned to program in Java will find their knowledge useless.
What matters is not whether you know langauge X, but rather that you know the fundamental algorithms of computer science and can translate them into any language. If you can break down a task into algorithms, then you can pick the language best suited for those algorithms, and translate the algorithms into code in a trivial amount of time, regardless of which language you use. What too many people miss is the fact that if you can't break a problem down into its fundamental algorithms, or translate those algorithms into an arbitrary language, your days as a programmer will be few, irrespective of how well you know a particular language.
Preach on! (Score:2)
And I'll go even farther than you, and state:
"Properly written code is largely language independant - so the language you choose to program in does not affect system effectiveness"
Or dumbed down:
"If it works, and it was well-written, then it doesn't matter what language it was written in"
The trick is that you-as-programmer have to assume that you are writing code that someone else will maintain, that this maintainer will be unfamilliar with the language, and that this code runs the system that pays your salary.
You have to optimise your code for LEGIBILITY, so that when the downstream maintainer starts changing it, you give him the highest possible chance of understanding what is actually going on, making the change correctly, and not screwing up your paycheque.
It's really not that hard to do, once you get into the swing of it, and very very rarely does it compromise the ultimate system performance. There usually is no downside.
If you learn to do this, then you can let people work in their language of choice, which pays HUGE dividends in productivity and coder happiness.
I wrote a huge user-management tool in my personal language of choice - perl. Perl maps well into the way I think (you might say I think in perl) Immediately after I wrote it, I moved to a new position in the company, and this massive codebase was dropped on three people who had zero experience with the language. But because the code was optimised for legibility, they picked up on it right away, and were able to greatly extend the functionality of the code with almost no delay and no loss of original functionality.
Forcing coders to work in a particular language - or badmouthing a language because it isn't fashionable (like one moron of a consultant recently chose to do at a meeting I was at) is a sure sign of Not Getting It.
DG
Just an observation... (Score:2, Insightful)
"So what", you may say, "just deal with it."
Well, the problem is not "just dealing" with it - the problem is if classes do not make my life easier, write code faster, write code that fails predictably, then they are in fact failures.
Part of my history with software is I like to write software that you look at and go "oh, I could have written that". Which is far more difficult than writing code that is hard to understand. "Intuitive programming" is what someone once called it (I forget the brilliant soul who came up with the phrase). C++, much like Java, does not fall into that category.
Sooooo, it was with much trepedation that I plunged into Objective C. At first, I hated the syntax (and the NeXT/Apple classes). Then, quickly and surprisingly, I learned how rich and powerful it was. Best it really DID make programming easier and fun again.
But I am back at C++ (ugh). It is again like cutting off both arms and legs and being expected to whip Jet Li's ass. Yah, right!
OO has been touted as the best thing since sliced bread, yet I have found that for the most part it is like having bread where all the slices are tagged as "virtual" - the REAL slicing still has to be done by yours truly. And to be honest, the tools are still effing primitive. I can't believe that we STILL debug EXACTLY the same effing way we did 20+ years ago (okay, source code debugging makes it easier still, but not significantly).
Finally, for those who expect Microsoft to save the day, 'bout time to give up on those losers. By the time they get something out and it is being used a LOT, they dump it for the NEXT GREAT THING (and folks see pink slips).
Sounds like DB normalization?? (Score:2, Interesting)
My Book Title (Score:2)
The syntax of a language? Easy to master in a short period of time. Usage in expressing ideas? Months. Years. It's amazing what people think they can get away with shortcutting.
Cross platform (Score:3, Insightful)
Making "Write Once, Run Anywhere" a Java mantra was a huge mistake. It should have been more like "Write once, tweak a little, maybe it'll run... But it's easier than porting C code!" A more modest claim would have been much better.
Re:Cross platform (Score:2)
Let me guess, you don't work with marketing, right?
My opinion? Those who believe it without trying it makes a mistake, but from a marketing point of it was brilliant. Imagine the number of power-point slides with
* Platform independent
that has been shown to management as a rationale when choosing Java technology for the upcoming project.
Just because it is presented and accepted as a rationale doesn't mean it *is* rational. The marketing is brilliant.
Re:Cross platform (Score:2)
When I said a huge mistake, though, I did mean with regards to the loss of developer respect that resulted from the ultimate failure of that claim. Obviously with regards to manager acceptance it was a hit, and for that I can't fault them. But they still should have said what was -really- going on, maybe on some hidden developer-only web page that managers would never see.
Re:Cross platform (Score:2)
Re:Well hell yeah! (Score:2)
Not to be rude, but if you're so "bitter" about Java why don't you design something better? I agree that Sun overmarkets Java's cross-platform capabilities, but for the most part it DOES work. I don't know of anything else (commercial-quality, that is) that works across as many hardware platforms, especially for server-side apps, which is the area where Java has really done well. Most of the examples in the book seem to revolve around J2EE and Servlets.
Yes, applets suck for the most part. Oh well...big loss there. Then again, most crappy applets I've seen tend to be the ones where someone implements a menu-bar or some retarded visual gimmick.
So Java has it's problems, but there's no more reason to be bitter about Java than any other software platform.
Re:Well hell yeah! (Score:2)
Take a look at Python [python.org]. It doesn't have a large commercial backer, but it is commercial-quality. NASA uses it, Disney uses it, more shops than you probably imagine. Oh, and python simply rocks.
Re:Well hell yeah! (Score:2)
Other than this, I have not heard of Java code not being portable across platforms. I'd love to hear some examples of what you are talking about.
Re:Well hell yeah! (Score:2)
Nevertheless, the code does not run on multipul platforms (until 1.4 at least)
Re:Well hell yeah! (Score:2)
Re:This book is right on the money (Score:3, Insightful)
Oh, then he's an idiot. ;-)
His final chapter is scathing (words like "worst" and "language" and "ever" all pop up) but is entirely factual.
Sounds like flamebait...er...'opinions' to me. Not facts.
The fact is Java is good for nothing but web applets and only then if you don't care about uptimes.
Nice assertion...now back it up with some facts. You might want to start by explaining how all those application servers out there do so much useful work running Java. Then go download Eclipse (www.eclipse.org) or JBuilder and then explain how such great IDEs could possibly be written in Java. There are also plenty of great Java-based websites out there, StockCharts.com [stockcharts.com] being one example.
Fact is, Java is very good these days. Like anything, it has it's warts...but the good far outweighs the bad. Being able to target Windows, Linux and MacOS with a single code base is sweet.
There may be issues with specific Java libraries and frameworks. Don't confuse those with the language or runtime, which are both fairly clean.
Re:This book is right on the money (Score:2)
My memories of JBuilder contradict this. JBuilder was very prone to crashing and taking the OS with it..
I've used JBuilder 4 heavily for over a year (it is written in Java/Swing). It never crashes for me. I often leave it up for days at a time (perhaps weeks). This is all under RedHat Linux 7.1.
Just to add my .02 but I don't think Java is the best tool for the web. Its one niche IMHO is for applications with GUI frontends that need to be portable. If you don't need portable and you don't need GUI then don't use Java.
My view is that Java is the best cross-platform OO language around. It has very strong industry support, and there is plenty of Java talent available. It is suitable for most complex projects, and is far more productive than C++.
Someday something better may come along...until then Java fits the bill for most development.
For web stuff - what could be better than Perl? :)
Almost anything that's not ASCII line noise pretending to be a programming language? ;-)
Re:This book is right on the money (Score:2)
Actually, I have seen some decent Perl lately. I've seen quite a bit of older stuff that was darned unreadable, though.
My personal interest is high-performance computing (coupled with productivity and cross-platform deployment) so Perl isn't a good fit. I've always liked the idea of a "swiss army knife" language, and Java (coupled with C if necessary) seems like the right choice at the moment.
Re:This book is right on the money (Score:2)
Ever since version 4, JBuilder has been a Swing app.
That is how it easily supports Linux, Windows and MacOS. Download the personal version and check it out.
Re:This book is right on the money (Score:2, Interesting)
Re:A T*roll.... (Score:2)
Pascal [qut.edu.au]
Scheme [gnu.org]
Python [jython.org]
Re:Comp Sci degree == bad code (Score:2)
Something that is commonly overlooked though, is that academic experience has a significant benefit when combined with practical experience. Having one, but not the other, has a whole host of problems.
It's not meaningless to have a comp sci degree, but having a comp sci degree does not, in any way, make one a programmer.