Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain modern switch block #2893

Closed
wants to merge 4 commits into from
Closed

Conversation

josealonso
Copy link
Contributor

@josealonso josealonso commented Jan 2, 2025

Explain modern switch block

Text added to the switch block concept, explaining the modern switch statement and the switch expression.


Reviewer Resources:

Track Policies

@josealonso josealonso changed the title Explained modern switch block Explain modern switch block Jan 2, 2025
@josealonso
Copy link
Contributor Author

I didn't want to include pattern matching. I think it's quite easy to read.
I welcome your feedback, @kahgoh @manumafe98

Thanks :)

@josealonso josealonso marked this pull request as ready for review January 2, 2025 20:38
@manumafe98
Copy link
Contributor

Hey @josealonso Thanks for the contribution! You have to actually make the update here as you can see in the .docs directory we have a .md.tpl file that points to that one.

What i'm thinking is that the usage of switch would depend on what version of java the students use, makes sense to teach both the newer and older version but seems weird to called them like modern or older version, maybe specify in what versions of java the modern one can be applied and in which of them not?

Copy link
Contributor

@manumafe98 manumafe98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the introduction in the correct file

@kahgoh
Copy link
Member

kahgoh commented Jan 3, 2025

I think it might be confusing to mention both versions of the switch statement in the instructions - are students expected to use the "old" or the "new" switch statements in the exercise? If we're adding to this exercise, I'd suggest we could add/update the exercise to practice both styles. Alternatively, we've already mention switch expressions in the about.md. The about.md is for adding extra information about the concepts after they finish the exercise (see about.md documentation).

Other than, I'd suggest using the terms "switch statement" and "switch expressions" as I believe they commonly used to distinguish between the two.

@josealonso
Copy link
Contributor Author

Hey @josealonso Thanks for the contribution! You have to actually make the update here as you can see in the .docs directory we have a .md.tpl file that points to that one.

What i'm thinking is that the usage of switch would depend on what version of java the students use, makes sense to teach both the newer and older version but seems weird to called them like modern or older version, maybe specify in what versions of java the modern one can be applied and in which of them not?

Thanks @manumafe98. I'm sorry I didn't modify the correct document. Regarding the Java versions, that is explained in the text I wrote.

@josealonso
Copy link
Contributor Author

I think it might be confusing to mention both versions of the switch statement in the instructions - are students expected to use the "old" or the "new" switch statements in the exercise? If we're adding to this exercise, I'd suggest we could add/update the exercise to practice both styles. Alternatively, we've already mention switch expressions in the about.md. The about.md is for adding extra information about the concepts after they finish the exercise (see about.md documentation).

Other than, I'd suggest using the terms "switch statement" and "switch expressions" as I believe they commonly used to distinguish between the two.

That's a good point. I didn't know that was possible, sorry. The best option would be to update the exercise to practice both styles, since the traditional switch block is probably the most common one. But that requires to use the Analyzer and I still have to look into that API.
So for the time being, I'll move the text I wrote to the about.md file.
The modern switch statement is not an expression, but it's different from the traditional switch block. In Java 17 the switch expression is in preview stage, I think.

Thanks for the feedback @kahgoh

@kahgoh
Copy link
Member

kahgoh commented Jan 3, 2025

So for the time being, I'll move the text I wrote to the about.md file.

That sounds okay to me.

In Java 17 the switch expression is in preview stage, I think.

Ah, I think I missed Patterns for Switch (JEP 441), which was added in Java 21. Switch expression came out of preview in Java 14 (according to this Wikipedia page).

@josealonso
Copy link
Contributor Author

josealonso commented Jan 3, 2025

Many thanks for the link to the docs @kahgoh. I went trough several pages and I'm impressed it's so well-documented.

@josealonso
Copy link
Contributor Author

Replaced by #2899 @kahgoh

@josealonso josealonso closed this Jan 3, 2025
@josealonso josealonso deleted the patch-2 branch January 3, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants