[
https://issues.apache.org/jira/browse/GROOVY-8570?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16468021#comment-16468021
]
Paul King commented on GROOVY-8570:
-----------------------------------
I can see both sides to this suggestion. There have been numerous times when
I've wanted just such a feature in the past (a warning when you use a
deprecated api is one example that comes to mind) but I also appreciate some of
Jochen's previously raised concerns. Basically, one person's "important"
warning is another's "spam" warning.
Just taking a Devil's advocate stance for a minute, I would argue that it is
debatable whether using curly braces for an array definition would make my list
of critical warnings. It might be slightly more important than an unneeded
semi-colon or a double-quoted string with no interpolated variables (so not
really a GString) but I wouldn't regard it as an order of magnitude more
important. Even the proposed warning when using var is hard to imagine as being
an order of magnitude more important. It wouldn't be applicable (at least with
the current wording) when using @CompileStatic and when using dynamic Groovy
you should already expect certain things that might happen at compile time with
Java would happen at runtime with Groovy. That's true for many things, so why
the warning for this case? There are over 350 warnings in codenarc. We
certainly wouldn't want all of those in the compiler!!
Stating it another way, the Groovy compiler has always been relaxed about code
using Java idioms. You can take your Java code and slowly add in more Groovy
idioms over time. You don't get lots of warnings encouraging you to have more
perfect code which might be off-putting for new users. Using codenarc allows
anyone that wants such guidance to turn on as many such warnings as makes sense
for them.
So, I see value in having warnings but if we had a codenarc hook, that would
dramatically affect what kind of warnings I'd want to see in the compiler. For
the deprecated api usage, I might get a single warning: 'Deprecated api usage
detected, turn on the XYZ codenarc rule for details', similarly for say your
first example I might see: 'Legacy Java idioms detected, turn on the ABC
codenarc rule for details'. And there would probably be a way to suppress even
these warnings if I am running codenarc anyway in my build.
> Support Warnings in Groovy Compiler
> -----------------------------------
>
> Key: GROOVY-8570
> URL: https://issues.apache.org/jira/browse/GROOVY-8570
> Project: Groovy
> Issue Type: New Feature
> Components: Compiler
> Affects Versions: 3.0.0-alpha-3
> Reporter: mgroovy
> Priority: Major
>
> * To warn Java developers using e.g. non-idiomatic Groovy constructs which
> only exist to support copy-and-paste Java-to-Groovy code compatibility, The
> Groovy compiler should support compiler warnings in addition to compiler
> errors.
> * Warnings should by default only be emitted in special circumstances such
> as the one described above, and not spam developers with an endless stream
> of, often subjectve, messages on "how to use Groovy correctly".
> * Sample warnings:
> # WARNING: Using curly braces Java style array literals (\{...}) is not
> idiomatic Groovy. To avoid confusion with Groovy closures, it is recommended
> to use the performance-identical Groovy square bracket list literal syntax
> ([...]) instead.
> # WARNING: The 'var' keyword is currently only an alias to 'def' (i.e.
> Object) in Groovy. To get reassignment type safety use an explicit type
> instead.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)