Re: Time to relax some restrictions on the walrus operator?

On Sun, May 08, 2022 at 04:00:47PM +0100, Rob Cliffe wrote:
Yes, I know unrestricted use of the walrus can lead to obfuscated code (and some of Steven's examples below might be cited as instances 😁).
They're intended as the simplest, least obfuscatory examples of using the walrus operator that is not pointless. That is, an example of the walrus as a sub-expression embedded inside another expression. If you think my examples are obfuscated, then that is an argument in favour of keeping the status quo. I could have given an example like this: ((a, b) := [1, 2]) but there is no good reason to use the walrus operator there, it is not a sub-expression, and it Just Works if you use the assignment statement instead. -- Steve

I have not personally ever used the walrus operator, and I don't think I've even seen it used in the wild, either. That's not a commentary on how useful it is, but that it takes time for changes like this (that can't be back-ported) to get much real world use. So no, I don't think it's time to relax the restrictions -- for the same reason the restrictions were there in the first place. - CHB On Sun, May 8, 2022 at 9:40 AM Steven D'Aprano <steve@pearwood.info> wrote:
-- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython

I'm sorry Steven, I didn't mean to denigrate your examples. Please note that I said I was in favour of relaxing the restrictions on the walrus operator. I guess I just meant that using the walrus operator generally adds extra complexity to code and means that more effort is required to read and understand it. Or, at least, its use often results in fewer lines of code (whether or not that was the primary motive) which means that particular lines of code become more complicated and harder to understand. I try (so far fairly successfully I think 😁) to resist the temptation to use the walrus operator just to save a line of code. (Isn't it "Pythonic" to do one thing and one thing only on each line of code? I'm sure I read that somewhere.) I try to only use the walrus when performance matters and I think (or know, from testing) that it will improve performance by avoiding re-evaluating an expression. Or, possibly, when there is some other compelling reason (sorry, can't think of an example offhand). Best wishes Rob Cliffe On 08/05/2022 17:38, Steven D'Aprano wrote:

I have not personally ever used the walrus operator, and I don't think I've even seen it used in the wild, either. That's not a commentary on how useful it is, but that it takes time for changes like this (that can't be back-ported) to get much real world use. So no, I don't think it's time to relax the restrictions -- for the same reason the restrictions were there in the first place. - CHB On Sun, May 8, 2022 at 9:40 AM Steven D'Aprano <steve@pearwood.info> wrote:
-- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython

I'm sorry Steven, I didn't mean to denigrate your examples. Please note that I said I was in favour of relaxing the restrictions on the walrus operator. I guess I just meant that using the walrus operator generally adds extra complexity to code and means that more effort is required to read and understand it. Or, at least, its use often results in fewer lines of code (whether or not that was the primary motive) which means that particular lines of code become more complicated and harder to understand. I try (so far fairly successfully I think 😁) to resist the temptation to use the walrus operator just to save a line of code. (Isn't it "Pythonic" to do one thing and one thing only on each line of code? I'm sure I read that somewhere.) I try to only use the walrus when performance matters and I think (or know, from testing) that it will improve performance by avoiding re-evaluating an expression. Or, possibly, when there is some other compelling reason (sorry, can't think of an example offhand). Best wishes Rob Cliffe On 08/05/2022 17:38, Steven D'Aprano wrote:
participants (3)
-
Christopher Barker
-
Rob Cliffe
-
Steven D'Aprano