Chinaunix首页 | 论坛 | 博客
  • 博客访问: 592683
  • 博文数量: 207
  • 博客积分: 10128
  • 博客等级: 上将
  • 技术积分: 2440
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-10 21:40
文章分类

全部博文(207)

文章存档

2009年(200)

2008年(7)

我的朋友

分类: Python/Ruby

2009-04-06 16:00:08

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 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.

阅读(665) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~