On Fri, 7 Aug 2020 17:33:04 -0300
"Joao S. O. Bueno" <jsbu...@python.org.br> wrote:
> 
> Branch comparison for the match/case version:
> https://github.com/jsbueno/terminedia/compare/patma

For me, your example is bonkers from the start.  Anyone who thinks

`Rect(left_or_corner1=None, top_or_corner2=None, right=None,
      bottom=None, *, width_height=None, width=None, height=None,
      center=None)`

is a reasonable constructor signature for a rectangle class needs to be
convinced otherwise, rather than be allowed to find convenient
implementation shortcuts for that signature.

I'll note that there's no checking for superfluous / exclusive
arguments, so apparently I can pass all those arguments at once and the
constructor will happily do what it likes, ignoring half the
arguments I have without telling?  WTH?

(and of course, there's no docstring anywhere, so I can only /presume/
this is supposed to be a rectangle class, based on its name)

And as a matter of fact, while the pattern matching implementation is
definitely shorter, it's still unreadable.

I don't know about you, but if I see this during a code review:
```
        match kw:
            case {"c1": (c1:=(_, _)), "c2": (c2:=(_, _))}: pass
            case {"c1": Rect(c1, c2)}: pass
            case {"c1": Number(), "c2": Number(), "right": Number(),
        "bottom": Number()}:
                c1, c2 = (kw["c1"], kw["c2"]), (right, bottom)
            case {"c1": (_, _, _, _)}:
                c1, c2 = kw["c1"][:2], kw["c1"][2:]
            case {"c1": (c1:=(_, _)), "width_height": (_, _)}:
                c2 = c1 + V2(width_height)
            case {"c1": (c1:=(_, _)), "width": Number(), "height":
        Number()}:
                c2 = c1 + V2(width, height)
            case {"c1": (c1:=(_, _)), "c2": None, "right": Number(),
        "bottom": Number()}:
                c2 = bottom, right
            case {"c1": None, "right": Number(), "bottom": Number(),
        "center": (_, _)}:
                c1 = 0, 0
                c2 = bottom, right
            case {"c1": (c2:=(_, _)), "c2": None}:
                c1 = 0, 0
```

then I will ask the author to think twice about the fact they're
inflicting pain on their follow contributors by committing write-only
code (in addition to the toxic API design).

So, if the aim of the example was to prove that bad APIs could be
implemented more tersely using pattern matching, then congratulations,
otherwise I'm not impressed at all.

Regards

Antoine.

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/4LCLAS5QKWUU4SBVKX2QOLW7XAONMXQQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to