[Python-ideas] start, test, init

Andrew Barnert abarnert at yahoo.com
Sun Dec 1 14:49:58 CET 2013


On Dec 1, 2013, at 4:45, spir <denis.spir at gmail.com> wrote:

> Every module using such functions is then a set of definitions: assignments, def's, classes, plus imports and such. Possibly 1, 2, 3 of them are language-defined main functions. Very clean...
> 
> The execution logics would be:
> * if imported module:
>    ~ run init if any
>    ~ else, run nothing
> * if executed module:
>    ~ run test, if any (see below)
>    ~ else, run start, if any
>    ~ else, run nothing (error?)
> 
> What do you think?

I assume you realize that function and class definitions, assignments, etc. are code, and there is no separate execution phase for defining code vs. running code in Python.

So, are you proposing that top-level code only be allowed to run some subset of the language, or that it just be encouraged to do so as a convention?

Meanwhile, your proposal to make hello world a two-liner instead of a one-liner may not seem that big a deal, but it means that every novice has to learn how to define functions before they can write their first program. And it means that everyone who wants to use Python as an admin/scripting language in place of perl or awk or whatever has to write that extra line of code, making Python less usable. And so on.

And meanwhile, in realistic large programs, you're already going to define and call the function anyway, so you're only saving the call. I don't think saving 1 line in 100-line scripts is worth adding 1 line to 1-line scripts.


More information about the Python-ideas mailing list