[Python-ideas] globals should accept parenteses for extending beyond 1 line

Chris Angelico rosuav at gmail.com
Mon Jan 23 15:24:53 EST 2017


On Tue, Jan 24, 2017 at 6:37 AM, João Matos <jcrmatos at gmail.com> wrote:
> One does not need to have 10 global vars. It may have to do with var name
> length and the 79 max line length.
>
> This is an example from my one of my programs:
> global existing_graph, expected_duration_in_sec, file_size, \
>     file_mtime, no_change_counter
>

I think you're already running into serious design concerns here. Why
are file_size and file_mtime global? Perhaps a better design would
involve a class, where this function would become a method, and those
globals become "self.file_size" and "self.file_mtime". Then you can
have a single global instance of that class for now, but if ever you
need two of them, it's trivially easy. You encapsulate all of this
global state into a coherent package.

But if you MUST use globals, I would split the lines according to purpose:

global existing_graph, expected_duration # "in_sec" is unnecessary
global file_size, file_mtime
global no_change_counter # also probably needs a new name

That way, you're unlikely to run into the 80-char limit.

ChrisA


More information about the Python-ideas mailing list