Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Python vs. C#

Reply
Thread Tools

Re: Python vs. C#

 
 
=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=
Guest
Posts: n/a
 
      08-10-2003
"Brandon J. Van Every" <(E-Mail Removed)> 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#.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 R. David Murray Python 0 01-17-2011 02:23 PM
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 Senthil Kumaran Python 0 01-17-2011 10:31 AM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Martin v. L÷wis Python 0 03-01-2008 10:51 PM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Paul Moore Python 0 03-01-2008 10:39 PM
Searching comp.lang.python/python-list@python.org (was: UTF-8) skip@pobox.com Python 0 03-10-2007 02:50 PM



Advertisments