expand on range & "inverse" range checking #4381
Closed
MaliusArth
started this conversation in
Proposals
Replies: 1 comment
-
None of this is ever going to happen. For this to work, ranges would have to be a moveable construct rather than mere syntactic sugar. And some of those things don't make zero sense, especially |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Odin currently supports range checking via comparison operators:
Unfortunately, this syntax makes it hard to identify errors and intent.
For example, did you recognize the typo in one of the comparisons?
This method of range checks can be made clearer using "yoda" expressions
While this slightly improves readability and intent, it can definitely be improved upon.
Odin already has range operators which significantly improve readability & intent signaling while also reducing surface area for errors.
As of now, though, their use for range checking is quite limited:
The
if
statement variants probably offer the most bang for the buck as they don't seem to collide with existing language constructs and can be combined with regular loops. Furthermore, the already supportedswitch
variant can work around the ambiguity of thefor
statements.As for range exclusion checking, ie. checking whether a variable value resides outside of a range, no support exists in any of the currently existing control flow statements.
To sum it up:
At the very least add support for range checking via range operators in
if
statementsFor completeness & consistency it would be great to support range operations in all control flow statements.
Beta Was this translation helpful? Give feedback.
All reactions