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

Revisit ternary operator section #370

Open
technocidal opened this issue Oct 16, 2023 · 0 comments
Open

Revisit ternary operator section #370

technocidal opened this issue Oct 16, 2023 · 0 comments

Comments

@technocidal
Copy link

Swift 5.9 introduced the final implementation of of SE-0380.

It is now possible to rewrite a given ternary operator using if/swift expressions

let value = 5
result = value != 0 ? x : y

turns into

let value = 5
result = if value != 0 {
  x
} else {
  y
}

In my opinion this syntax can lead to a more readable result than using a ternary operator making it more useful for evaluating complex conditions and expands the complexity of conditions that are evaluated during assignment. It might be a good idea to mention it or include additional language describing best practices.

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

No branches or pull requests

1 participant