Re: Python vs. C#

Discussion in 'Python' started by =?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=, Aug 10, 2003.

  1. "Brandon J. Van Every" <> wrote in message news:<3f357a9b@shknews01>...
    > So again my question is, language-wise, what can I get done with Python that
    > I can't get done with C#? What is easy to express in Python, that is
    > tedious, difficult, or impossible to express in C#?


    There aren't many single cases where Python can express things
    considerably better, but in general Python leads to about 50% of the code
    that you'd end up with in C# (actually, I've only had this experience
    when comparing to Java or C++, but C# is quite similar to Java).

    First, I'll give some of the real examples that can't be expressed
    in C#. I can make a memoize()-function in Python, that remembers
    what arguments were passed to a function and what the return value
    was, so calling again with the same arguments is but a simple
    hash table look-up.

    def fib(n):
    return n < 2 and 1 or fib(n - 1) + fib(n - 2)

    Everyone knows what kind of recursion nightmare that is. But
    let me add this line:

    fib = memoize(fib)

    Now fib() calculates fibonacchi numbers in linear time and
    for numbers that were already calculated, it's O(1) (average case,
    mind you. hashes can be slow when unlucky). I'm not an expert
    in C# but I still dare to say you can't make such a generic
    function as "memoize".

    Python has some other features not found in C# (AFAIK, once again)
    that can lead to considerably cleaner and shorter code. At least
    metaclasses and generators. With metaclasses you could e.g. make
    fully automatic class registration, so that each subclass won't
    need a piece of code to register itself. With generators you
    can make itearion over some complex system very simple, such
    as iterating through a directory and all it's subdirectories. In many
    other languages, this has to be done with cumbersome callbacks.

    Then there are the typical things that make Python code smaller,
    like dynamic types (no need for interface classes at all, or explicit
    declaration of types), list comprehensions, blocks indicated by
    indentation and multiple return values. So your whole program ends up
    being easy to express in Python, as compared to C#.
     
    =?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=, Aug 10, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    750
  2. Paul Moore
    Replies:
    0
    Views:
    618
    Paul Moore
    Mar 1, 2008
  3. Martin v. Löwis
    Replies:
    0
    Views:
    658
    Martin v. Löwis
    Mar 1, 2008
  4. Senthil Kumaran
    Replies:
    0
    Views:
    576
    Senthil Kumaran
    Jan 17, 2011
  5. R. David Murray
    Replies:
    0
    Views:
    757
    R. David Murray
    Jan 17, 2011
Loading...

Share This Page