docs.scala-lang icon indicating copy to clipboard operation
docs.scala-lang copied to clipboard

Taste section on match control structure is difficult to follow

Open stev-0 opened this issue 11 months ago • 2 comments
trafficstars

As a newcomer to the Scala language, I find this section difficult to follow.

It would help if Person and namewere defined somewhere to be able to compile at least but it's not at all clear what is going on to me.

Is anyone able to shed some light, happy to improve the docs myself once I understand what's trying to be demonstrated here.

stev-0 avatar Dec 03 '24 23:12 stev-0

I cribbed the example from Control Structures and made some modifications to illustrate it better here. I guess the point is that if you need to have a complex match condition decomposing an object, you can do, but appreciate this is a bit contrived.

stev-0 avatar Dec 04 '24 00:12 stev-0

I think the section is intended to be a "taste" and not a tutorial. It should say up front, "Here is a preview of pattern matching explained in more detail at link to detailed section." The examples should not be pseudocode but also need not compile as-is.

The ambiguity in this section is that the words don't explain any concepts. It says "match can be used with any data type and can be used to test a variable against many different types of patterns." I happen to know what that means after years of study, but as a beginner, I'd prefer: it can be used to extract the name field of class Person, etc.

Conversely, the detail section has an info box on @switch, which I think is TMI.

I think I've noted in the past that Fred says

https://flintstones.fandom.com/wiki/Yabba-Dabba-Doo!

so it's hard to trust the information at that point.

som-snytt avatar Jun 24 '25 09:06 som-snytt