Code formatter & multi lines

The past days I was doing some code work for openhab, including making the code readable by using some proper formatting. Unfortunately Eclipse seems to have a different opinion (out-of-box) about how code should look, while I prefer

StringBuilder urlBuilder = new StringBuilder(NestBindingConstants.NEST_ACCESS_TOKEN_URL)
       .append("?client_id=")
       .append(config.clientId)
       .append("&client_secret=")
       .append(config.clientSecret)
       .append("&code=")
       .append(config.pincode)
       .append("&grant_type=authorization_code");

Eclipse seems to think that the following is more readable:

StringBuilder urlBuilder = new StringBuilder(NestBindingConstants.NEST_ACCESS_TOKEN_URL)
       .append("?client_id=").append(config.clientId).append("&client_secret=").append(config.clientSecret)
       .append("&code=").append(config.pincode).append("&grant_type=authorization_code");

@all do you agree that the first one is more readable or am I alone in this?

@Kai can we please change the formatter to allow the more readable and maintainable (!) form and if you agree how should we do this, with what kind of procedure?

The configuration should not be hard others did it to:

1 Like

The openHAB IDE uses exactly the same settings as the ESH IDE, so that the codebase follows the same guidelines.

The code formatter has been discussed and defined a while ago. Note that we are very reluctant to do any changes to it, because it would mean that we generate lots of code changes that make diffing and browsing the code history very difficult.

Wrt your specific case: While it looks ok for your example as it has the same method all over again, it might not be a good choice in other cases. In general, the typical way in Java is to put such code on a single line (after all it is a single variable assignment) and all the code formatter does it to wrap at a certain line length.

If you think that something should be changed, the best place would imho be https://dev.eclipse.org/mhonarc/lists/smarthome-dev/.

Personally I also favor it for other cases:

Just some some random work example which went through a thorough review at my company:

return ticketNumbers
        .stream()
        .map(fileResourceService::getAttachments)
        .flatMap(List::stream)
        .collect(Collectors.toList());

But I would even be more happy if that part would be left open, so that both style can live safely next to each other (like Intellij supports :wink: ) I will register at the Eclipse forums later this week and open the discussion there.

I thought smarthome had a forum but is it only maillist now is that correct?

The mailing list is rather for internal stuff that the committers need to decide on - the general discussion forum is at https://www.eclipse.org/forums/index.php/f/271/.