Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a dynamic language like python give you? Coming from a c#/java background. show me the light! [duplicate]

Possible Duplicate:
What’s with the love of dynamic Languages

I'm coming from a c#/java background i.e. strongly typed, OOP language.

I'm very much interested in Python, but I need to learn a little more about the advantages of a dynamic language.

What power does it really give me? (in web applications).

Can someone outline some of the advantages and cool tricks I can do?

like image 258
Blankman Avatar asked Feb 27 '23 18:02

Blankman


2 Answers

I don't think of dynamically typed languages as "allowing cool tricks" (they do, but mostly it's not really sound to use "cool" tricks in production software -- they come in handy for testing, debugging, etc, but when it comes to getting good, fast stuff deployed for production, simplicity rules).

Rather, I think of such languages as "not getting in my way" -- in particular, not slowing me down by forcing me to redundantly specify things over and over. Not every statically typed languages does "get in your way" -- good ones with solid, logically correct type systems like Haskell let the compiler deduce types (though you may redundantly specify them if you like redundancy... or, more to the point, if you want stricter constraints than what the compiler can actually deduce from the code). But in Java (and to a lesser extent in C# except when you use the reasonably recent var keyword) redundancy is the rule, and that impacts productivity.

A compromise can be offered by third-party checking systems for Python, like typecheck -- I don't use it, myself, but I can see how somebody who really thinks static type checking adds a lot of value might be happy with it. There's even a syntax (which the Python compiler accepts but does nothing with) in recent Python versions to let you annotate your function arguments and return values -- its purpose is to let such packages as typecheck be extended to merge more naturally with the language proper (though I don't think typecheck does yet).

Edit:

As I wrote here, and I quote:

I love the explanations of Van Roy and Haridi, p. 104-106 of their book, though I may or may not agree with their conclusions (which are basically that the intrinsic difference is tiny -- they point to Oz and Alice as interoperable languages without and with static typing, respectively), all the points they make are good. Most importantly, I believe, the way dynamic typing allows real modularity (harder with static typing, since type discipline must be enforced across module boundaries), and "exploratory computing in a computation model that integrates several programming paradigms".

"Dynamic typing is recommended", they conclude, "when programs must be as flexible as possible". I recommend reading the Agile Manifesto to understand why maximal flexibility is crucial in most real-world application programming -- and therefore why, in said real world rather than in the more academic circles Dr. Van Roy and Dr. Hadidi move in, dynamic typing is generally preferable, and not such a tiny issue as they make the difference to be. Still, they at least show more awareness of the issues, in devoting 3 excellent pages of discussion about it, pros and cons, than almost any other book I've seen -- most books have clearly delineated and preformed precedence one way or the other, so the discussion is rarely as balanced as that;).

like image 107
Alex Martelli Avatar answered Mar 01 '23 06:03

Alex Martelli


I enjoyed reading this comparison between Python and Java.

In relation with web, I would recommend doing a simple example with Django to see how it works.

like image 44
Macarse Avatar answered Mar 01 '23 08:03

Macarse