Sharing my experience with Switch Expressions
David Alayachew
davidalayachew at gmail.com
Sun May 11 19:22:57 UTC 2025
Hey Chen,
Sure.
Here is the old nested Switch version.
https://github.com/davidalayachew/HelltakerPathFinder/blob/12c57dab041924192b8613075ff6966b1b159e91/src/main/java/HelltakerPathFinderModule/HelltakerPathFinderPackage/Board.java#L511
And here is the new flattened switch version.
https://github.com/davidalayachew/HelltakerPathFinder/blob/b0e8359e429967758b1ded02b818b8d46ed05b32/src/main/java/HelltakerPathFinderModule/HelltakerPathFinderPackage/Board.java#L512
I specifically made these links so that they link to the commit. So, you
can browse the files, as they were at the time of that commit.
But lol, hopefully looking at these can show you the night and day
difference that I am talking about in readability? Or the ability to forget
a case in the nested way? Flattened way outright FORBIDS me forgetting a
case BECAUSE record patterns in Switch demand exhaustiveness. Semantically
speaking, I almost feel like the flattened version is more accurate of my
true intention, and less likely to be wrong.
On Sun, May 11, 2025 at 11:38 AM Chen Liang <chen.l.liang at oracle.com> wrote:
> Hi David,
> I wonder if your code is open for review. If you can provide your actual
> code, I think we can have a better grasp of the whole situation.
>
> Regards, Chen Liang
> ------------------------------
> *From:* amber-dev <amber-dev-retn at openjdk.org> on behalf of David
> Alayachew <davidalayachew at gmail.com>
> *Sent:* Sunday, May 11, 2025 9:48 AM
> *To:* amber-dev <amber-dev at openjdk.org>
> *Subject:* Re: Sharing my experience with Switch Expressions
>
> Let me also add one thing.
>
>
> I had started this project before Record Patterns had been released. So,
> it was only incidentally that I had ended up using a set of nested Switch
> Expressions -- I was forced to back then.
>
> I know for a fact that, had I been given the opportunity, I would have
> done things flat from the beginning. Nesting switch expressions is
> definitely not my first choice.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20250511/78e8b44a/attachment-0001.htm>
More information about the amber-dev
mailing list