www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [DIP1005] Unused imports in with(import) declarations: leave alone of

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
Consider:

with (import std.stdio)
int fun(int x/*, File f*/)
{
     // f.writeln("In: ", x);
     return x * x;
}

Such situations occur during refactorings and code evolution. The import 
is no longer used. Should the compiler flag that as an error, or leave 
it be?


Andrei
Dec 24 2016
next sibling parent Tourist <gravatar gravatar.com> writes:
On Saturday, 24 December 2016 at 20:32:58 UTC, Andrei 
Alexandrescu wrote:
 Consider:

 with (import std.stdio)
 int fun(int x/*, File f*/)
 {
     // f.writeln("In: ", x);
     return x * x;
 }

 Such situations occur during refactorings and code evolution. 
 The import is no longer used. Should the compiler flag that as 
 an error, or leave it be?


 Andrei
I'd use a warning, as with unused variables: the code is in an OK state when in the middle of a work (such as temporarily commenting a block), but less OK for a release. Also, Visual Studio highlights unused includes for C#, which is nice.
Dec 24 2016
prev sibling next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
On 25/12/2016 9:32 AM, Andrei Alexandrescu wrote:
 Consider:

 with (import std.stdio)
 int fun(int x/*, File f*/)
 {
     // f.writeln("In: ", x);
     return x * x;
 }

 Such situations occur during refactorings and code evolution. The import
 is no longer used. Should the compiler flag that as an error, or leave
 it be?


 Andrei
How costly is the checking of if said import is used?
Dec 24 2016
prev sibling next sibling parent Jonathan M Davis via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Saturday, December 24, 2016 15:32:58 Andrei Alexandrescu via Digitalmars-
d wrote:
 Consider:

 with (import std.stdio)
 int fun(int x/*, File f*/)
 {
      // f.writeln("In: ", x);
      return x * x;
 }

 Such situations occur during refactorings and code evolution. The import
 is no longer used. Should the compiler flag that as an error, or leave
 it be?
I say leave it be. It's the sort of thing that risks causing problems with conditional compilation (not as bad as in some cases, but I still don't think that it's worth the risk). IMHO, this is the sort of thing that should be left up to a lint tool, and there's technically nothing wrong with it. - Jonathan M Davis
Dec 24 2016
prev sibling next sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
On Saturday, 24 December 2016 at 20:32:58 UTC, Andrei 
Alexandrescu wrote:
 Such situations occur during refactorings and code evolution. 
 The import is no longer used. Should the compiler flag that as 
 an error, or leave it be?
please, no. "this is a work for a linter", as Walter likes to say (sorry for inexact quoting ;-).
Dec 24 2016
prev sibling next sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
On Saturday, 24 December 2016 at 20:32:58 UTC, Andrei 
Alexandrescu wrote:
 Consider:

 with (import std.stdio)
 int fun(int x/*, File f*/)
 {
     // f.writeln("In: ", x);
     return x * x;
 }

 Such situations occur during refactorings and code evolution. 
 The import is no longer used. Should the compiler flag that as 
 an error, or leave it be?


 Andrei
Generic code and generated code would suffer from an error being generated there.
Dec 25 2016
prev sibling parent Daniel =?iso-8859-1?b?S2964Ws=?= via Digitalmars-d writes:
Andrei Alexandrescu via Digitalmars-d <digitalmars-d puremagic.com>=20
napsal So, pro 24, 2016 v 9=E2=88=B632 :
 Consider:
=20
 with (import std.stdio)
 int fun(int x/*, File f*/)
 {
     // f.writeln("In: ", x);
     return x * x;
 }
=20
 Such situations occur during refactorings and code evolution. The=20
 import is no longer used. Should the compiler flag that as an error,=20
 or leave it be?
=20
=20
 Andrei
for such things there should be support in IDE or use some lint tool =
Dec 25 2016