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

Always break nested Conditionals #434

Closed
belav opened this issue Sep 12, 2021 · 2 comments · Fixed by #460
Closed

Always break nested Conditionals #434

belav opened this issue Sep 12, 2021 · 2 comments · Fixed by #460
Assignees
Milestone

Comments

@belav
Copy link
Owner

belav commented Sep 12, 2021

When we have a nested conditional, we should probably break each one.

Currently it is like this.

return (h >= '0' && h <= '9')
  ? h - '0'
  : (h >= 'a' && h <= 'f') ? h - 'a' + 10 : (h >= 'A' && h <= 'F') ? h - 'A' + 10 : -1;

But I think it should look like this

return h >= "0" && h <= "9"
  ? h - "0"
  : h >= "a" && h <= "f"
      ? h - "a" + 10
      : h >= "A" && h <= "F"
          ? h - "A" + 10
          : -1;

Prettier does it like this, but I think the indentation makes it more readable

return h >= "0" && h <= "9"
  ? h - "0"
  : h >= "a" && h <= "f"
  ? h - "a" + 10
  : h >= "A" && h <= "F"
  ? h - "A" + 10
  : -1;
@respel
Copy link

respel commented Oct 9, 2021

I like your approach for this @belav. The prettier one is pretty(no pun intended :P) confusing.

I forgot to mention the one true correct way ™ to do it though. Just don't use ternary operators :)

@belav belav added this to the 0.11.0 milestone Oct 24, 2021
@belav belav self-assigned this Oct 24, 2021
belav added a commit that referenced this issue Oct 24, 2021
@belav
Copy link
Owner Author

belav commented Oct 24, 2021

@respel you should look at some of the crazy nested ternary operators https://github.com/belav/csharpier-repos/pull/10/files

belav added a commit that referenced this issue Oct 24, 2021
shocklateboy92 added a commit that referenced this issue Oct 24, 2021
closes #434

Co-authored-by: Lasath Fernando <devel@lasath.org>
belav added a commit that referenced this issue Nov 10, 2021
closes #434

Co-authored-by: Lasath Fernando <devel@lasath.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants