On 13May2018 00:51, MRAB <pyt...@mrabarnett.plus.com> wrote:
On 2018-05-12 22:07, Cameron Simpson wrote:
On 06May2018 02:00, Nick Coghlan <ncogh...@gmail.com> wrote:
Similar to import statements, optional parentheses could be included in the
grammar, allowing the name bindings to be split across multiple lines:

  if diff and g > 1 given (
      diff = x - x_base,
      g = gcd(diff, n),
  ):
      return g

I'm well behind, but... this! This turns "given" into a +0.8 for me.

That's really nice. It reads clearly too.

That's longer than this:

diff = x - x_base
g = gcd(diff, n)
if diff and g > 1:
   return g

which is already valid.

Yes, but in a slightly larger scope such as a cascaded if/elif/.../else sequence embedding the "given" into the expression has 2 advantages: it stops the if-else cascading across the terminal purely to embed assignments before the next test, and it lets one clearly associate these particular assignments as relevant to the test itself.

Obviously there are circumstances for each, and I expect overuse of "given" degrades readability. However, I still find Nick's "if this given that" formulation quite compelling as a logical form.

Cheers,
Cameron Simpson <c...@cskk.id.au>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to