[Discuss] Functional programming @ UVic (was 'C' string tokenizer
for those who hate strtok)
Adam Parkin
pzelnip at telus.net
Mon Jul 3 11:47:27 PDT 2006
dbarker at turing.cs.camosun.bc.ca wrote:
> Actually I think C++ would be a far worse choice than C. The syntax
> has become more complex with the recent versions, so that hello world
> now has to have either
True, and I did see this when I did a C++ course at college a few years
back. C++ is a massive language, but so long as you stick to a subset
of it I think it would help the problem (although I agree C++ isn't an
ideal choice -- but I disagree that it is worse than C, at least in C++
you have references so you can shield the coder somewhat from problems
with pointers).
> This last year we made python our first programming language at
> camosun. It is sufficiently close to pseudocode that when I translate
> the algorithms from the text we used to use for the Into to Computer
> Science course into python and showed them to other faculty most
> didn't see any difference until it was pointed out to them.
But is that necessarily a good thing? There's something to be said for
having to really understand a piece of pseudocode so that you can
implement it in an actual language, and if the mapping from pseudocode
to actual code is essentially 1 to 1, then perhaps then the process
becomes more mechanical than actual understanding. That happened to me
in the numerical analysis course @ UVic (CSC 340) as the assignments
were all just taking the psuedocode from the book and rewriting it in
Matlab which was often trivial and didn't require any real understanding
of what was going on.
> Although a single iteration (recursion?) of the course is hardly
> statistically significant, my feeling, both during and after teaching
> it, was that we are definitely on the right lines. Most of the
> students enjoyed it too - which is more than can be said for java,
> when that was our first language.
But of course, just because students enjoyed it doesn't mean it's the
best choice. I hated learning ML, but now when I look back on it, it
was one of the most beneficial learning experiences I had in my
undgraduate studies. At any rate, I would love to hear how well Python
does in future versions of the course as it sounds like your initial
experiences are quite promising.
> I believe that as of python 2.something you can use { and } to delimit
> blocks.
>
> I don't tell my students this...
Yeah I know that braces are optional, as are statement terminators, but
I just think that Python doesn't "feel" like a normal programming
language. It just feels too different from most to be used as the intro
to programming language of choice. But then again, maybe that's just my
inexperience and bias against Python talking. =;-> I just find that
when I try to write code in Python I feel like I'm fighting the
language, whereas when I write code in Perl, Java, C, etc it feels
natural to me (but perhaps that's because I'm jaded by years of writing
in "typical" imperative/procedural style languages that all look more or
less the same).
The other big drawback I see with Python is the lack of good reference
material (not online, but printed books) that are good introductions to
the language. Perl has the Llama book which is one of the best intros
to a language you'll find and while there is a Learning Python book,
it's my understanding that it isn't anywhere near as good of an
introduction to the language as Learning Perl is (the latest edition of
Learning Python is something like 500-600 pages as well, which is way
too long for an introduction). And of course you could fill a library
with books just on C/C++ and Java.
I was blown away when I went to the Uvic library to find books on Python
and found none. Perl OTOH has 9 titles in the UVic library, and there
are tons of books on Java, C, or C++ there. Of course that's more of a
criticism of the UVic library than of Python, but still.... =8-p
> Well the WYSISYG nature of the indentation is IMHO almost reason enough
> to use it...15 years teaching experience has shown that if you don't
> force students to intent properly, most of them never will.
ABSOLUTELY. It blew me away when I just recently had to mark
assignments for the course I'm TAing and how many students in 2nd year
still don't know how to indent properly. I gotta admit I have no
explanation for that one, as how hard is it to learn to indent properly?
> Example: when we were still using modula-2 we had one instructor whose
> marking was done almost entirely on the basis of program layout - I
> know of one former student is is still ticked off that a working
> assignment was marked lower than somebody else's no-working assignment
> because of layout.
Yeah I've seen that before. But that's part of the problem with the way
assignments are structured, students are given the impression that it's
the end results that matter, not the "how you solve the problem" that
does, so the focus is on getting something that works rather than
something good that maybe doesn't work quite as well.
> So, I munged the emacs pascal-mode uinto a modula-2-mode, which
> auto-indented and handed it over to the students. "No need to worry
> about losing marks for layout any more!"
>
> How many used it? (A number definitely in single digits)
Yeah, but to be fair if they have their editor do the indenting for
them, will they ever learn to indent properly themselves? Once they go
to a new editor they'd still fall back to the same old bad habits.
> As for python being too much OO, I'm not sure where you get this
> notion from. All the OO stuff is there but you don't have to use
> any of it. You can write entire systems which don't use the word
> 'class' once. (as opposed to the pathetic java insistence on having a
> 'main' class! Oh really...)
Technically, Java doesn't require a main class, but rather (at least
one) class which has a main method which is public and static (and takes
as an argument an array of strings). =;->
As for why I feel like Python is OO, it's the whole thisObject.method()
stuff which has a very OO feel to it. I think if you don't understand
OO-ish syntax or concepts then there is a fair bit of confusion as to
why in some circumstances you use a straight function call with no
object instance and in others you use an object instance followed by a
dot, followed by the function/method. For example I told my students
that pop() is a member of the list class, so we go:
someList.pop()
But think about how many OO concepts are involved with that: the notion
of a class, the notion of a method being a part of that class, and the
notion that an instance of that class has access to any of the methods
of that class, and therefore since someList is an instance of the list
class then pop is available to it. I told the same class that to find
the length of a list you use len, which is a function which takes a
list, which looks completely different:
len (someList)
No objects involved (other than the argument to len), so now there's a
confusion that arises: why is len a function, and pop a method? It just
seems to me that you can't write anything useful in Python without using
methods from one of the predefined classes, and that's why it feels very
OO to me.
--
Adam Parkin
E-mail: pzelnip at telus.net
----------------------
There are two ways to slide easily through life; to believe everything
or to doubt everything. Both ways save us from thinking.
-- Alfred Korzybski
More information about the Discuss
mailing list