5 ms·
I have problem with both new checkers: regarding the `consider-ternary-expression` if condition(): x = 4 else: x = 5 allow me to put fc
by _ZeD_ 5y ago
I have problem with both new checkers:
regarding the `consider-ternary-expression`
if condition():
x = 4
else:
x = 5
allow me to put fck'n breakpoints - in this case the expression is dumb, but what if is some complex stuff?
x = 4 if condition() else 5
is cute, but - remember, kids - not everything* should be an expression
regarding the `while-used`, while I personally prefer the legibility of the `for` loop, I find the following paragraph... at best wrong:
>>> A while loop introduces unbounded computation. Do you really need unbounded computation for your boring web app? I doubt it. In almost all cases, the loop can be bounded in advance, as in “do this N times” or “do this for every item in this list”. Those kinds of loops are guaranteed to terminate, and that’s a nice guarantee to have.
in python `for` loop are equally unbounded as `while` ones. Yes, most of the time you are looping over a (finite) list or a (finite) dict, but the concept underlying the `for` loop is the iterator, not the list. And iterators can easily be infinite.
- ghgr 5y ago> in python `for` loop are equally unbounded as `while` ones. Yes, most of the time you are looping over a (finite) list or a (finite) dict, but the concept underlying the `for` loop is the iterator, not the list. And iterators can easily be infinite. Not only iterators, but also plain lists. Example: a=[1] for i in a: a.append("the ride never ends") print(i)
- deleted 5y ago[deleted]
- klyrs 5y agoDid you try that out in a REPL before posting? You should.
- shhsshs 5y agoI'm guessing he did, because it does exactly what he's implying it does.
- klyrs 5y agowow, my bad. That's sets & dicts that invalidate their iterators when the size changes.
- marcosdumay 5y agoIterating over mutable unordered containers is an entire new level of crazy.
- klyrs 5y agoThat's what linters are for, right? To make your code more fun to read