Popular conceit about learning programming languages

Robin Munn rmunn at pobox.com
Mon Nov 25 14:32:58 EST 2002


Kenny Tilton <ktilton at nyc.rr.com> wrote:
> 
> 
> Bengt Richter wrote:
>> On Thu, 21 Nov 2002 18:03:48 +0100, Pascal Costanza <costanza at web.de> wrote:
>>>Could you try to describe what it means to you to think in Python? What 
>>>makes it different from thinking in other languages? (This is not a 
>>>rhetorical question!)
>>>
>> 
>> (Please pardon my jumping in with my view. I realize you didn't ask me ;-)
> 
> Nor did you answer him! :)
> 
> What is it about Pythonthink that is different from Otherlangthink?
> 
> I actually was wondering the same thing, because I do not see a lot 
> different in Python from C other than very practical advantages, such as 
> the indentation thang and GC. But I just am digging into Python, so 
> whadoiknow?

Well, one of the first observations I would make about the difference is
Python's high-level-ness. I came to Python via a C->Perl->Python path,
but with rather little time actually spent in Perl. So my experience in
learning Python has been, I think, rather similar to what yours will be.
I found myself writing for loops that weren't necessary, e.g.:

    # Thinking in C, translating into Python
    new_list = []
    for item in old_list:
        if (item % 2):   # Keep only the odd numbers
            new_list.append(item)

    # Thinking in Python
    new_list = filter(lambda x: x%2, old_list)

Of course, list comprehensions are much more similar to the for loop, so
this is not the best example; but I think you'll get the idea.

I think my biggest adjustment going from C to Python was that instead of
thinking code-centrically, I started thinking data-centrically. In other
words, I started thinking, "What operation do I want to perform on my
data next?" and looking for the shortest way to do that operation. It's
surprising how many of those shortest ways turned out to be idiomatic
one- or two-liners in Python. :-)

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838



More information about the Python-list mailing list