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

Go "useless if/else" example is wrong #213

Open
josharian opened this issue Jun 28, 2024 · 0 comments
Open

Go "useless if/else" example is wrong #213

josharian opened this issue Jun 28, 2024 · 0 comments

Comments

@josharian
Copy link

One of the rewrites in https://github.com/getgrit/stdlib/blob/main/.grit/patterns/go/useless_if_else_body.md is wrong.

It rewrites

if ($conditon) { $body } else { $body }

to

if ($conditon) { $body }

Oops. (Also, condition is misspelled, and Go doesn't support using integers as booleans in conditions. But those are less important.)


The other rewrites is only sometimes sound. Rewriting

if ($conditon) { $body } else if ($conditon) { $body }

to

if ($conditon) { $body }

is unsafe if evaluating the condition has side-effects.

Given GritQL's goals, that might be ok. But it might be worth a sentence in the docs there?

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