4 ms·
I 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 s
by wodenokoto 8y ago
I 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.