Popular conceit about learning programming languages

Michele Simionato mis6 at pitt.edu
Sat Nov 23 08:54:47 EST 2002


> I would like to know more specifically what features make Python 
> special to you. As Kenny put it, in what regards is Pythonthink 
> different from Otherlangthink?

Different languages have different "natural" ways of doing things, so
you have to think accordingly to the language you have at your
disposal. I want to be specific here, and I take an example you cited
in this tread, i.e. the problem discussed in
http://csis.pace.edu/~bergin/patterns/ppoop.html

Here the authors discuss different ways of solving a simple problem in
the same
language, according to different phylosophies. Here it is the solution
I came out in Python in two seconds of thinking, the "natural"
solution at this stage of my knowledge of Python:

def print_OS_evaluation():
    "Gives a thought evaluation of operating systems"

    import sys

    def GoodBox():
        print "This is a good box"

    def BadBox():
        print "This is a bad box"
   
    def UnknownBox():
        print "This is not a box"
          
    printEvaluation={
       'linux2':GoodBox,
       'sunos5': GoodBox,         
       'win32':BadBox}.get(sys.platform,UnknownBox)

    return printEvaluation

The code is pretty obvious, but let me discuss how would I have
"naturally" solved the problem in other languages. Was I coding in
Basic or Fortran, I would have written something like

if platform='linux' then call GoodBox()
elseif platform='win32' then call BadBox()
elseif ...

Very ugly, but these languages (I refer to the old Basic of the early
80's I
learned as my first programming language, or Fortran 77 which is
unfortunately still too much used in the scientific environment) don't
allow you to do much more than that.
You cannot simply *think* of another solution. 

On the other hand, was I working in Pascal or C, where "case" and
"switch" constructs exist, I would have certainly used them. The code
would have been less ugly, and more adapted to these languages, not
simply a translation from Basic.

When I learned Python I discovered dictionaries and I immediately get
in love with them; I started using dictionaries from my first
programs. They allow me to
*think* better, I believe, and now I use the if..elif.. construct much
less
than before. The idea of having a dictionary of functions appeals to
me much
more than a switch statement; still I couldn't have thought of this
possibility
before the discovery of Python. Dictionaries have strongly changed my
way of
solving problems: and you will agree that this is a feature that not
all
languages have or stress as much as Python. I am sure Lisp has even
more
sophisticated ways of doing the same thing; actually I always wanted
to know
more about Lisp, but the parenthesis always stopped me ;-<.

I want to comment on OOP, too. As a I said in a previous posting, I am
still
in the process of learning OOP. At this state of my knowlegde, I tend
to think that OOP is a great idea, but sometimes overkill and too
verbose. That's the reason why even if the original code in
http://csis.pace.edu/~bergin/patterns/ppoop.html
used a class, I prefer to use a function instead. It seems to me that,
for simple tasks, functions are still better and easier to grasp. Of
course objects have their advantages, but if I don't plan to inherit
from a class doing the job of print_OS_evaluation, why should I use a
class at all ? Functions are shorter and easier to maintain, in my
view. Still, the biggest issue I have with OOP is a syntactical one:
too verbose for my taste.

The fact that the code before has come to me naturally, let me suppose
that I
*think* dictionaries and I *think* functions; but not yet objects. I
will say
that I will think *Python* when ALL the constructs of Python,
including dictionaries,lists, strings, functions, objects, etc.  will
be natural to me.

The reason is that Python is multiparadigm himself: therefore if you
want to understand Python you must become multiparadigm yourself. To
be open to different views is in the phylosophy of the language. Other
languages have different phylosophies: for instance Ruby claims one of
its strenghts to be "pure" OOP. If you want to *think* that language,
than you must think "pure" OOP and starting subclassing from
numbers... ;-)

I hope I have answered your question this time: 

Q: what features make Python special to you ?

A: dictionaries (and a lot of other stuff ;-)

Ciao,

                                                Michele



More information about the Python-list mailing list