News for hackers. Stuff that matters.
Re:Pattern matching accepted for Python by make3 on Tuesday February 09, 2021 @04:25PM (#26082558)
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.
Re:Pattern matching accepted for Python by pmart123 on Tuesday February 09, 2021 @04:38PM (#26082675)
I agree with this up through Python 3.7. The recent updates though seem to be unnecessary or have obtuse syntax.
Re:Pattern matching accepted for Python by make3 on Thursday February 11, 2021 @12:08AM (#26098442)
do 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
Re:Pattern matching accepted for Python by enriquto on Tuesday February 09, 2021 @05:41PM (#26083440)
What's the problem with nested comprehensions? How else do you create bi-dimensional stuff?
Re:Pattern matching accepted for Python by magnusmundus on Tuesday February 09, 2021 @06:11PM (#26083771)
Not 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]
Re:Pattern matching accepted for Python by joshuamorton on Tuesday February 09, 2021 @06:41PM (#26084055)
Fwiw, 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.
Re:Pattern matching accepted for Python by cat199 on Tuesday February 09, 2021 @11:21PM (#26085724)
nice trick.. though if you are relying on the 'generator' aspect of comprehensions this may be problematic (will create in-memory copies)
Re:Pattern matching accepted for Python by cjohnson318 on Tuesday February 09, 2021 @05:18PM (#26083148)
Yes, 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.