A while ago (in the first attempt on this journal thingy to be precise), I noted a proposed feature of "complex conditionals". Since there hasn't been much response, it may be better to dedicate a post to it.
It all boils down to a single new added possibility - chain more relational operations in a single expression. Example: if you need to compare a variable to two values, you currently need to do this:
if (1 < a && a < 5) {}
Well, that doesn't look too bad, you're right. What about this?
if (0 < a && a < b && b < c && c < d && d < 255) {
// do something
} else {
error ("Invalid data");
}
I don't know about you, but I think this is just evil.
Now, with the complex conditionals thingy, this would be possible:
if (1 < a < 5) {}
if (0 < a < b < c < d < 255) {
// do something
} else {
error ("Invalid data");
}Muuuuuch nicer. :)
However, Jürg suggested that there are more possible approaches to this problem. For example a range syntax:
if (a in [1..5]) {}
I don't find this possibility particularly bad, but it wouldn't allow any fancier chaining, like in my second example.
So, questions for you: What do you thing about it? Which one do you prefer? Do you have any other suggestions?
EDIT:
Ahh, forgot to link the bug report.
https://bugzilla.gnome.org/show_bug.cgi?id=606480