免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1884 | 回复: 0
打印 上一主题 下一主题

The depressing state of dynamic languages [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-06 16:00 |只看该作者 |倒序浏览

I love to code in Python and JavaScript and I have coded in them for some years now. The unfortunate thing is that their current state is depressing for writing bigger applications. This is unfortunately true for most dynamic languages such as PHP, Ruby or Perl.
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.


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/78/showart_1891288.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP