4 ms·
Yeah, came here to say the same thing. Disappointing to have to write this: match shape: case Square(l): area = l * l case Rect
by rattray 6y ago
Yeah, came here to say the same thing. Disappointing to have to write this:
match shape:
case Square(l):
area = l * l
case Rectangle(l, w):
area = l * w
case Circle(r):
area = (PI * r) ** 2
when I want to just write this:
area = match shape:
case Square(l):
l * l
case Rectangle(l, w):
l * w
case Circle(r):
(PI * r) ** 2
I'm almost guaranteed to forget (or mistype) the `area = ` at least once in any match clause of length.
- whalesalad 6y agoThat works almost exactly in Ruby. I really wish Python and Ruby would have a child.
- rattray 6y agoFunny. Having worked extensively with Ruby and less so with Python, I think what I really want is expression-oriented Python. Ideally as a next version of Python. But I think Julia and Nim come to mind as related to these concepts.