Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > teaching OO

Reply
Thread Tools

teaching OO

 
 
Ville Vainio
Guest
Posts: n/a
 
      11-24-2004
>>>>> "Gabriel" == Gabriel Zachmann <(E-Mail Removed)-bonn.de> writes:

>> I don't think virtual classes (as in inheriting from base classes
>> "virtually" to avoid a certain multiple inheritance problems) is all
>> that important in this single inheritance favouring world.


Gabriel> ah, sorry, i meant "classes with virtual methods" (i.e.,
Gabriel> classes that have RTTI).

Ah, ok. Python has the clear upper hand here because everything is
"virtual", type(obj) is always the "most derived" version.

BTW, a slight terminology correction - having a "virtual table"
doesn't necessitate existence of RTTI, in fact some systems (Symbian
OS at least) omit RTTI on purpose but still have virtual
functions. Having RTTI means dynamic_cast<Foo>(obj) can return NULL if
obj can not be cast to Foo, while e.g. in Symbian OS C++ environment
dynamic_cast is just the same as static_cast, with all the Access
Violations that go with it .

>> The concept of overloading is easy, you can go one step further by
>> introducing generic functions / multimethods through one of the
>> modules floating around the net.


Gabriel> You mean in Python? (or C++)
Gabriel> Could you give me a pointer to one of those modules?

http://www-106.ibm.com/developerwork.../l-pydisp.html

http://www.cis.upenn.edu/~edloper/pydecorators.html

(the last one has the wrong guess for @decorator syntax, and so has
the examples wrong).

Google for "python generic function decorator" or something along
those lines for more. I bet we'll see one @decorator implementation
become pretty "standard" once Python 2.4 goes final.

--
Ville Vainio http://tinyurl.com/2prnb
 
Reply With Quote
 
 
 
 
Ian Bicking
Guest
Posts: n/a
 
      11-24-2004
Gabriel Zachmann wrote:
>> The concept of overloading is easy, you can go one step further by
>> introducing generic functions / multimethods through one of the
>> modules floating around the net.

>
>
> You mean in Python? (or C++)
> Could you give me a pointer to one of those modules?


There's a simple example of multimethods in the Python Cookbook
(online). PEAK now includes a generic function implementation, a bit
more at http://dirtsimple.org/2004/11/generi...ve-landed.html

Adaptation and interfaces are related idea. I feel like they are a
little vague at this point, as far as best-practices go.

--
Ian Bicking / http://www.velocityreviews.com/forums/(E-Mail Removed) / http://blog.ianbicking.org
 
Reply With Quote
 
 
 
 
Ian Bicking
Guest
Posts: n/a
 
      11-24-2004
Gabriel Zachmann wrote:
> Another question is: can you teach effectively the inner workings, if you
> teach only a dynamic language?


To a degree, maybe not. But I don't think that's the place to start --
to me the foundation of CS is abstract algorithmic thought, not a CPU;
math, not electronics. Again, that's not a perspective everyone agrees
with, some feel it's best to start with assembler.

But then, if you are writing assembler, there's a good chance now that
you'd be writing MIX or some other fake assembler for a fake CPU. I can
imagine approaching that from Python -- code an assembler and virtual
CPU in Python, and start programming it. To the degree that the virtual
CPU looks like real CPUs, you learn about processors. The assembler
teaches the beginning of compiler design.

The next level up -- C, where you are dealing with pointers and memory
management -- probably isn't feasible from Python. In assembler you are
only writing trivial programs, so it's not a big deal that it's slow;
you can't realistically implement either C or an efficient runtime
environment in Python; even if you could, the task would be too large.
But that's okay, C still has an important role in a CS education. I'm
less certain about C++ -- it's neither low level nor high level.

And since Java or C# will almost inevitably be taught at some point,
most of C++'s features and complications are not novel, again making C
seem more reasonable.

--
Ian Bicking / (E-Mail Removed) / http://blog.ianbicking.org
 
Reply With Quote
 
Stelios Xanthakis
Guest
Posts: n/a
 
      11-24-2004
Gabriel Zachmann wrote:


> My question now is: do you think I should switch over to Python completely
> (next time), and dump all the interesting issues involved in C++'s virtual
> classes, overloading, and templates? (In Python, all of that would just
> disappear ... )
>


No! Python, being a dynamic language has certain advantages over
compiled languages.
In analogy with C/C++, in python:
* all functions are pointers to functions
* all methods are virtual
* all classes have a virtual table (__dict__)
* all types are "virtual"
* as a result everything is polymorphic and generic
* etc.

Moreover, in python an instance can have it's own methods, so the
class/instance distinction is different than C++ and friends. Python's
classes are more like "flying dictionaries" or something

IMO, it would be better to proceed normally teaching OOP with C++ and
dedicate extra lessons on "dynamic/interpreted languages and how can
they do everything OOP'd like to".


Stelios
--------------------
How's the PEP going?
 
Reply With Quote
 
Alan Gauld
Guest
Posts: n/a
 
      12-06-2004
On 24 Nov 2004 18:31:13 GMT, Gabriel Zachmann
<(E-Mail Removed)-bonn.de> wrote:

> You know, I keep wondering exactly what we will be teaching as programming
> languages become easier and easier to learn.
>
> Programming itself? -- won't be enough for a whole semester.


Oh no way. You could teach a whole semester just using flow chart
stule diagrams. The concepts of programming stay the same
regardless of language. You just won't need to spend so much time
on syntax, you can focus on the real issues like jump tables,
data types - and how the data structure shapes the code
structure! Issues of locking, error handling strategies,
threading, event-handling etc etc... All of these stop being
advanced features and move into mainstream. Someday....

> Another question is: can you teach effectively the inner workings, if you
> teach only a dynamic language?


Yes, its just different inner workings.

But to be serious. I've never quite understood the sense in
universities teaching students about how C++ VMTs etc work.
They are only relevant to one language - and possibly one
implementation of one language since they aren't part of the
standard - and languages change on a ~10 yearly cycle. (Which
means Java should soon be making way for the Next Big Thing -
BEPL maybe?...)

Concepts like hashes and jump tables and generic compiler
techniques are universal but how a particular language is
implemented is only of marginal value IMHO. It would be
like an Electronics professor spending a lecture dismantling
an oscilloscope and discussing the circuit diagram - mildy
interesting, but ultimately pointless!

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IE 5 as a teaching tool Adrienne Boswell HTML 1 03-09-2006 01:37 AM
self teaching WAN ; driving me back out into the garden to plant peas; frustrated . Barrett Bonden Cisco 5 04-07-2005 04:09 AM
Self teaching, cannot lock database file Michael Powell ASP .Net 2 03-29-2005 03:34 PM
Teaching resources VisionSet Java 2 10-07-2004 07:22 AM
OT: Japanese Teaching/Translation Software Krhis Computer Support 1 09-06-2003 08:30 PM



Advertisments