The depressing state of dynamic languages
时间:2009-04-06 来源:cobrawgl
One must understand that dynamic scripting languages were made for one thing: writing small applications (small scripts, small websites). Performance and maintainability isn't a big issue for small scripts / small applications - hence, most of the scripting languages perform REALLY bad and maintainability is really hard.
Anyhow, the core problem of dynamic languages is brain dead compilers - - actually, most of them don't have a compiler at all, they let everything be evaluated and checked at runtime. Currently a lot of work is being done in improving performance, but one thing that's forgotten is doing any forms for sanity checks that can help a programmer. Imagine if a Python compiler could check simple things like function signatures at compile time or even just making sure that you don't spell a functions name wrongly (i.e. check that a function is actually defined in the current environment).
An example: In Python (or any other "dynamic" languages) you can write following unsound code (at least this is unsound if you haven't done any "magic" to the environment):
def blah(): calling_a_magic_function() import not_found_module not_found_dict['not_found'] = "NOT FOUND!"
The above program will run without any problems - there aren't any sanity checks and you can't tell the compiler to "turn on sanity checking". If you do small scripts then this isn't an issue, but if you are doing a big application with lots of modules and lots of code, then changes are very hard to do since the compiler does not give any form for help.
I have built simple custom tools on top of pyflakes to check for simple things such as calling a function that isn't defined or imported. But I wish that Python could do these checks for me, so if I used a module that wasn't defined it would throw an error before running the actual code. Check out my post Static checking Python code for more info.
Anyhow, having coded in Java I think the real strengths of Java is the JVM and an amazing compiler that can spot tons of errors at compile time (such as calling a method with invalid parameters). Of course, such checking is much harder to do in Python (or other "dynamic" languages) - - that said, it's not impossible and the worst thing the compiler can do is to ignore static checking and let the runtime system handle everything.
Anyhow, my hope is that not only performance improves for dynamic languages, but also static checking for stupid errors.