+6 votes
by
In the process of learning Python, I ask this question what are its advantage it before C, as dynamic. I mean, is it just that it is not necessary to declare the type of variables? I understand that Python was never intended as a fast language, but declaring variables is not such a big job for the programmer in order for this to reduce the speed of the program. And so, the question is how big the difference in speed in this regard.

9 Answers

0 votes
by
 
Best answer
The advantage of dynamically typed languages, of course, not in syntax but in semantics.

By defining types during program execution strongly facilitates metaprogramming. Very much easier. It, in turn, simplifies the rest of the work.

Thanks to the flexibility of the code in runtime (see duck typing) and introspection (analysis of the properties of objects and code) can be obtained much easier and faster to write generic algorithms and design like interior decorators, all sorts of ORM and things like that. This greatly simplifies the interfaces of the libraries, which together leads to more simple code and a smooth learning curve to newcomers.

From my experience (5 years of writing C++, then the same in Python, these terms overlap a bit) I can say that from the point of view of errors of typing (and actually put them in the disadvantage of dynamically typed languages), the difference is minimal — they are very rare and all are caught with automatic tests. Of course, if you have hands grow from where it should be, and if not from where it should be, these errors are not the biggest problem. Therefore, in the field of software development, not performance-sensitive, such languages rule.

The advantage of statically typed languages is that imposing additional restrictions on the programmer and the code flexible, they allow the compiler to obtain additional information about the program and to make more specific operations. However, now used almost everywhere JIT and it partially neutralizes the difference in performance.

In the end we get the classic dilemma: raising the level of abstraction against the increase in the level of specialization. Each way has its pros and cons.

The performance of the Python references already inserted, but in any case, here we must proceed from the requirements of a particular task — easier to take and test yourself.
+3 votes
by
Python - this is C. This is a simple interface written in C/C++ libraries.

But Python is strong not that. Python is powerful due to its Zen. Where else will you be able to write Web, Desktop, Android (and eventually iOS and WinPhone) applications on your choice, knowing one language? Or, for example, pokodit for CUDA?

Speed nothing faster, there is nothing to guess, all sorts of Java/Go approach and declare before that on some tests they are "at least as good", but... here's a five year old topic habrahabr.ru/post/90942
and that's what became a reality just last year: speed.pypy.org and this is also the Zen of Python

With regard to "declare the type of variables", you are confusing concepts, take a look habrahabr.ru/post/161205
in Python very quickly run into manifestations of strong typing (read from the WEB without decode(), for example), and it is unclear who (Python or C) there is more LAMER
by
knowing C# all of the above can be done
by
mono
by
and Linux how to be?
by
lamazavr : Why?

Moreover, this mono will always lag.
by
AVKor Given that now support came from MS, it is likely that you will catch up soon.
by
AxisPod : Support mono on Linux?

The first time I hear it.
+1 vote
by
I mean, is it just that it is not necessary to declare the type of variables

The type of the variables (primitives) possible to specify, it is not difficult. It is much harder to specify the type of objects. You may not know what kind of object should work. In Python I need to know that an object has a certain method or field (but you can not know). In a static language the compiler itself me wouldn't leave me alone until I did not specify the type of the object. For that, I'd have to make sure that all objects inherit from one base class (which is not always possible), or I'd have to allocate the interface implementarea all possible objects of a given interface. There would be a situation where I had to invent how to make so that you do not explicitly specify the type, but the compiler missed. Well, where my colleagues on C# I write all sorts of dependency injection, visitor, overload methods, wrapped around some kind of abstraction, introduce interfaces, my Python just checks whether a property using hasattr(), or know the type using type(). So, the power of Python to introspection and reflection.
0 votes
by
The difference in speed can be found here: benchmarksgame.alioth.debian.org/u64q/compare.php?... but I don't think the problem is dynamic typing, but rather the fact that Python is not compiled in native code.
+1 vote
by
Everything seems to confuse "dynamic typing in YAP" and "YAP interpreted".

So let it be 2 types of question:
1. "Dynamic typing better than static and why?"
2. "An interpreted compiled language is better and why?".

1. Today, when the spectrum is to be solved on a computer task is very broad, the way of typing depends on the details.

2. Today, when the line between interpreters and compilers when the opcodes of the processor and interpreter are the same, the choice of YAP depends on the details.
+1 vote
by
In dynamic languages write where their speed is sufficient - sites, etc., simple desktop-ADM. scripts, etc.
In static languages you write only if you need a high-speed operation of the program.
by
iegor : Computer turns machine code. Compiled languages the output is converted into machine code, and interpreted not generate native code - instead, the program executes the interpreter, written in C/C++, in command. Because of this, there is a difference in working speed to 100 and 1000 and more times. But for simple tasks at low loads, this difference is not noticeable. Can try to write something simple in python and C. Visually the difference in speed probably won't notice.
But the python code will be less.
by
asd111 in compiled languages there is no interpreter? i.e. the compiler makes machine code and let the processor and interpreted by each team alternately converted into machine code? the question may seem stupid as is, but this is due to the lack of necessary education.
by
asd111 : thx
by
iegor mainly because the definition of code addresses challenges and read/write of data is performed at run time, not compile time (which itself may not be). Read about early and late binding.
by
iegor : Yes, the compiler makes machine code which can be directly run on the processor, and the interpreter executes each command separately - can he compile and make the machine code - this interpreter is called a JIT compiler(although it is an interpreter, meaning that it is the interpreter which can make the native code when necessary) is just the interpreter - look what came to the team and runs the machine code, namely the recognition of commands and the further you run the command, it takes a lot of time interpreters, so they are slower
by
Ie, do I understand correctly that in these cases there is a cost savings to the developer (code in C to write longer) by increasing the cost of iron (code in Python requires a lot of resources)? And do not tell by what happens such a strong drawdown for speed in dynamic languages
+2 votes
by
Dynamic faster to sculpt the prototype, but the harder it is to continue to support.
Take a look here: dlang.ru/why-d-is-better
by
Under the "difficult to maintain" mean that there may not be enough speed in the future?
by
iegor : this is more difficult that you can stick too incomprehensible code with changing time typing.
+3 votes
by
In many, even in most problems, where the bottleneck is not the performance of the interpreter/runtime of language, the main advantage is dynamic languages you can write those programmers who are unable to static. Not in the sense can't learn, or don't understand, and I mean - absolutely do not want. It's something deep in the mind of the programmer, depending on his choice of dynamic/static typing (and resp. language). I'm more and more convinced that, depending on the variant typing, programmers that chose the "right" language, you write much more effective code.
I as the developer of Yandex (via the link in the answer beduin01 ) too bad memory to develop in a dynamic language. I can't keep a lot of entities in my head to effectively and correctly use dynamic languages. I am used to and can not without any checks at compile time (and the more the better).
Others believe the limitations of static typing is stupid, the need to create any weird "interfaces," to fuck the abstraction and polymorphic behavior - perversion. They feel easy with objects and classes. The ability to add any property or method to an existing object inspires them to innovative and effective architectural and infrastructural solutions.
Apparently it really depends on the peculiarities of memory and consciousness of a particular person.

Of course, there are many technical differences, read the rest of the answers.
0 votes
by
As for me, the advantage of interpreted before C that's what (js, Python I do not know):

var obj = {
a: 10,
b: "Hello",
c: true,
d: {
e: {
f: 10000
}
}
}

obj.a = "user";
obj.b += " world";
obj.b.x = obj.d.e.f;
obj.b.x++;
console.log(obj.b, obj);
Sobsno written program is very fast compared to si, and the code is shorter and simpler.
...