Popular conceit about learning programming languages
Dennis Lee Bieber
wlfraed at ix.netcom.com
Thu Nov 21 21:03:11 EST 2002
Brad Hards fed this fish to the penguins on Thursday 21 November 2002
02:55 pm:
>
> The big thing I don't yet really get is OO. I don't see solutions in
> terms of classes yet. In the natural language analogy, this is the
> equivalent of never come across a tonal language (for those not
> familiar, this is very roughly where the meaning (in a denotational
> sense, not just a connotational sense) of a sound varies with how it
> is pronounced - the same sound with a rising frequency might be a
> verb, while a flat frequency might be a noun). No OO is a big hole,
> and while I can program using classes (in C++ and Python) a little
> bit, I don't really "see the solution" in those terms yet.
>
Unfortunately, OO is not a language specific feature... It is a whole
philosophy of how to look at a problem.
While not easily done, one /can/ apply OO to even FORTRAN applications.
I'll admit I tend to have difficulty applying OO to abstract things
(like records in a database <G>).
Much easier to learn by applying to real-world objects. Are you
familiar with RPN calculators? (mainly because I don't want hassle with
the ugliness of arithmetic/algebraic/algebraic-with-parens processing).
The simplest RPN calculator has a 4-entry stack, a display, 10 digit
buttons, a decimal button, four functions, clear, and an enter button.
Objects are: button, stack, display.
Stack object has "methods" "push" and "pop" (with internal data for
the stack itself)
push does:
shift the stack data
save new value
display.display(value)
pop does:
str = stack value
shift stack data (duplicate top of stack)
return str
Display object has "display" method (do whatever is needed to drive
display)
Button object has sub-classes of "digit" (include decimal here for
simplicity), "operator", "enter", "clear"
Digit buttons, when pressed perform essentially the following:
str = stack.pop
append <button constant digit> to str
stack.push(str)
Operator buttons perform:
str1 = stack.pop
str2 = stack.pop
rslt = value(str2) <operator constant> value(str1)
stack.push(rslt)
And similar for enter and clear. NOTE: I've not covered the fact that
a flag is needed in the stack to indicate that the entry is complete
(which means digit buttons start a new entry, rather than append to
current entry).
Or a radio... The basic radio has a tuner and an amplifier. A tuner
has frequency as a settable parameter, amplifier has volume setting.
Fancier radios may extend the object with balance, FM/AM, frequency
band settings, etc.
--
> ============================================================== <
> wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed at dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
More information about the Python-list
mailing list