Fog Creek Software
Discussion Board




Sources/ Training for O-O Design Principles

I've been programming for a Java web app on the job for about a year now, Servlets, JSP, and data access objects. I'm interested in hearing from the JoelOnSoftware brain trust; some good ways to increase my object-oriented IQ. Whether you've taught your self through books, or taken courses, or learned on the job, I'd love to hear what has worked and what hasn't. I learned Java basics in two courses at a local college before switching roles to full-time development on the job. That worked pretty well and has allowed me to perform the job, but I'm looking to take it to the next level in the most practical way possible. Any advice?

Thanks,
Pete

Post-Mortem Pete
Sunday, March 30, 2003

Stop learning from books, course materials and presentations - start learning from sources. Really.

Find a program that interests you, _that comes with source_, and start reading it, file by file, class by class. Try to understand why the developers took the decisions they did, how you would have done it before reading their code, how you'd do it after reading their code, what tradeoffs are there to each decision, etc. [ http://freshmeat.net ] and [ http://sourceforge.net ] are great places to find real working programs with source - both are Unix oriented. I'm not aware of any similar Windows software-with-source directory or repository.

And don't subscribe to the all-too-common O-O biggotry; If you look at programs that actually work, you'll notice many of them make very light use of O-O or not at all. Try to see why is that, and in what way would O-O simplify things - and if you know how, try to implement that.

O-O has its place - it's just not as big as most people think it is.

Advice above (about learning by reading _real_ code) is, in my experience, the best way to learn programming, regardless of the paradigm you want to learn, and it is especially useful in evaluating the merits of competing paradigms.

Ori Berger
Sunday, March 30, 2003

Read the Gang of Four Design Patterns book.

It's not real big on theory or principle, but it really opened my eyes because it demonstrates how to solve a set of specific problems in an OO way. It really shows some of the ways of thinking behind some solutions.

I'm not sure if it'd be a good teacher book or not, but I think it's required reading for any OO guy.

Also, Fowler's Patterns of Enterprise Application Architechture is similar, but with patterns more geared towards enterprise apps (web apps, database apps, O/R mapping). It gives a good once-over of a lot of useful things for ent. apps. This may be more directly applicable to something you're writing now.

Again, these aren't tutorials, but you should see some of the reasoning behind some common strategies, and I find those insights invaluable.

Mike Swieton
Sunday, March 30, 2003

Give "Thinking in Java" by Bruce Eckel at try.  He offers an online version at http://www.mindview.net/Books/TIJ/ Another book to take a look at is Java Design by Peter Coad and Mark Mayfield.  You also might want to take a look at some of Scott Amblers articles at http://www.ambysoft.com/onlineWritings.html

Rich
Sunday, March 30, 2003

"Design Patterns Explained" by Shalloway & Trott

Walter Rumsby
Monday, March 31, 2003

Great comments Ori, but how can you tell good code samples from crap when you're learning?

KLink
Monday, March 31, 2003

Argh, I was going to type some more in my original post, but the keyboard on the laptop I'm using keeps dying.

Anyway, the Shalloway and Trott book "Design Patterns Explained: A New Perspective on Object Oriented Design" - http://www.netobjectives.com/dpexplained/dpe_book.htm - is excellent. The GoF book is more or less a catalogue of patterns, while DPE looks at statements like "favour composition over inheritance" and explains why that strategy is a good idea. The book lives up to its subheading ("a new perspective...") and I now try to apply their conclusion (OO supports encapsulation, OO designs should encapsulate variation) whenever I write code these days. NetObjectives (Alan Shalloway's company) also offer training in the U.S. I believe.

Joshua Bloch's "Effective Java" is essential for Java developers.

"Pragmatic Programmer" is essential for developers.

Walter Rumsby
Monday, March 31, 2003

I think Ori is bang on the mark.  Personally I worked with the Dynapi framework for cross browser DHTML.  Although the project itself has fallen off now before reaching its final objectives it is a great example of using OO to encapsulate underlying complexity.  The nightmare of working with IE and Netscape is hidden under a neat object model.  I think the team finally became fed up with shifting standards, but it is still a good advert for what OO can do.  http:dynapi.sourceforge.net 

Before you can really start to get OO you have to ask yourself what OO can do for you.  OO propeganda says that OO is a magic fairy dust, like Tinkerbell in Peter Pan.  You just shake it over the project and the code just takes of and flys.  When this doesn't happen its because you just don't believe strongly enough.

So find something you want to do with OO, then use it to achieve that goal.

Ged Byrne
Monday, March 31, 2003

I know the DynAPI Ged, or at least I was familiar with it when it was being run by Dan Steinman (I wrote an OO cross platform DHTML API based inspired by DynLayer). In the case of DynAPI platform differences where handled by something like:

  if ( document.all ) {
    // is IE!!!
  } else {
    // it's Netscape
  }

Which is okay for two different platforms, but with multiple versions, multiple operating systems etc. it's not a great way of encapsulating the variation. Head down to your local bookstore, read Chapter 8 of "Design Patterns Explained" and you'll see how the Bridge pattern is a much cleanier, much more extensible solution. 

