Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 24, 2016 [DIP1005] Unused imports in with(import) declarations: leave alone of flag as errors? | ||||
---|---|---|---|---|
| ||||
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 |
December 24, 2016 Re: [DIP1005] Unused imports in with(import) declarations: leave alone of flag as errors? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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.
|
December 25, 2016 Re: [DIP1005] Unused imports in with(import) declarations: leave alone of flag as errors? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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?
|
December 24, 2016 Re: [DIP1005] Unused imports in with(import) declarations: leave alone of flag as errors? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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
|
December 25, 2016 Re: [DIP1005] Unused imports in with(import) declarations: leave alone of flag as errors? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 ;-).
|
December 25, 2016 Re: [DIP1005] Unused imports in with(import) declarations: leave alone of flag as errors? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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.
|
December 25, 2016 Re: [DIP1005] Unused imports in with(import) declarations: leave alone of flag as errors? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu Attachments:
| Andrei Alexandrescu via Digitalmars-d <digitalmars-d@puremagic.com> napsal So, pro 24, 2016 v 9∶32 :
> 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
for such things there should be support in IDE or use some lint tool
|
Copyright © 1999-2021 by the D Language Foundation