5 ms·
I think this comment is super exaggerated. In my experience pretty much all features in Python 3 by far are really welcome. The only features you're usually not
by make3 6y ago
I think this comment is super exaggerated. In my experience pretty much all features in Python 3 by far are really welcome. The only features you're usually not supposed to use are very obvious ones, inspect, metaclasses and nested comprehensions, which are super uncommon and feel like dark magic that you would obviously not want to use, or just shit ugly code in the case of nested comprehensions.
- pmart123 6y agoI agree with this up through Python 3.7. The recent updates though seem to be unnecessary or have obtuse syntax.
- make3 6y agodo you have specific examples? honestly I was against the walrus operator but having played with it for just two seconds I think it's really great and that people are making a bigger deal than needed about this
- cjohnson318 6y agoYes, I think the general consensus on metaclasses is that if you don't already know what they are, then you probably don't need to use them. There's some metaclasses in Django, but it's pretty easy to see how you're expected to use them from examples, and you don't need to really understand what's going on.
- enriquto 6y agoWhat's the problem with nested comprehensions? How else do you create bi-dimensional stuff?
- magnusmundus 6y agoNot the same kind of nesting, is it? [[None for _y in range(y)] for _x in range(x)] for two dimensions is fine, while [None for _x in range(x) for _y in range(y)] (to create a flattened 2-dim list? excuse the dummy example) is just begging for later headache. Explicit looping is much more readable. Note the flipped order of expressions -- these two statements create the same iterators. Not to mention, you can even reuse the name for extra evil: [i for i in range(2) for i in range(3)] results in [0, 1, 2, 0, 1, 2]
- joshuamorton 6y agoFwiw, I find creating a 2d array and then flattening (`itertools.chain.from_iterable([[None for _y in range(y)] for _x in range(x)])` to be both readable and reasonably concise, though yes explicit loops are also fine.
- cat199 6y agonice trick.. though if you are relying on the 'generator' aspect of comprehensions this may be problematic (will create in-memory copies)