On Mon, 28 Oct 2024 22:36:50 GMT, John Hendrikx <jhendr...@openjdk.org> wrote:

>>> I don't indent case labels inside of switch.
>> 
>> Our typical code style is to indent. I don't have a strong preference, but I 
>> switched (pun intended) many years ago from not indenting to always 
>> indenting because: A) the IDEs (at least most of them) indent by default; B) 
>> most of the code in the JDK and JavaFX does.
>> 
>>> I don't think we enforce one way or the other.
>> 
>> No, we don't. Feel free to leave it as you have it.
>
> This is a bit silly.  You have an opening brace, you should be indenting as 
> you would in every other case when an opening brace appears and you break off 
> the line.  So unless there is a **really** good reason to suddenly not do so 
> that has to do with readability, I think this is an really odd stand to take.

I agree that especially when each switch case is on a single line, indenting is 
the most sensible thing to do. It's a little more defensible to treat the 
standard switch `case NNNN:`, on a line by itself, as a label which is placed 
at the same indentation level as the switch itself (but even indenting it is 
more consistent).

Taking this example:

Option 1 - don't indent:


        String s = switch(val) {
        case 1 -> "one";
        case 2 -> "two";
        // ...
        default -> "unknown";
        };

Option 2 - indent:


        String s = switch(val) {
            case 1 -> "one";
            case 2 -> "two";
            // ...
            default -> "unknown";
        };


It seems pretty clear that the second option is easier to read. Virtually _all_ 
such uses in the JDK, and all uses up to now in JavaFX use the second pattern.

@andy-goryachev-oracle care to  make a counter-argument?

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1604#discussion_r1821009136

Reply via email to