Closed lucaswerkmeister closed 10 years ago
value result = mySequence
.fold(...)
?.operation(...);
But this breaks my entire indentation architecture and just doesn’t work with tabs instead of spaces.
value result = mySequence
.fold(...)?
.operation(...);
Unfortunately, this isn’t syntactically valid. I suppose it’s also hard to read.
value result = mySequence
.fold(...)
?.operation(...);
That’s what the IDE’s indentation strategy does.
value result = mySequence
.fold(...)?.
operation(...);
value result = mySequence.
fold(...)?.
operation(...);
For now, I’ll go with Aligning the columns. I might add an option for All operators on the previous line later.
Strangely, I kinda liked Aligning the periods, 2. But that would mean changing the grammar of the language. I think Aligning the columns is reasonable.
I’m kinda torn about Aligning the periods, 2 myself... I think it makes sense in a long call chain where you just don’t care if some intermediate result is null
(“What, that’s optional? Fine, I’ll just add a ?
. Ugh, that makes it all misaligned. Can’t I stick the ?
up there?”), but if the null
case is important (for example, if you’re assigning the result to some variable, maybe with an else
clause as well), then I think that ?
is too hidden and makes the code very unreadable.
I don't think aligning the periods makes sense. More often you've got just one invocation, not a whole chain of them. Then for some crazy reason lines starting with ?.
are indented differently to the rest of the code.
You mean 1? Yeah, I don’t like that one either. I don’t know why I put it first in the list...
Ah, ok, yes, that's what I meant.
Also, FTR, I don't like seeing lines ending in periods, it looks much too much like a full stop. And there's nothing warning you, if you just look at the next line, that it is a member reference you're seeing.
Good point. I don’t think that’s really used in Java either (Eclipse formatter doesn’t seem to have a setting for it), so I’ll just drop that and close the issue.
The regular member operator,
.
, is usually put on the start of the new line:How should this look for the nullsafe member operator
?.
and the spread member operator*.
?