4 ms·
This is so ugly, especially the C-like parens. I wish they had gone with the pythonic as syntax: if rawdata.count("\n", i, j) as nlines: self.lineno =
by akvadrako 8y ago
This is so ugly, especially the C-like parens. I wish they had gone with the pythonic as syntax:
if rawdata.count("\n", i, j) as nlines:
self.lineno = self.lineno + nlines
...
- mehrdadn 8y agoI agree this one is very elegant, but the downside is that you'll still need the parens if you use it as a subexpression, which you most likely will if you want to distinguish between, say, 0 and None.
- raverbashing 8y agoUsing 'as' is prettier, but a pain to read, as your eyes have to go all the way to the end of the line You can still use the old way if you think this new one is ugly, but to be honest I think it's going to be an improvement.
- wodenokoto 8y agoI don't understan what you mean that you have to "go all the way to the end". with if my_data := my_function(): do_stuff(my_data) the left-hand side of the assignment is completely irrelevant to the if statement. Here you have to go "all the way to the end" just to see what that clause of the if-statement is. With the as-syntax, the if-statement and the clause are placed together. However, I do find the if-as sentence kinda weird, when trying to understand it using normal english.
- mehrdadn 8y ago> the left-hand side of the assignment is completely irrelevant to the if statement I guess is subjective? To me, that's the first thing I want to know about an assignment -- what is being assigned to? Especially if you try to keep your programs reasonably functional, then it's in fact the thing that matters, since the right-hand side would be side-effect-free. Another way I see it is that an assignment expression is like solving a problem: first you'd ask "what did they solve for?", then you ask "how did they solve for it?" -- not the other way around.
- raverbashing 8y agoJust go back to the original example > if rawdata.count("\n", i, j) as nlines: I have to read the beginning of the line, then jump to find the as (which is not very obvious in the expression) then find the var name. > if nlines := rawdata.count("\n", i, j): Here I do a continual motion from the beginning of the line up to the start of the condition > the left-hand side of the assignment is completely irrelevant to the if statement It is relevant to the subsequent block of code, I need to know what 'nlines' mean.
- conaclos 8y agoI agree. This makes me think about the elegant "attached as" syntax [1] of Eiffel: if attached rawdata.count("\n", i, j) as nlines then .... [1] https://www.eiffel.org/doc/eiffel/Void-safety%3A%20Background%2C%20definition%2C%20and%20tools https://www.eiffel.org/doc/eiffel/Void-safety%3A%20Backgroun...
- 1wd 8y agoThe parentheses are actually not required: https://mail.python.org/pipermail/python-dev/2018-July/154335.html https://mail.python.org/pipermail/python-dev/2018-July/15433... Why not "as" syntax: https://mail.python.org/pipermail/python-dev/2018-July/154333.html https://mail.python.org/pipermail/python-dev/2018-July/15433... (I'm just pointing to the given explanations for the interested. I'm not necessarily agreeing with them.)