Python vs C#, Dynamic vs Managed Compiled

2008年1月24日

Python vs C#, Dynamic vs Managed Compiled

Python is a dynamic language, and C# is a managed compiled language.  Lets see their common points and differences.

Feature

C#

Python

Notes

Array boundary check

Yes

Yes

Garbage collection

Yes

Yes

C# uses an industrial-standard 3-generation compacting GC; Python uses reference counting and a tree traversing GC.

Wild pointers

No

No

Since GC is used, no wild pointer is possible.

Strongly typed

Yes

Yes

C# is statically typed and also has run-time type checking, so type checking is done both at compile time as explicit type declarations and at run-time when doing type-casting.  Python is dynamically typed, so no type-checking is done at compile time.  All type checking is done at run-time, including whether the object has a function of a specific name that is called at run-time.  This brings difficulty to debugging the python program, though.

Dynamic classes, functions, objects

Partly

Yes

C# can dynamically load classes in a DLL using reflection; Python inherently has dynamic classes, that is, classes as objects [ce1].

Interfaces

Yes

Yes

C# requires explicit interface definition and implementation.  Since Python is dynamically typed, interfaces are automatically supported.  As long as functions of the same name exist in required classes, the calling code works.

Generics

Yes (in 2.0)

Yes

Generics in C# requires explicit definition.  Python is dynamically typed so generics are automatically supported.  A class or a function can operate on objects of any types that fit.

Templates

No

No

Templates are not supported in Python.  In C#, the only thing that resembles templates is its generics on fundamental types.  The resemblance is in execution efficiency, rather than in syntax and semantics.

Initial memory consumption

8MB (1.0) or 16MB(2.0)

4MB(2.5)

The actual amount of memory in use may be lower.  However this affects the system performance if the amount of free memory is tight.

Built-in fixed-size arrays

Yes

Yes

Built-in array lists

No

Yes

This is something that made Python look weird, but is also a thing that made Python very easy-to-use [ce2].

Built-in slicing

No

Yes

This is something that made Python interesting and easy-to-use [ce2].

Built-in hashtables

No

Yes

This is something that made Python look a little bit weird, but is also a thing that made Python very easy-to-use [ce3].

[ce1]
python:

class A(object):
    def __init__(self):
        print("A.__init__()")

# let B represent class A
B = A
# create a class A object
a = B()
# print the name of class A
print(B.__name__)

[ce2]
python:

list = []
list.append("a")
list.append("b")
list += ["c", "d", "e", "f"]
# now `list’ contains "a" to "f"
# print ["c", "d"]
print(list[2:4])
# print "f"
print(list[-1])
# print ["f"]
print(list[-1:])
# print ["e", "f"]
print(list[-2:])

[ce3]

dict = {}
dict["Mary"] = "Little Lamb"
dict["Sam"] = "A House In Seattle"
dict["Michael"] = "Cooperated with the rabbit"
dict["Cougar"] = "Was the No. 1"
dict["Maverick"] = "Is the No. 1"
del dict["Mary"]

“Python vs C#, Dynamic vs Managed Compiled” 已有 6 条评论

  1. Lincoln 在

    So, can you make the conclusion that Python>C#?

  2. Robbie Mosaic 在

    nge. For small programs, Python > C#. For large programs, C# > Python.

  3. Unknown 在

    Welcome to enter (wow gold) and (wow power leveling) trading site, (wow gold) are cheap, (wow power leveling) credibility Very good! Quickly into the next single! Key words directly to the website click on transactions! -282713768874313

  4. Unknown 在

    Hi,Do you need ad players, advertisement player and LCD advertisings? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
    amberdigital Contact Us

    E-mail:sstar@netvigator.com
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[dhbiggigdaaehi]

  5. Unknown 在

    Wan Moshou game, to (wow power leveling) site to buy the cheapest gold coins! To (wow gold) for the best Dailian upgrade!

  6. Unknown 在

    Hi,Do you need advertising displays, digital signages, advertising player and LCD displays? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
    amberdigital Contact Us
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[cjcdieaecbacgeh]

留下您的评论