different styles when coding #3

Updated: Mar 11

it wasn't that long ago that i tried to convince others in using optionals over nulls or empty strings. today i can say that i am more matured and accept almost any style of error handling or flow. optional flow forks like a charm if you can chain the return values one by one and dont have deal with multiple variables. with nulls or empty strings you are more or less forced to use classic if checks. additionally one cannot know if a returned null value is valid or should lead to a termination of the program. as in the last few posts, lets see which of of the two styles you prefer.

style 1:

        .forEach(minimalDto -> System.out.println(minimalDto.getNumber()));

style 2:

final var complexDto = plotter.getComplexDto();

if (complexDto == null) {

final var minimalDtos = complexDto

for (final var minimalDto : minimalDtos) {
    if (minimalDto != null) {

so which style are you, 1, 2 or even something else, tell me about it in the comments. 😄

Recent Posts

See All