Feature #10343
openPostfix notations for `when` and `else` inside `case` statement
Description
In case
statements, the condition part are not always uniform in length, and especially, else
is short. When we want to put each when
statement in a single line, they are not always aligned, and are hard to read.
case foo
when some_very_long_condition then "a"
when short_cond then "bb"
when some_long_condition then "ccc"
else "dddd"
end
I think it would be better if we can do postfix notations with when
and else
inside case
statement as below.
case foo
"a" when some_very_long_proc
"bb" when short_regex
"ccc" when some_long_regex
"dddd" else
end
The length of "a"
, "bb"
, "ccc"
, "dddd"
, etc. can also vary, but they are usually more homogenuous with respect to length than the condition, and easier to align. And, it is these values that we are interested in, rather than the conditional parts. Furthermore, this notation is closer to the case-like notation standardly used in mathematics for conditions, so it would be easier to read for those who are familiar with mathematics.
x! = 1 (x = 0)
x (x - 1)! (otherwise)