[Geoserver-devel] New check to avoid too deply nested/indented code

Hi all,

I’d like to introduce a Checkstyle check that verifies lines are not too deeply nested.

The Google format we are using is indenting excessively long lines that are overflowing on the next line 8 chars instead of 4,
I believe as a way to discourage too deep nesting.

However, we have a lot of old code that has been reformatted blindly, and we have situations in the code like these:

https://github.com/geotools/geotools/blob/f66689b5305eaf381e21dc2feec8011138d4cb24/modules/library/referencing/src/main/java/org/geotools/referencing/operation/transform/GeocentricTransform.java#L446

https://github.com/geotools/geotools/blob/f66689b5305eaf381e21dc2feec8011138d4cb24/modules/library/referencing/src/main/java/org/geotools/referencing/operation/projection/TransverseMercator.java#L174

The first one can be easily fixed using Objects.hashCode(…) while the second is in need of a bit of expression splitting.
There are other egregious cases around, mostly due to excessive usage of nested classes (e.g., Wicket GUI code).

I’ve found a simple checkstyle configuration can spot all of them:

This should make the code overall more readable, and stop new too deeply nested bits to show up in the codebase.
Opinions?

Cheers
Andrea

Thanks Andrea, I have also found some of the closures getting deeply nested.

Jody

···


Jody Garnett

Here we go, for the GeoTools code, limiting the start line to column 65 (leaves 35 chars to write a bit of code before wrapping happens):
https://github.com/geotools/geotools/pull/3724

Did not try to go down to 60 but… it’s likely quite a bit of extra effort, I started with 80 and went down, each step required more code
changes to enforce the rule.

Cheers
Andrea

···

Regards,

Andrea Aime

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail

On Fri, Dec 31, 2021 at 4:04 PM Andrea Aime <andrea.aime@anonymised.com> wrote:

Did not try to go down to 60 but… it’s likely quite a bit of extra effort, I started with 80 and went down, each step required more code

changes to enforce the rule.

Actually, I did go down to 60 LOL… but that’s it.

Cheers
Andrea