Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107540

Re: How much sanity checking is required for function inputs?

From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: How much sanity checking is required for function inputs?
Date 2016-04-24 06:40 +0000
Message-ID <mailman.30.1461480050.32212.python-list@python.org> (permalink)
References (10 earlier) <571C2541.9050309@icloud.com> <571C30C8.5000208@gmail.com> <mailman.24.1461465315.32212.python-list@python.org> <571c5e72$0$1615$c3e8da3$5496439d@news.astraweb.com> <CAGgTfkOXzfdASq7h4+0n3wokpmQmTREZ7Kzd_Qbog-hZ5HM7MA@mail.gmail.com>

Show all headers | View raw


On Sun, Apr 24, 2016, 1:51 AM Steven D'Aprano <steve@pearwood.info> wrote:

> On Sun, 24 Apr 2016 12:34 pm, Michael Torrie wrote:
>
> > There are many aspects to Pythonic programming, not just OOP.  For
> > example using modules to store shared state for your program components
> > is very pythonic, rather than using classes.  A module is kind of like a
> > singleton instance, and still is object-oriented by the way (the module
> > is an object).
>
> I find myself going backwards and forwards on whether or not that is a good
> idea. I think it depends on whether you are writing a library or an
> application.
>
> If you're writing an application, then storing state in module-level
> variables works fine. Your application is, effectively, a singleton, and if
> you try to run it twice, you'll (probably) be running it in two distinct
> processes, so that's okay.
>
> (If you're not, if somehow you perform some sort of trickery where you have
> a single Python interpreter running your script twice in the same process,
> then it will break horribly. But if you can do that, you're living on the
> edge already and can probably deal with it.)
>
> But if you're writing a library, then using module state is a Bad Idea.
> Your
> library may be used by more than one client in the same process, and they
> will conflict over each other's library-level state. "Global variables
> considered harmful."
>

I think we're giving mixed messages because we're conflating "constants"
and globals that are expected to change.

In our case here, I think two clients in the same process sharing state
might be a feature rather than a bug. Or at least it has the same behavior
as the current implementation.

>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: How much sanity checking is required for function inputs? Michael Torrie <torriem@gmail.com> - 2016-04-23 20:34 -0600
  Re: How much sanity checking is required for function inputs? Steven D'Aprano <steve@pearwood.info> - 2016-04-24 15:49 +1000
    Re: How much sanity checking is required for function inputs? Michael Selik <michael.selik@gmail.com> - 2016-04-24 06:40 +0000
      Re: How much sanity checking is required for function inputs? Steven D'Aprano <steve@pearwood.info> - 2016-04-25 04:00 +1000
        Re: How much sanity checking is required for function inputs? Michael Selik <michael.selik@gmail.com> - 2016-04-25 01:02 +0000

csiph-web