Implicit initialization is EXCELLENT

rantingrick rantingrick at gmail.com
Tue Jul 5 21:53:23 EDT 2011


On Jul 5, 10:26 am, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> This is not strictly Python, although it is peripherally relevant.
>
> Some month or three ago, I read an article or blog post about API design,
> specifically the wrong-headedness of insisting that callers manually
> initialise instances using a separate step after creation.
>
> The argument goes, if your API looks something like this:
>
> instance = Spaminator(extra_truffles=False)
> instance.activate()
> instance.nom_nom_nom()
> => prints "yummy spam, the food of the Gods!!!"
>
> chances are that you are doing it wrong and your users will hate you. Why
> force the user to manually "flip the switch" (so to speak)? It's not like
> they can possibly avoid it:

I completely agree!

> Exceptions to this rule are if the Spaminator has side-effects (e.g. files,
> in which case the user may want finer control in when they are opened and
> closed), or if there are meaningful operations you can perform on an
> inactive Spaminator.

Agreed again!

> It's also relevant to
> tkinter, which will implicitly create a root window for you when needed.

WRONG.
Oh wait,
of course,
you are correct!
YES!
Maybe we should have library modules import only when needed! i mean,
who needs those pesky import statements anyways! Sure it will slow
down run time BUT WHO CARES! My gawd, you just opened my mind to so
many possibilities! Why stop at library modules, if it is not there
just download the source at run time! Guido really dropped the ball on
this one folks.

> Since you can't do anything without a root window, I don't see the benefit
> in forcing the user to do so.

The reason is simple. It's called order. It's called learning from day
one how the order of things exists. Widgets are part of windows, not
the other way around. Saving a few keystrokes is not acceptable if you
jumble the understanding of a new student. To understand and use
Tkinter properly you must understand the order of window->widget.

> When they need to learn about root windows,
> they will in their own good time.

So you would start drivers education class with road construction? Or
the history of the internal combustion engine? Who cares about
actually *driving* the car.



More information about the Python-list mailing list