On Sun, Dec 04, 2022 at 01:34:13PM -0800, Bruce Leban wrote:

>  I agree with most criticism of this proposal, although I'll note that 
> the one place where I'd like something like this is at top level. I 
> often write something like this at top level:
> 
> __part1 = (some calculation)
> __part2 = (some other calculation)
> THING = combine(__part1, __part2)
> __part1 = __part2 = None

A couple of stylistic points...


* I don't know if you have a personal naming convention for double 
  leading underscore names, but to Python and the rest of the community,
  they have no special meaning except inside a class. So you might want 
  to save your typing and just use a single leading underscore for
  private names.

* You probably don't want to assign the left over private names 
  `__part1` and `__part2` to None. Yes, that frees the references to the 
  objects they are bound to, but it still leaves the names floating 
  around in your globals.

Instead, use `del`, which explicitly removes the names from the current 
namespace, and allows the objects to be garbage collected:

_part1 = (some calculation)
_part2 = (some other calculation)
THING = combine(_part1, _part2)
del _part1, _part2

In which case I'm not sure I would even bother with the leading 
underscores.


> If they are large objects and I forget to explictly delete the 
> references, then they won't be garbage collected.

Very true. And when you do forget, what are the consequences? I daresay 
that your program still runs, and there are no observable consequences.

> Looking at all these options, is the cost of adding anything actually 
> worth the benefit? Probably not.

Agreed.

Given how rare it is for this sort of thing to actually matter, I think 
that the correct solution is "remember to del the variable when you are 
done" not "let's complicate the language".


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2ATDFK2JB6UGGEOCQXRP3CG7M5AA3CW3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to