Skip to main content

If you loved real OO, you wouldn't really love 'if'

Posted by fabriziogiudici on December 7, 2007 at 1:54 PM PST

I've href="">blogged
just a few days ago about the Java Day in Rome,
talking about the event in general. Now I'd like to focus about what
probably was the best talk of the conference.

It's a bit curious, but I knew in advance the contents. href="">Francesco
Cirillo, leader of XPLabs
and global guru of Agile Methods, taught me most of those things a few
years ago, when I was lucky enough to attend a class lead by him as
part of a Sun Microsystems "Train The Trainer" event. It was the event
and the trainer that most dramatically changed my professional life of
OO Architect. I think I owe to Francesco a good amount of thanks if I
can say that in the latest years I was always able to get to the
successful end of a project I was involved with, including the most
complex ones - and I have to confess that so far I was able to put in
practice only a subset of his teaching.

Now sure you're wondering which was the subject of the talk. What if I
told you "how to work in the Object Orientation way?". I bet you'd be
confused: what's exceptional with that? Everybody and his dog knows OO
today, and probably you can even find some introductory slides bundled
with a pack of fried chips. The point is: most of the things we do and
we tag as "Object Oriented" aren't, or aren't completely. For instance,
if you use getter and setter methods, you're not doing a true OO (I
know, I know, NetBeans, Eclipse, IDEA, most of the existing frameworks
use them...). Even more: if you use a lot of "if" and "for" keywords in
your Java code, you're probably not doing a good OO. Many of you are
probably confused at this point. Don't worry: it's ok. When I attended
Francesco's class I had less years in my experience, but - hell - I
presumed I knew a good deal of things, good practices, patterns, etc.
After all I was a pretty good experienced designer with a few large
industrial projects in my CV and I had been in this business for ten
years. Nevertheless, the first day of the class was just frightening:
all of my certainties had been shaken up to their very roots and I
couldn't understand whether a) I was just a OO rookie, after all b)
Francesco was a fool c) I wasn't just understanding what I was being
told d) it was a nightmare and in the end I'd wake up out of it. In the
following days everything went in the right place and I felt as I had
step up in the next level of my OO karma.

cellpadding="4" cellspacing="0">
alt="" src=""> 20071201-0004-400.jpg

Ok, enough teasing. I can't really explain a lot more about this, since
it would require too long. Francesco's talk this year was put in the
context of the href="">"Anti-IF
campaign" (in italian: "Campagna Anti-IF") that he has personally incepted (but as you read
"if", also think of "for", the talk actually focused on the latter).
The basic concept is that "if" and "for" make your code less readable,
but above all they increase the complexity by raising the number of
combinations of path flows and making testing harder.

Now many of you are probably even more confused - "How in the hell I
can program without "for" and "if"? - you can really get rid of them by
using good OO stuff. After all, this is what Ruby people are telling us
when they claim that with Ruby they are "more productive" and write
"less code". Now, the problem is not the language, but your approach to
design. Most of people are dominated by the process and/or the
language/the tools, while the opposite should happen (please, apply IoC
here, too!). You can be as productive with Java - and I'm meaning style="font-style: italic;">today's Java,
without waiting for Java 7. Two memorable quotes by Francesco: "it's
the design, not the language", "it's up to you to cast your favourite
language to fit your needs". Which are one of the reasons for which href="">sometimes
I complain about people too focused on the wonders
of Java 7, as if an improved syntax or a new language feature was the
silver bullet.

In the end, let me give you an advice: if you have money to spend for
the educational budget in 2008, I strongly suggest you about
Francesco's seminars
(don't worry about the language, they can be in italian or in english).