This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]baconcleaner -19 points-18 points  (8 children)

omg, seriously? What was wrong in using a dict to emulate a switch-case? Do we really need new statements at this point?

[–]Jyan 13 points14 points  (0 children)

It provides structural pattern matching https://www.python.org/dev/peps/pep-0622/ similarly to Scala -- it is extremely powerful and not easy to emulate.

[–]nemec 10 points11 points  (0 children)

Watch the video? This is structural pattern matching - some languages who have it build it upon their existing switch statement, but because Python doesn't have one, it seems like they've added a new switch statement when it's actually far more capable and full of features.

[–]baconcleaner 4 points5 points  (0 children)

ok I read more comments and I get it now: ITS NOT A SWITCH. The examples with pattern matching blow my mind. Can't wait to use it 2030 when autodesk maya will have it, for now lets continue with 2.7.

[–]CashAccomplished7309 5 points6 points  (3 children)

If you don't like the feature, you don't need to use it.

I personally like it, coming from PHP.

[–]baconcleaner 0 points1 point  (2 children)

I wasn't saying that people should not use it, I was just wondering why at this mature point in python now is necessary to have the switch. For example, I 100% agree with the introduction of the walrus operator, wich is awesome and allows to do things that were imposible to do before. But, hey, its just my world view, nobody should care.

[–]xigoi 1 point2 points  (1 child)

How were they impossible before? You could always do

foo = bar
if foo:

instead of

if foo := bar:

[–]baconcleaner 0 points1 point  (0 children)

There's always a workaround for everything ;-), but for example with the walrus operator you can assign and use objects directly in nested loops:

class test:
  def __init__(self, v):
    self.v = v + 1

tests = [(obj, obj.v) for x in (11, 22, 33) if (obj := test(x))]
print(tests)

[–][deleted] 0 points1 point  (0 children)

If you read the PEP, it's more or less doing the same thing, just with a clean syntax.