J
Juha Laiho
Followups set to comp.object; apologies for disturbing comp.lang.forth
readers, but this seems to have a sideline into that direction as well.
I've been trying my hand in programming Java for a while now, but have
failed to see the "big" difference of what is procedural and what is OO
programming until very recently (or this is how I currently feel). I'm
inviting comments on whether or not I finally have the correct idea. My
background is mostly from procedural languages with or without objects
(mostly C, perl), but I've occasionally tried to understand Smalltalk
as well as Forth. In Java I've mostly been limited to server-side Java
(servlets, with an occasional touch of EJBs).
Now, to the thought that occurred to me: in Java, much of the code is
actually not real OO code, but procerdural code that utilises objects.
Still, it would in many places be possible to write Java in more rigid
OO fashion. This'd explain my perplexion in not seeing that much
difference with what I consider "good" perl code and with Java.
Contrasting Java with Smalltalk: in Java, it seems common to write
methods to very procedural form (no return values on methods, lots
of branching constructs). With Smalltalk, it seems that pretty much
all methods have made some selection on which object type to return.
Additionally, methods tend to be very short (esp. comparing to some Java
servlet code I've seen).
The Smalltalk style appears to me to be build on very long (Contrasting
to Java) message chains, which begin by building some new object, then
doing numerous pieces of small-scale processing on that object (and in
the end perhaps/often returning a completely different object than was
originally created). I think I've seen a reference to "message-passing
OO" somewhere.
What I often see with Java is that a single statement contains just
a single method call - and for the cases where the method returns
something, the return value is stored to a variable, to be used
perhaps once or twice later on. So, in many cases, code very similar
to the Smalltalk messaging would be possible, but is not done. This
is the issue that seems odd to me; is this just a cultural issue
(Java programmers largely having a strong background in procedural
programming, and the paradigm shift is not happening), or are there
technical issues somewhere in the history of Java?
Further, in the Smalltalk code it seems that actual branches are not
very common, instead behaviour differences come from very heavy use of
polymorphism (which seems to be much less often used in Java). Again,
is this just a culture issue? Or is the whole issue that the Java code
I've seen is just procedurally written crap - that in "real life" (for
some value thereof..) Java code resembles much more my representation of
Smalltalk?
So, summarizing; what I feel is non-OO in the way I see Java code written:
- many methods written to return no value (void)
- if/else constructs used instead of object polymorphism to achieve
differences in program behaviour
- a lot of avoidable local variables used (references to which could then
be accidentally leaked somewhere, and thus be ineligible for garbage
collection)
This still leaves me to think about the need of exceptions in OO code:
I think exceptions have their place, but are often misused in Java.
My experience with Smalltalk doesn't yet cover exception use, so cannot
make any comparisions on this (does Smalltalk even have exceptions?).
.... and a further question: is "message-passing OO" as used in Smalltalk
the only form of object-oriented programming, or are there other variants
of "pure OO" (as in "not tainted by procedural programming")?
Finally to the sideline to Forth. I seem to see strong resemblance of
Forth idea of threading small pieces of code to modify a set of data
to the Smalltalk object-message style of programming -- just that the
"raw" data of the Forth program is presented as objects in Smalltalk.
Am I just seeing ghosts here, or do these two share some conceptual
similarity?
And thanks goes to anyone for shedding any light on this all-too-long
rambling - but I seriously need handholding to get my thoughts on this
to any sensible shape.
readers, but this seems to have a sideline into that direction as well.
I've been trying my hand in programming Java for a while now, but have
failed to see the "big" difference of what is procedural and what is OO
programming until very recently (or this is how I currently feel). I'm
inviting comments on whether or not I finally have the correct idea. My
background is mostly from procedural languages with or without objects
(mostly C, perl), but I've occasionally tried to understand Smalltalk
as well as Forth. In Java I've mostly been limited to server-side Java
(servlets, with an occasional touch of EJBs).
Now, to the thought that occurred to me: in Java, much of the code is
actually not real OO code, but procerdural code that utilises objects.
Still, it would in many places be possible to write Java in more rigid
OO fashion. This'd explain my perplexion in not seeing that much
difference with what I consider "good" perl code and with Java.
Contrasting Java with Smalltalk: in Java, it seems common to write
methods to very procedural form (no return values on methods, lots
of branching constructs). With Smalltalk, it seems that pretty much
all methods have made some selection on which object type to return.
Additionally, methods tend to be very short (esp. comparing to some Java
servlet code I've seen).
The Smalltalk style appears to me to be build on very long (Contrasting
to Java) message chains, which begin by building some new object, then
doing numerous pieces of small-scale processing on that object (and in
the end perhaps/often returning a completely different object than was
originally created). I think I've seen a reference to "message-passing
OO" somewhere.
What I often see with Java is that a single statement contains just
a single method call - and for the cases where the method returns
something, the return value is stored to a variable, to be used
perhaps once or twice later on. So, in many cases, code very similar
to the Smalltalk messaging would be possible, but is not done. This
is the issue that seems odd to me; is this just a cultural issue
(Java programmers largely having a strong background in procedural
programming, and the paradigm shift is not happening), or are there
technical issues somewhere in the history of Java?
Further, in the Smalltalk code it seems that actual branches are not
very common, instead behaviour differences come from very heavy use of
polymorphism (which seems to be much less often used in Java). Again,
is this just a culture issue? Or is the whole issue that the Java code
I've seen is just procedurally written crap - that in "real life" (for
some value thereof..) Java code resembles much more my representation of
Smalltalk?
So, summarizing; what I feel is non-OO in the way I see Java code written:
- many methods written to return no value (void)
- if/else constructs used instead of object polymorphism to achieve
differences in program behaviour
- a lot of avoidable local variables used (references to which could then
be accidentally leaked somewhere, and thus be ineligible for garbage
collection)
This still leaves me to think about the need of exceptions in OO code:
I think exceptions have their place, but are often misused in Java.
My experience with Smalltalk doesn't yet cover exception use, so cannot
make any comparisions on this (does Smalltalk even have exceptions?).
.... and a further question: is "message-passing OO" as used in Smalltalk
the only form of object-oriented programming, or are there other variants
of "pure OO" (as in "not tainted by procedural programming")?
Finally to the sideline to Forth. I seem to see strong resemblance of
Forth idea of threading small pieces of code to modify a set of data
to the Smalltalk object-message style of programming -- just that the
"raw" data of the Forth program is presented as objects in Smalltalk.
Am I just seeing ghosts here, or do these two share some conceptual
similarity?
And thanks goes to anyone for shedding any light on this all-too-long
rambling - but I seriously need handholding to get my thoughts on this
to any sensible shape.