Hi all,
continuing on the thread of possible code improvements, I'd proposed to
move variable declarations
as close to their usage as possible.

There is currently a lot of code, probably written by people coming from C
K&R experiences, that
declares variables close to the top of a method, and then assigns them way
later. Or even just code
that splits declaration and assignment over two subsequent lines.

Personally, both annoy me. The first one looks nothing like Java code, and
makes it harder to figure
out what is the type of the assigned variable. The second looks
unnecessarily verbose.

IntelliJ provides an "assignment can be joined with declaration" refactor
which seems to do the trick.
I've experimented running it, here are draft PRs showing the results:

   - GeoTools: https://github.com/geotools/geotools/pull/3320
   - GeoWebCache: https://github.com/GeoWebCache/geowebcache/pull/915
   - GeoServer: https://github.com/geoserver/geoserver/pull/4659

Opinions?

Cheers
Andrea

PS: IntelliJ offers another K&R avoidance refactor, dealing with array
declaration, switching all
"Object myArray[]" to "Object[] myArray". I think it's also worth applying,
as odd and out of place
the C style approach might seem, there are actually hundreds of those in
the code base (470 to be precise)

== GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf
Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa
(LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549
http://www.geo-solutions.it 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.*
_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to