From: "mame (Yusuke Endoh) via ruby-core" Date: 2023-03-10T01:16:28+00:00 Subject: [ruby-core:112815] [Ruby master Feature#10343] Postfix notations for `when` and `else` inside `case` statement Issue #10343 has been updated by mame (Yusuke Endoh). Status changed from Open to Rejected Discussed at the dev meeting. @matz rejected this proposal because he didn't think it was easy to understand. ---------------------------------------- Feature #10343: Postfix notations for `when` and `else` inside `case` statement https://bugs.ruby-lang.org/issues/10343#change-102318 * Author: sawa (Tsuyoshi Sawada) * Status: Rejected * Priority: Normal ---------------------------------------- In a `case` statement, the condition part (`when ...`) in the branches do not have the same length in general, and especially, `else` is much shorter than the conditions. So when we write the condition and the return value in a single line, they are not aligned, and are hard to read. ```ruby case foo when some_very_long_proc then "a" when short_regex then "bbb" when some_long_regex then "cc" else "dddd" end ``` I propose to allow postfix notations with `when` and `else` (or `otherwise`) inside `case` statement as below: ```ruby case foo "a" when some_very_long_proc "bbb" when short_regex "cc" when some_long_regex "dddd" else end ``` Pros are: 1) Postfix notation does not require `then` or `;`, so it is concise. 2) The return values from the branches (e.g., `"a"`, `"bb"`, `"ccc"`, `"dddd"`) tend to be shorter and more uniformly lengthened than the conditions, hence they are somewhat close to being aligned naturally, making this easier to read. 3) We are usually more interested in the return value than the condition of a branch, especially when we are reading someone's code and are trying to grasp what the `case` statement does or returns. 4) This notation is closer to case-like conditional notations regularly used in mathematics: ``` ��� 1 (x = 0) x! = ��� ��� x (x - 1)! (otherwise) ``` So it would be easier to read for those who are familiar with mathematics. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/