Topics

Unused import warnings

Dan Boudreau
 

 

I’m seeing hundreds of unused import warning.  I can easily clean them up, anyone object?

 

Dan

Randall Wood <rhwood@...>
 

PR 7378 is already removing those unused imports (and putting a warning on future PRs to ensure they stay removed).

Randall

On Oct 1, 2019, at 17:13, Dan Boudreau <daboudreau@...> wrote:



 

I’m seeing hundreds of unused import warning.  I can easily clean them up, anyone object?

 

Dan

Dan Boudreau
 

Ok thanks.

 

Dan

 


From: jmri@jmri-developers.groups.io <jmri@jmri-developers.groups.io> on behalf of Randall Wood via Groups.Io <rhwood@...>
Sent: Tuesday, October 1, 2019 5:16:17 PM
To: jmri@jmri-developers.groups.io <jmri@jmri-developers.groups.io>
Subject: Re: [jmri-developers] Unused import warnings
 
PR 7378 is already removing those unused imports (and putting a warning on future PRs to ensure they stay removed).

Randall

On Oct 1, 2019, at 17:13, Dan Boudreau <daboudreau@...> wrote:



 

I’m seeing hundreds of unused import warning.  I can easily clean them up, anyone object?

 

Dan

Bob Jacobsen
 

On Oct 1, 2019, at 2:13 PM, Dan Boudreau <daboudreau@...> wrote:


I’m seeing hundreds of unused import warning. I can easily clean them up, anyone object?
Fixing them would be great, but let me recommend that you find that e.g. one of the following lines is unused:

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.Toolkit;

You replace the whole thing with

import java.awt.*;

That’s the practice in the standards doc we agreed to (admittedly a long time ago), but it occasionally gets lost due to IDE settings.

(Yes, I understand that there are two List classes in the Java API; that’s an interesting, but not compelling, special case)

Bob

--
Bob Jacobsen
@BobJacobsen

danielb987
 

Is this only about "import java.awt.*;" or about any packages, for example "import jmri.*;" ? 

Daniel 


-------- Originalmeddelande --------
Från: Bob Jacobsen <rgj1927@...>
Datum: 2019-10-02 14:59 (GMT+01:00)
Till: jmri@jmri-developers.groups.io
Rubrik: Re: [jmri-developers] Unused import warnings



> On Oct 1, 2019, at 2:13 PM, Dan Boudreau <daboudreau@...> wrote:
>
>
> I’m seeing hundreds of unused import warning.  I can easily clean them up, anyone object?

Fixing them would be great, but let me recommend that you find that e.g. one of the following lines is unused:

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.Toolkit;

You replace the whole thing with

import java.awt.*;

That’s the practice in the standards doc we agreed to (admittedly a long time ago), but it occasionally gets lost due to IDE settings.

(Yes, I understand that there are two List classes in the Java API; that’s an interesting, but not compelling, special case)

Bob

--
Bob Jacobsen
rgj1927@...






Bob Jacobsen
 

I think there’s some small N where one transitions from N specific imports to one * import to increase readability and accessibility of the file (the compiler doesn’t care either way[1]). Reasonable people can vary, but I think N of 3 to 5 is reasonable.

c.f.
java/src/jmri/jmrit/display/layoutEditor/LayoutEditor.java

If you’re editing by hand, do you need to add a import? Remove an import?

Bob


[1] Yes, there can be collisions in names, but they’re really quite rare in well-structured JMRI code.

On Oct 2, 2019, at 7:18 AM, danielb987 <db123@...> wrote:

Is this only about "import java.awt.*;" or about any packages, for example "import jmri.*;" ?

Daniel


-------- Originalmeddelande --------
Från: Bob Jacobsen <@BobJacobsen>
Datum: 2019-10-02 14:59 (GMT+01:00)
Till: jmri@jmri-developers.groups.io
Rubrik: Re: [jmri-developers] Unused import warnings



On Oct 1, 2019, at 2:13 PM, Dan Boudreau <daboudreau@...> wrote:


I’m seeing hundreds of unused import warning. I can easily clean them up, anyone object?
Fixing them would be great, but let me recommend that you find that e.g. one of the following lines is unused:

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.Toolkit;

You replace the whole thing with

import java.awt.*;

That’s the practice in the standards doc we agreed to (admittedly a long time ago), but it occasionally gets lost due to IDE settings.

(Yes, I understand that there are two List classes in the Java API; that’s an interesting, but not compelling, special case)

Bob

--
Bob Jacobsen
@BobJacobsen






--
Bob Jacobsen
@BobJacobsen

Randall Wood <rhwood@...>
 

The reality is that for an IDE user, removing every single unused or redundant (i.e. same package) import in JMRI is something like 4 clicks with a mouse, without touching a single file by hand.

Randall

On Oct 2, 2019, at 14:58, Bob Jacobsen <@BobJacobsen> wrote:

I think there’s some small N where one transitions from N specific imports to one * import to increase readability and accessibility of the file (the compiler doesn’t care either way[1]). Reasonable people can vary, but I think N of 3 to 5 is reasonable.

c.f.
java/src/jmri/jmrit/display/layoutEditor/LayoutEditor.java

If you’re editing by hand, do you need to add a import? Remove an import?

Bob


[1] Yes, there can be collisions in names, but they’re really quite rare in well-structured JMRI code.

On Oct 2, 2019, at 7:18 AM, danielb987 <db123@...> wrote:

