OO programming - illumination?

A

Andy Dent

In other words, I got nothing against OOP, I just don't find it the
right paradigm for EVERY problem:

this->add (this->value);

Is simply less clear and evident than:

a += a;

Or even:

a dup @ swap +!

Umm, what has choice of syntax got to do with OOP?

How many of the people on this thread arguing against "OOP" are arguing
against a particular message-oriented and awkward syntax?

For example, a += a; could very well be implemented in C++ using
(horrors) OOP!
 
M

Mike Burke

believe it or not

(SNIP)

I strongly agree that the biggest problem is understanding the problem
domain. I was hoping that OOP and UML would shorten the time needed for
understanding, and here is my current set of assumptions, subject to
change as I get smarter:

1. Programmers should learn to solve problems before they impose their
solutions on others. In business, a problem is defined as the
difference between the way things are and the way you would like them to
be. Important is the scope, timing and location of the problem
elements. In programming, a problem is more like a problem in
mathematics where we are looking for a series of behaviors that lead to
a desired goal. However, since the first iteration seldom leads cleanly
to the desired results, go back to identifying scope, location and
timing to understand why not.

2. Use case forms and diagrams can greatly improve the understanding of
the goals of the system, especially if the system analyst/programmer is
not fully involved in the field of expertise involved. I've been
through dozens of approaches to using UML, and I finally hit on a book
called, "Tried and True Object Development" by Aalto, et al., which
finally made sense to me. I am now willing to spend lots of up-front
time getting all the use case forms I can imagine filled in before
trying to develop the system. Of course, going back to the business
problem "scope" parameter, I believe it's very important to determine as
many desirable and undesirable effects as possible and design the
appropriate behaviors for the system.

3. If you don't understand propositional logic, you probably don't
understand the problem domain. I doubt that anyone is going to parse
the whole system for validity, but prop. logic is an underused tool for
sub-domain problem-solving. Objects should be logically consistent.

4. Nobody really programs but the programmer. I'm a big fan of first-
or second-draft code generation from Rational Rose or similar tools, but
the tools are not sufficient for elegant systems. When I first learned
to program back in 1965, we did a flowchart, then coded from the
flowchart (an assembly language called AUTOCODER...isn't THAT funny!). I
still like the process of building from a blueprint.

I've found my way back to Smalltalk because Smalltalk suits my
thinking/programming style better than most languages do, but I'm multi-
lingual, and I have developed craft in other languages such as VB, C++
and Java so I'm able to speak the language of the country I'm in, and
still successfully develop strong apps and systems.

There are still situations where straight assembly language programming
is superior to high-level languages. I generally use decision tables
instead of flowcharts these days, but the use case forms are still VERY
helpful in understanding the problem.

For OOP, the patterns on
http://www.object-arts.com/EducationCentre/Patterns/PatternIndex.htm
are very helpful. Why re-invent the wheel? This page was helpful in
developing patterns for my other languages, also.

This has been a long post. I hope it's useful to someone else, but I'm
grateful that I can share my opinions with others in this group.

Mike
 
D

Doug Hoffman

No, I use OOP as a technique. Like lookup tables, calculation, and any
other programming technique or algorithm you can think of. That
doesn't mean I find every problem suitable to be solved by using OOP.
In other words, I got nothing against OOP, I just don't find it the
right paradigm for EVERY problem:

Go back and reread my post. Nowhere did I suggest that you or I or
anyone should either not use OOP at or use it for everything. I, like
you, suggest that there might be a middle road. Apparently we do agree
on that.

Regards,

-Doug
 
T

Tilman Bohn

[Removed cl.forth, added and set F'up2 to comp.object]

I didn't follow the (predictably) ensuing flame war closely, so I'm not
sure if this has been addressed. If it has, I apologize, but I didn't see
it. And sorry I'm a bit late in this.

In message <[email protected]>,
Tom Dyess wrote on Sun, 13 Feb 2005 12:36:26 -0500:

[...]
I know absolutely nothing about SmallTalk, but this seems very strange to
me. Are you talking about inheritance?

No, message-passing is a customary generic OO term for describing the
interaction between objects. They send each other messages. Since message
passing has had some other connotations for quite some time that aren't
necessarily supposed to be implied by the term in OO, Jacobson for
example prefers to speak of stimuli (no idea if that alternative has been
widely accepted in the OO community). What it comes down to is that you
trigger some behavior in the receiving object, whether you say by sending
it a message or by giving it a stimulus.

In the context of Java, a method call is a message/stimulus. Returning
something to the caller of a method is a message/stimulus. Throwing an
exception is a message/stimulus.

I think this generic terminology is often employed to emphasize the
decoupling of message sender and receiver achieved through polymorphism,
abstraction and encapsulation (in varying proportions).

[...]
You should always define variables in the lowest scope possible. There is
nothing wrong with local variabes, on the contrary, it's bad form to have a
bunch of global variables, but you will probably always have them, just try
to keep them to a minimum. For example, in a servlet, I keep my DB
connection/pool in a global scope in the servletContext. It doesn't make
sense to create them locally.
[...]

What you say is true, but I think he wasn't referring to local
vs. global variables at all. Instead, I think he meant the proliferation
of method-local variables that serve no other purpose than to be able to
call a method on (send a message to ;-) ) that object, when a cleaner
design would have the object the reference originated from delegate
correctly instead. To illustrate:

Compare and contrast

A a = registry.getSomeA( x ); // just to get started somewhere
B b = a.getB();
C c = b.getC();
D d = c.getD();
d.doSomethingUseful( y );

with

A a = registry.getSomeA( x );
a.doRealWork( y ); // a relays to its b, b to its c, and c to its d.

(Going from the first to the second form is known as the Hide Delegate
refactoring. Notice that a.getB().getC().getD().doSomethingUseful()
wouldn't be an improvement over the first form.)

Note I intentionally named the method on A differently, because to A's
clients another name might be much more appropriate and descriptive than
doSomethingUseful(), which in turn might be perfectly appropriate for D's
clients. But a calling sequence as seen in the first version strongly
suggests the calling code shouldn't really be a client to a D, but rather
to an A. As an added benefit, a, b, and c can all choose to decorate d's
behavior (or decline to do so) instead of simply passing the message
through 1:1. (See how the message passing mode of thinking about it can
be useful?)

While there certainly are cases where constructs as in the first
version are ok (well, maybe not quite that extreme), in general terms I
would claim the second way is _much_ more OO. The first way forces the
calling code to have intimate knowledge of the composition not only of A,
but of B and C, as well as of D's behavior. In the second example, it
only needs to know someone who knows someone who knows someone... who
knows how to do something. Hence, better encapsulation. Of course this
can harbor its own problems, but enough rambling for now. ;-)
 
H

Hans Bezemer

Andy Dent said:
Umm, what has choice of syntax got to do with OOP?
How many of the people on this thread arguing against "OOP" are arguing
against a particular message-oriented and awkward syntax?
For example, a += a; could very well be implemented in C++ using
(horrors) OOP!
Yes, and there is exactly the problem: if you consider using OOP, you
must realize that EVERYTHING is OOP. Why make an exception for
'simple' datatypes like integers and characters? Why not let a integer
value add itself? Or a character make itself uppercase? This strange
mixture of syntax is what makes C++ a horrible OOP kludge. True object
orientation goes all the way. It's like 'I'll always love you, but not
today'.

Hans Bezemer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,192
Latest member
KalaReid2

Latest Threads

Top