3 ms·
> This is how Python has always been. Nah, idiomatic Python always used to prefer comprehensions over explicit loops. This is just the `match` statement making
by pansa2 2y ago
> This is how Python has always been.
Nah, idiomatic Python always used to prefer comprehensions over explicit loops. This is just the `match` statement making code 3x longer than it needs to be.
- the-grump 2y agoYou can express the loop as a list comprehension, and I would too. As for the logic, I would still use pattern matching for branching and destructuring, but I’d put it in a helper. More lines is not a negative in my book, though I admit the thing with convert and format is weird.
- pansa2 2y ago> I would still use pattern matching for branching and destructing, but I’d put it in a helper Yeah, using a helper function makes things much clearer. To be honest though, I'm not a huge fan of using either `isinstance` (which is generally a sign of a bad design) nor `match/case` (which is essentially a "modern" way to write `isinstance`). I can't help but think that a better design could avoid the need for either of those (e.g. via polymorphism).
- the-grump 2y agoWhat I would use is an ADT and I make a wish for that every day in every language that’s not Haskell :D Haskell also has operator overloading on steroids so you could use the (|>) operator from Flow and write transformations the same as you would shell pipes. I’d love to whip up an example but it’s difficult on this tiny screen. Will try to remember when I’m on my computer. Before someone chimes in with ML propaganda, I warn you that I’m going to exercise my rights under the Castle Doctorine the moment you say “of”.
- davepeck 2y agoYou can access .strings and .interpolations directly and avoid type checks. There is always one more string than interpolation, of which there may be zero.
- zahlman 2y ago> As for the logic, I would still use pattern matching for branching and destructuring, but I’d put it in a helper. I wrote it up (https://news.ycombinator.com/item?id=43650001 https://news.ycombinator.com/item?id=43650001) before reading your comment :)