Is this only about "import java.awt.*;" or about any packages, for example "import jmri.*;" ?

Daniel


-------- Originalmeddelande --------
Från: Bob Jacobsen <@BobJacobsen>
Datum: 2019-10-02 14:59 (GMT+01:00)
Till: jmri@jmri-developers.groups.io
Rubrik: Re: [jmri-developers] Unused import warnings



On Oct 1, 2019, at 2:13 PM, Dan Boudreau <daboudreau@...> wrote:

I’m seeing hundreds of unused import warning. I can easily clean them up, anyone object?
Fixing them would be great, but let me recommend that you find that e.g. one of the following lines is unused:

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.Toolkit;

You replace the whole thing with

import java.awt.*;

That’s the practice in the standards doc we agreed to (admittedly a long time ago), but it occasionally gets lost due to IDE settings.

(Yes, I understand that there are two List classes in the Java API; that’s an interesting, but not compelling, special case)

Bob

--
Bob Jacobsen
@BobJacobsen






--
Bob Jacobsen
@BobJacobsen





Bob Jacobsen
 

And that’s great so long as those same clicks _don’t_ expand `import java.util.*` into a flock of individual imports. In the past, that’s been a collateral consequence.

Note that I agree that reasonable people can differ on imports c.f. https://www.leadingagile.com/2018/12/the-importance-of-imports-in-java/ and I have _no_ problem with people removing individual unused imports; thank you to all that do that.

At the same time, please understand that some of the JMRI development community don’t think that Huge Sequences Of Import Statements are readable, and prefers to remove them. An `import javax.swing.*` is not a bad thing. Thank you to all that simplify those HSOIS occurrences. (And, if you’re removing an import in a HSOIS, you can often quickly drag over N-1 of them, delete, and change the last word in the remaining one to a *)

Bob

On Oct 2, 2019, at 12:24 PM, Randall Wood via Groups.Io <rhwood=mac.com@groups.io> wrote:

The reality is that for an IDE user, removing every single unused or redundant (i.e. same package) import in JMRI is something like 4 clicks with a mouse, without touching a single file by hand.
--
Bob Jacobsen
@BobJacobsen

Dan Boudreau
 

Found that I can configure Eclipse to automatically consolidate imports to something like `import java.util.*`.  Found under Organize Imports.  Interesting that I found the default to be 99, changed it to 5 and it seems to be doing the right thing.

 

 

Randall Wood <rhwood@...>
 

Every IDE I have used makes a distinction between “organizing” imports and “removing unused” imports.

Randall

On Oct 2, 2019, at 18:47, Bob Jacobsen <@BobJacobsen> wrote:

And that’s great so long as those same clicks _don’t_ expand `import java.util.*` into a flock of individual imports. In the past, that’s been a collateral consequence.

Note that I agree that reasonable people can differ on imports c.f. https://www.leadingagile.com/2018/12/the-importance-of-imports-in-java/ and I have _no_ problem with people removing individual unused imports; thank you to all that do that.

At the same time, please understand that some of the JMRI development community don’t think that Huge Sequences Of Import Statements are readable, and prefers to remove them. An `import javax.swing.*` is not a bad thing. Thank you to all that simplify those HSOIS occurrences. (And, if you’re removing an import in a HSOIS, you can often quickly drag over N-1 of them, delete, and change the last word in the remaining one to a *)

Bob

On Oct 2, 2019, at 12:24 PM, Randall Wood via Groups.Io <rhwood=mac.com@groups.io> wrote:

The reality is that for an IDE user, removing every single unused or redundant (i.e. same package) import in JMRI is something like 4 clicks with a mouse, without touching a single file by hand.
--
Bob Jacobsen
@BobJacobsen





RadSolution
 

" Every IDE I have used makes a distinction between “organizing” imports and “removing unused” imports. "

...except Visual Studio, which does both with one mouse click.... ;-)


On Thursday, 3 October 2019, 02:50:39 BST, Randall Wood via Groups.Io <rhwood@...> wrote:


Every IDE I have used makes a distinction between “organizing” imports and “removing unused” imports.

Randall
> On Oct 2, 2019, at 18:47, Bob Jacobsen <rgj1927@...> wrote:
>
> And that’s great so long as those same clicks _don’t_ expand  `import java.util.*` into a flock of individual imports.  In the past, that’s been a collateral consequence.
>
> Note that I agree that reasonable people can differ on imports c.f. https://www.leadingagile.com/2018/12/the-importance-of-imports-in-java/ and I have _no_ problem with people removing individual unused imports; thank you to all that do that.
>
> At the same time, please understand that some of the JMRI development community don’t think that Huge Sequences Of Import Statements are readable, and prefers to remove them.  An `import javax.swing.*` is not a bad thing. Thank you to all that simplify those HSOIS occurrences.  (And, if you’re removing an import in a HSOIS, you can often quickly drag over N-1 of them, delete, and change the last word in the remaining one to a *)
>
> Bob
>
>> On Oct 2, 2019, at 12:24 PM, Randall Wood via Groups.Io <rhwood=mac.com@groups.io> wrote:
>>
>> The reality is that for an IDE user, removing every single unused or redundant (i.e. same package) import in JMRI is something like 4 clicks with a mouse, without touching a single file by hand.
>
> --
> Bob Jacobsen
> rgj1927@...
>
>
>
>
>
>