J
JoeC
I've taken a while to answer this, largely because it's a hard question
to answer well and I've had to think a while about how to say what I
mean and have any hope of getting my point across.
Good code is often a bit like an allegory -- many of the "characters"
are a lot more pure and idealized forms of some particular idea than
you'd usually deal with in real life. In a book or movie, that can lead
to one-dimensionality -- but in code, we're usually more concerned with
clarity and efficency than depth. Much as a politician tries to portray
a world in whcih "we" are pure good and "they" are pure evil, it's often
convenient and useful for us to create characters as the pure essence of
a single idea.
As character development goes, it tends to stink. It's too quick and
easy to understand a character in a novel who's too one-dimensional, so
they lose our interest fairly quickly -- they're too predictable so it's
hardly worth reading the novel to find out how they'll act in a
particular situation.
For code, however, that's much more what we want -- something that
quickly becomes almost boring, because we hardly have to think to know
how it'll act or react in any given situation. Something we in which we
can quickly lose interest because it's obvious and predictable.
Like an overly-obvious allegory, we also want it to be obvious exactly
what concept each of our characters represents. In fact, we usually go
much further than even a really obvious allegory, and do our best to
make a single character represent only a single concept, with no other
characteristics at all.
Then, when we need a "character" with more than one characteristic, we
literally compose it out of the individual characteristics we've already
defined. IOW, we create a class that directly includes instances of
those other classes the represent the characteristics.
In practice, that means well-written code tends to be built up in
relatively small steps. Each step adds only a _few_ simpler concepts
together into one slightly more complex concept, but (with skill) does
so in a way that's still simple and straightforward to understand.
To use a rather different simile: your code is a bit like a spandex
mini-skirt on woman in her mid-50's. We're only separated from some
things that are less than beautiful by one thin layer.
What we'd like is more like a belly-dancer's costume -- lots of layers
that don't cling too closely to each other. They look a lot more
transparent than the mini-skirt, but still do more to cover up any warts
underneath.
--
Later,
Jerry.
The universe is a figment of its own imagination.
I think I get it. My code is not abstract enough. I am inferring that
I need to have more data hidden in objects and functions. For
starters, I wanted to create seperate functions for paint and create
but my compiler complained. First I am trying to get the program to
work the way I want then try to make it better. The problem I keep
adding and expanding my program and never get back to making it better
part. I should do somthing to make the color object better. That
shouldn't be too hard to put the color statment inside the object.
Still I have made some improvment where I see the opertunity.