Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Java Books Media Programming Book Reviews

Bitter Java 427

Peter Wayner writes: "There are 1693 books for sale at Amazon.com with the word "java" in the title and almost all of them are earnest, chipper books that promise real programmers, dummies , and nuts that learning Java is easy. Bruce Tate's, Bitter Java , is not one these books." Read on to see if you'd like to experience Bruce Tate's bitterness first hand.
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.

This discussion has been archived. No new comments can be posted.

Bitter Java

Comments Filter:
  • by PhysicsGenius ( 565228 ) <`moc.oohay' `ta' `rekees_scisyhp'> on Thursday May 16, 2002 @10:24AM (#3529607)
    You neglect to mention the conclusion, probably for fear of reprisal by Slashbots, but I have no such fear. He advocates the total abandonment of Java. His final chapter is scathing (words like "worst" and "language" and "ever" all pop up) but is entirely factual. The fact is Java is good for nothing but web applets and only then if you don't care about uptimes.
  • Antipatterns (Score:5, Informative)

    by Frums ( 112820 ) on Thursday May 16, 2002 @10:37AM (#3529687) Homepage Journal
    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.

    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:The solution (Score:2, Informative)

    by BrokenHalo ( 565198 ) on Thursday May 16, 2002 @10:45AM (#3529749)
    So what is the solution?

    Go back to assembly! :-)

  • by Glock27 ( 446276 ) on Thursday May 16, 2002 @11:07AM (#3529882)
    I think the point is that the simple, stupid (i.e. clean) use of objects in Java can make it slow.

    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++. ;-)

  • by fingal ( 49160 ) on Thursday May 16, 2002 @11:24AM (#3530010) Homepage

    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:-

    AntiPatterns are fun to read and discuss with firends. But get serious! This book is about the truth of software technology and development. In it, we define what's really hapening in technology and on software projects, and what you can do about it. AntiPatterns identify those bad design concepts, technical approaches, and development practices that lead to poor-quality software and project failure. This book also explains how projects identified and avoided these problems to improve their designs and practices for software success.

    Can you handle the truth? The truth is surprisingly hard to comunicate, and often regarded as politically incorrect and undiplomatic. The truth does not make everybody happy. In order to make this exposition of our industry palatable, we resort to comedy wherever feasible; and it has been said that comedy is the most serious tragedy. The truth is that the state of software engineering today is a tragedy: Five out of six coprporate development projects are considered unsuccessful. [Johnson 95]. Most software systems that are delivered fall far short of the desired features and virtually every system is a stovepipe, unable to accommodate changing business needs.

    In trying to explain this universal lack of software success, we came to the conclusion that there are many more AntiPatterns in practice than design patterns. In Internet time, technology is changing so fast that the design patterns of yesterday are quickly becoming the AntiPatterns of today....
  • Sample chapters (Score:4, Informative)

    by jacoplane ( 78110 ) on Thursday May 16, 2002 @11:35AM (#3530078) Homepage Journal
    There are some sample chapters available on the book's website [manning.com]
  • by melquiades ( 314628 ) on Thursday May 16, 2002 @11:40AM (#3530114) Homepage
    Another really superb book is Effective Java, written by Josh Bloch, who is responsible for the Java Collections API.

    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 ... it's superbly written. Bloch's prose is crisp, clear, and gets right to the point. It is, in fact, my favorite book devoted to a single language since K&R.
  • by scrytch ( 9198 ) <chuck@myrealbox.com> on Thursday May 16, 2002 @11:42AM (#3530130)
    The only programmers using design patterns are C++ and Java programmers.

    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.
  • by Anonymous Coward on Thursday May 16, 2002 @11:52AM (#3530191)
    Did you know that one of the primary reasons why many Lisp programmers see patterns as useless is that 90% of the patterns in the Gang of Four book are directly supported features or otherwise trivial non-issues in the Common Lisp Object System?
  • by Anonymous Coward on Thursday May 16, 2002 @12:43PM (#3530631)
    Give me just one example so I can begin to take you seriously.

    I not a devotee of purely functional languages, but check out this essay [norvig.com] on the role of patterns in Lisp. The author was a research scientist at Sun is presently head of research at Google. If it doesn't convince you, nothing will!
  • by Anonymous Coward on Thursday May 16, 2002 @01:42PM (#3531208)
    "his" is gender-neutral in this context.

    Much like in spanish, where a plural containing at least one male uses the masculine form.
  • by Anonymous Coward on Thursday May 16, 2002 @02:56PM (#3531935)
    Even better are "strict" type-inferencing languages. (O'Caml for example)

    The type is determined by its use and enforced. I wish C/C++ had similar facilities.
  • by Anonymous Coward on Thursday May 16, 2002 @02:56PM (#3531940)
    I have to say that I really miss typed-variables. Nothing catches a mistake faster than a type mismatch

    I don't miss typed variables at all. You can OPTIONALLY declare the types of variables using (declare ...). Lispers treat declarations as "hints to the compiler to make things fast" rather than strict contracts. If you want to enter into such contracts, you can...

    Or you can eschew functions and use methods exclusively. CLOS methods are really "multimethods" -- they dispatch on the types of as many of their arguments as you care to supply types for. Using methods instantly reveals when you've supplied an argument of the wrong type (since no applicable method will exist).
  • by Ed Avis ( 5917 ) <ed@membled.com> on Thursday May 16, 2002 @03:05PM (#3532028) Homepage

    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.

  • by alispguru ( 72689 ) <bob@bane.me@com> on Thursday May 16, 2002 @03:09PM (#3532054) Journal
    I think there seem to be fewer patterns in Lisp, because Lisp needs them less. Lispers tend to dismiss patterns because of presentations like this one [norvig.com] by Peter Norvig, in which he shows that roughly two-thirds of the patterns in the Gang of Four book deal with techniques that are unnecessary in Common Lisp.

    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);
    // Mess with file...
    }
    finally {
    myfile.close();
    }

    and

    (with-open-file (myfile filename)
    ;; Mess with file...
    )

    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.
  • by jaoswald ( 63789 ) on Thursday May 16, 2002 @03:36PM (#3532203) Homepage
    Lisp macros are also compile-time. And, because the transformations they perform end up producing "ordinary" Lisp code, all Lisp compilers get them correct. Also, since the macro language is the same as the base language, it is well-defined. In fact, a substantial portion of a Lisp compiler is likely to be written using Lisp macros.

    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.

Thus spake the master programmer: "After three days without programming, life becomes meaningless." -- Geoffrey James, "The Tao of Programming"

Working...