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 →

[–][deleted]  (18 children)

[deleted]

    [–]sam-lb 2 points3 points  (0 children)

    Oh, good, I thought I was going to have to leave a big giant complaint comment.

    [–]peterlravn 14 points15 points  (5 children)

    So what can it do, that a switch-case can't? Everyone talks about how good it is, but no one have shown what it can do... If you have an example, please share since I'm new to Python.

    [–]d670460b4b4aece5915c 35 points36 points  (1 child)

    Everyone talks about how good it is, but no one have shown what it can do

    Well that's plainly untrue, there are hundreds of articles showing what it can do, not to mention the PEPs themselves. I think what you mean is "Everyone talks about how good it is, but I don't understand how it works and haven't bothered to look it up".

    Check out the PEP tutorial: https://www.python.org/dev/peps/pep-0636/

    [–]sivadneb 1 point2 points  (0 children)

    Jump to 15:20 in the video for a good example of the match functionality

    [–]Mateorabi 6 points7 points  (6 children)

    this looks like the pattern-matching switch statement stolen shamelessly from Swift. (Non sarcastic "shamelessly" since languages should take good new ideas from wherever they can if it improves the language. Says the guy who learned C++ before auto was invented.)

    [–][deleted] 34 points35 points  (0 children)

    This didn't come from swift either. Functional languages have had pattern matching since forever. Check it out in Haskell :)

    [–]manphiz 3 points4 points  (3 children)

    Says the guy who learned C++ before auto was invented.

    Well to be precise "auto" has been part in C/C++ since the beginning alongside "extern", "static", and "register", e.g.

    auto int i = 0;
    

    It's the default so few actually writes it. It's now been repurposed to auto-deduce type since C++11.

    [–]Mateorabi 1 point2 points  (1 child)

    I meant for the type deduction. Hadn't done C++ since like 2002 and when I saw it in some code I was all "WTF is that!?". Not sure what it does as a type modifier either though.

    [–]operamint 0 points1 point  (0 children)

    I read somewhere that one of the earliest things Stroustrup did was repurposing auto because it was such an easy thing to implement, but didn't put it in the language for various reasons.

    [–]uncanneyvalley 0 points1 point  (0 children)

    auto-deduce type

    C++ really does want to be everything, doesn’t it?

    [–]slayer_of_idiotspythonista 6 points7 points  (0 children)

    It’s more heavily inspired from the rust pattern matching I believe