[Python-ideas] start, test, init

spir denis.spir at gmail.com
Sun Dec 1 15:13:14 CET 2013


On 12/01/2013 02:49 PM, Andrew Barnert wrote:
> 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.

Well, from the initial post:
	"however, the proposal does not force anyone to follow such a style"

Nothing prevents you to write hello-world the usual way. Nothing prevents using 
Python as a calculator, neither, nore as a programmer-friendly Bash; however, 
for the latter case, i'd still use 'test' and 'start'. Instead, it is a 
structural addition to the language; a backward compatible one if ever special 
names, like '__test__', are used rather than my preferred ones, like 'test'.

The last point of your post (saving a func call) has nothing to do with the 
proposal or its spirit. It is about code clarity and high-level structuration, 
replacing "if __name=='__main__'", allowing code flow logics to be all cleanly 
placed in funcs, such things...
(did you reply too fast, maybe?)

denis


More information about the Python-ideas mailing list