On Thu, 1 Apr 2021 12:57:44 GMT, Jayathirth D V <j...@openjdk.org> wrote:
>> Is it not right? >> I admit I don't understand what you mean by _map_ here. >> >> When the code is written like it was: >> if ((printServices[j] instanceof Win32PrintService) && >> (!printServices[j].equals(defaultPrintService))) { >> >> ((Win32PrintService)printServices[j]).invalidateService(); >> } >> it's hard to scan: it's not clear what is part of the condition and what is >> the statement inside the if block. >> >> I'd prefer to write it like this: >> if ((printServices[j] instanceof Win32PrintService) >> && (!printServices[j].equals(defaultPrintService))) { >> >> >> ((Win32PrintService)printServices[j]).invalidateService(); >> } >> That is moving the operator to the continuation line which makes it obvious >> it is a continuation line of the condition and adding a blank line before >> the statement in the code. It's still not perfect, however; and it changes >> the author in `blame` output. >> >> I indented the continuation line by additional 8 spaces, which is also a >> common practice in Java, to visually separate the condition and the >> statement. In fact, it's IDE that updated the formatting, I decided to keep >> it because it makes the code clearer. >> >> I can revert the change to this line if you like. >> Or I can just add a blank line between the condition and the statement. >> >> What is your preference? > > By mapping i mean same indentation for all conditions in if statement without > adding additional indentation for each continuation line like(Basically line > without your change of indentation) > if ((condition1) && > (condition2)) { > } > > or > > if ((condition1) > &&(condition2)) { > } > > I have not come across code in java.desktop where we add indentation at each > continuation line of 'if' condition. > I understand difficulty to scan without indentation but then in cases where > we have multiple lines on continuation line in if statement we will easily > hit 80 characters limit. > > If we want to differentiate between if conditions and actual statement > execution to improve readability, we can move the statement block to new line > like > if ((condition1) && > (condition2)) > { > } I would prefer if you revert this line or if we want to put emphasis on readability moving '{' to new line also seems fine. ------------- PR: https://git.openjdk.java.net/jdk/pull/3151