3 ms·
This example is interesting, in that the suggestion for canonical "<" (as apposed to ">") results in awkward code: if (index < xs.len) { // Not the point
by Nevermark 3y ago
This example is interesting, in that the suggestion for canonical "<" (as apposed to ">") results in awkward code:
if (index < xs.len) {
// Not the point
} else {
// The condition we wanted to do something
}
Which would be fixed (still using "<") with a NOT operator.
But, I have noticed that I feel slightly irritated by the extra parens that introducing NOT operators often causes:
if (!(condition expression)) {
// The condition we wanted to do something
}
Given NOT is always a unary operation, it would be some nice sugar if "if" clauses didn't require parens for "notting" the condition:
if !(condition expression) {
// The condition we wanted to do something
}
Or we could have "ifnot" clauses, to be clearer.
ifnot (condition expression) {
// The condition we wanted to do something
}
Point being, sometimes it feels easier to test for false than true, based on the variable meanings and context.
(All this syntax fine tuning, is at least amusing.)