Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] A matter of style: loops vs. streams and - gasp - braces

> If you debug such code (not written by you), you tend to read this
> wrong:
>
>        for (X x : coll)
>            if (isGood(x))
>                process(x);
>                andProcess(y);

I guess this might happen for bad code of (hopefully) non-eclipse
projects. With automatic code formatting these kind of things should
not happen in practice. I guess JDT is also using project specific
settings to enforce automatic formatting on save, right?

A somewhat compromise to both of your opinions might be to allow to
remove the brackets for the innermost of such loops and ifs:

	for (X x: coll) {
		if (isGood(x)
			process(x);
	}

From my experience most of these simple statements do not happen
massively nested but rather isolated, like

	if (loggingEnabled)
		log()

	whatEverComesNext()

In the example above we do still keep an empty line after the statement
for clearer readability. Still (to me) it looks nicer than having the
closing bracket there.

Christian




Back to the top