Is there a need for a “use strict” Python compiler?

后端 未结 10 2355
眼角桃花
眼角桃花 2021-02-03 21:26

There exist static analysis tools for Python, but compile time checks tend to be diametrically opposed to the run-time binding philosophy that Python embraces. It\'s possibl

10条回答
  •  长情又很酷
    2021-02-03 22:22

    I think there's some confusion as the what "use strict" does, from the comments I'm seeing. It does not turn on compile time type checks (to be like Java). In that sense, Perl progammers are in agreement with python programmers. As S.Lott says above these types of checks don't protect against logic bugs, don't reduce the number of unit tests you need to write and we're also not big fans of bondage programming.

    Here's a list of what "use strict" does do:

    1. Using symbolic references is a run-time error. This prevents you from doing crazy (but sometimes useful things like)

      $var = 'foo';

      $foo = 'bar';

      print $$var; # this would contain the contents of $foo unless run under strict

    2. Using undeclared variables is a run-time error (this means you need to use "my", "our" or "local" to declare your variable's scope before using it.

    3. All barewords are considered compile-time syntax errors. Barewords are words that have not been declared as symbols or subroutines. This is mainly to outlaw something that was historically done but is considered to have been a mistake.

提交回复
热议问题