[Tutor] Learning programming

Martijn Faassen M.Faassen@vet.uu.nl
Tue, 06 Apr 1999 11:05:20 +0200


John Kleinjans wrote:
 
> What I'm thinking here about teaching (and learning) programming is that:
> 
> 1. QBasic is a procedural language, and introduces sequence, branches, and
> loops; variables, constants, and data types; input, processing, and output;
> arrays
> and structures (and arrays of structures)... but if you got this far, don't
> put too
> much more energy into it but instead switch to ...

Why not skip QBasic and do Python instead? Python is in my opinion a
much cleaner language than QBasic, and can do anything QBasic can (with
less effort :). You can do procedural programming in Python just fine.
 
> 2. C, which is more... everything (except easy). Now you begin to learn (some)
> how the computer actually works. But still a procedural language.

While C is a good language to know as a programmer, I'm not sure if it's
necessary to teach it in an introductory programming course. It's low
level and makes some fairly basic stuff like string manipulation far
more difficult than it is in Python (or QBasic). *if* you want to teach
C, then Python is a better start than QBasic in my opinion: 

* Python exposes some Pythonized C libraries as modules. This way people
can become familiar with aspects of C (such as stdin and stdout) without
actually programming in C yet.

* You can teach C as a way of extending Python. That way you can make C
useful much sooner.

> 3. OhOh. Now we have to think in a whole new way. At least, I've been told
> by a reputable source that the key to programming objects is to understand
> objects--and then learn how to write code that does that. And I'm not so sure
> that C++ is the best way to _learn_ how to think like that.

I agree, I would definitely not recommend C++ for teaching object
oriented concepts. Python is a good language to teach most basic object
oriented concepts as used in C++ and other OO languages. The main
exception is perhaps data hiding, for which Python has only limited
facilities. Of course one can and should still practice data hiding
without facilities for it in the language anyway.
 
> So (as usual) I'm going from the known to the unknown--and in such a case
> (aka lack of knowledge) I have to go on informed intuition.
> 
> BTW--as I re-read this before sending it (what a concept!) I notice that I
> followed up on a loose end that I left dangling from my previous post. That
> is where I said (and I manually cut and paste) ...
> 
> --> I generally start teaching programming with Qbasic. Then, when the kids
> --> know something about (list of topics here)
> 
> ... that "list of topics here" was (partially) enumerated above in #1.
> 
> Do we need to teach all these things _before_ we get into objects? How much
> procedural programming do we need to learn OO? How and where does
> knowledge of procedural programming methods interfere with learning OO?
> Is there an OO way of thinking that doesn't depend on ...

Actually, good procedural and object based (which is basically
object-oriented without inheritance) is not that far apart at all.

procedural (in Python):

# define the structure of the data
# could be a dictionary, a list, an empty class, or a data-only class or
whatever
data = {}  

# define procedures which work on that data
def print_data(data):
    for key in data.keys():
        print key, data[key]

def add_keyvalue(data, key, value):
    data[key] = value

...

# to use:
mydata = { "foo" : "bar" }
print_data(mydata)
add_keyvalue(mydata, "hm", "um")

object based (in Python):

class Data:
    def __init__(self, some_data):
        self.data = some_data  # initialize object self with some
starting data

    def print(self):
        for key in self.data.keys():
            print key, self.data[key]

    def add_keyvalue(self, key, value):
        self.data[key] = value

    ...
# to use an object of this class:
mydata = Data({"foo" : "bar"})
mydata.print()
mydata.add_keyvalue("hm", "um")

In Python, object based is introduced rapidly as many built in modules
and even more importantly, the sequence data types make use of object
based techniques:

mylist.append(7) # object based way to add 7 to a list

> Anyway. I can't answer these questions because I don't know OO. As I said
> earlier, I've intentionally kept away from C++ in an effort to clearly
> learn C.

That is a good idea; it's good to learn C (and all the lore and
programming techniques associated with it -- C itself isn't much without
all the lore on how to use it):

* C can be compiled to very efficient code

* Many programming libraries (such as those in Windows and Linux) are
most easily used/interfaced to from C (as the libraries themselves are
in C).
 
* it opens up a lot of sources to your perusal (the majority of open
source/free software projects, including Python, are written in C)

Good luck, and regards,

Martijn