Search code examples
c#asp.netpythondjangoprogramming-languages

What are some of the core conceptual differences between C# and Python?


I'm new to Python, coming from a C# background and I'm trying to get up to speed. I understand that Python is dynamically typed, whereas C# is strongly-typed. -> see comments. What conceptual obstacles should I watch out for when attempting to learn Python? Are there concepts for which no analog exists in Python? How important is object-oriented analysis?

I believe answers to these and any other questions you might be able to think of would speed up my understanding Python besides the Nike mentality ("just do it")?

A little more context: My company is moving from ASP.NET C# Web Forms to Django. I've gone through the Django tutorial and it was truly great. I need to get up to speed in about 2 weeks time (ridiculous maybe? LOL)

Thank you all for your time and efforts to respond to a realllly broad question(s).


Solution

  • " I understand that Python is dynamically typed, whereas C# is strongly-typed. "

    This is weirdly wrong.

    1. Python is strongly typed. A list or integer or dictionary is always of the given type. The object's type cannot be changed.

    2. Python variables are not strongly typed. Indeed, Python variables are just labels on objects. Variables are not declared; hence the description of Python as "dynamic".

    3. C# is statically typed. The variables are declared to the compiler to be of a specific type. The code is generated based on certain knowledge about the variables use at run-time.

    Python is "interpreted" -- things are done at run-time -- little is assumed. [Technically, the Python source is compiled into byte code and the byte code is interpreted. Some folks think this is an important distinction.]

    C# is compiled -- the compiler generates code based on the declared assumptions.


    What conceptual obstacles should I watch out for when attempting to learn Python?

    None. If you insist that Python should be like something else; or you insist that something else is more intuitive then you've polluted your own thinking with inappropriate concepts.

    No programming language has obstacles. We bring our own obstacles when we impose things on the language.

    Are there concepts for which no analog exists in Python?

    Since Python has object-oriented, procedural and functional elements, you'd be hard-pressed to find something missing from Python.

    How important is object-oriented analysis?

    OO analysis helps all phases of software development -- even if you aren't doing an OO implementation. This is unrelated to Python and should be a separate question.

    I need to get up to speed in about 2 weeks time (ridiculous maybe?)

    Perhaps not. If you start with a fresh, open mind, then Python can be learned in a week or so of diligent work.

    If, on the other hand, you compare and contrast Python with C#, it can take you years to get past your C# bias and learn Python. Don't translate C# to Python. Don't translate Python to C#.

    Don't go to the well with a full bucket.