Also, you're talking about DHTML in web browsers including Netscape 4, which is a bit like talking about formula one driving in the streets of Mumbai (very ambitious, I wouldn't do it myself).

Walter Rumsby
Monday, March 31, 2003

Sorry, chapter 9:

http://www.netobjectives.com/dpexplained/download/ch09.pdf

:)

Walter Rumsby
Monday, March 31, 2003

Walter,

There was plenty wrong with the Dynapi, but what it did demonstrate was the potential of OO.

Before using Dynapi all those tests for IE or Netscape were in my code.  The relief of using an API, and the increase in productivity, where remarkable at the time.

This is just one possible big payoff for OO.  Taking a very wild implementation (eg.  with Windows API) and taming it beneath a blanket of abstraction (eg. Delphi's VCL or .Nets Winforms)

I'll read up on the Bridge pattern.  Thanks for the tip.

Ged Byrne
Monday, March 31, 2003

Walter,

What a well written chapter.  I think I'll have to buy the book now.

Thanks.

Ged Byrne
Monday, March 31, 2003

KLink - there's a lot to be learned from crap code - how NOT to do it. Knowing what NOT to do is extremely important, and extremely underrated.

Examples of thing that are well designed and work well are (off memory:)

The Python language [ http://python.org ] - download the source, and read the library as well as the interpreter code. It's relatively clean for what it achieves, it is consistent, well commented, and extremely functional.

The FLTK GUI toolkit [ http://fltk.org ]  - delievers amazing performance and simplicity and is extremely well engineered (even though a bit unorthodox - it's OO according to most definitions, but it uses globals extensively - and for good reasons; Look at the examples and at real world programs in the Bazaar and compare how much work you need in other toolkits to achieve similar functionality.

The qmail mailer [ http://qmail.org ] - is an example, but I'm not sure what of :). It's an ultra efficient, ultra robust, ultra secure mail server; The source is very hard to read, but you'll learn a lot if you insist on reading it until you can understand how it works.

Qt [ http://trolltech.com ] is a great example of a gui and general purpose toolkit - it is well commented and well engineered (and the X version is GPLd - you'll have to pay for the Win32 sources).

KDE and Linux are examples of huge systems which are extremely readable, extremely functional, and you can learn a lot from reading their sources.

Fabrice Bellard's stuff [ http://bellard.org ] is also inspiring - it has a cross platform x86 dynamic translator, an extensible WYSIWYG HTML editor that does just about anything you want and is 125K when compiled, a short but capable ANSI C compiler. His code is VERY readable.

There are many examples of good code, and even more examples of bad code (I won't give my list here -- it is not my intention to start a flame war).

Comparing how a task is achieved in different paradigms and different languages is also enlightening. If you look at compilers/parsers, you'll notice that the non-OO ones are more intuitive, more efficient and simpler (but not less capable) than the O-O ones.

If you can't tell that code you see is crap (and, unfortunately, most coders today don't have the required experience), then it is more reason to read _everything_ you can get your hand on. Eventually, you'll be able to tell in a few minutes what code is complex, what code is simple, what code is crap, what code is clever, and what code is bound to have endless bugs if it ever reaches QA. That alone is worth all the time you invest.

Ori Berger
Monday, March 31, 2003

I'm (re)learning OOP too, by using a multiparadigm language (Python) and using less power than usual.  Java forces you to use its paradigms, so it's hard to learn what it's like to go without.

I'm seeing things like the usefulness of adding type tags to my data.  I see how in Python, the OOP features provide a convenient type facility for you, and appreciate how it would simplify my job if I used it.

Also, it's useful to pass messages to data.  Again, Python's OOP manages that too.  At some point, when the design is more solid, I'll have to switch to OOP.

I started understanding OOP when I read SICP (links at bottom), even though it doesn't actually talk about it by name.  It alludes to it in an impressive way.

I'm also going through Pierce's book on types and Sonya Keene's CLOS book.  (The propaganda is that CLOS is better than message passing.  I don't care, I'll see for myself.)

I hear Bertrand Meyer's OOP book is useful.  I skimmed through it a long while ago, but found it dogmatic.  I'd like to build up a little knowledge before I go through it, because it glosses a number of things, and is software-engineery.  That's a bit of a turnoff.

Free SICP video lectures and online book:
http://www.swiss.ai.mit.edu/classes/6.001/abelson-sussman-lectures/

Tj
Tuesday, April 01, 2003

I am surprised that no one mentioned object mentor and robert c martin?

Karel
Tuesday, April 01, 2003

I've heard good things about Robert Martin and his books as well.
I am very interested in diving into a quality open source code base which has been wisely mentioned here. Please continue to recommend any that you feel are especially clean and elegant, ideally written in Java as that is my focus right now.

Thanks,
Pete

Post-Mortem Pete
Tuesday, April 01, 2003

*  Recent Topics

*  Fog Creek Home