dsimcha, el 20 de agosto a las 13:42 me escribiste: > == Quote from bearophile (bearophileh...@lycos.com)'s article > > A small Reddit thread regarding if unused variables and imports are better > > as > errors or warnings: > > http://www.reddit.com/r/programming/comments/d3emo > > In my opinion in this case errors are too much, warning are enough. > > Few situations for those warnings: > > - warning for unused variables (as GC, C# and other compilers do); > > - warning when a variable get used in some ways, and then its last > > assignment > gets unused (done by a kind of C compiler); > > - unused imports (useful to keep code clean and remove unnecessary module > dependences); > > - unused functions (but this is harder to do in a clean way in a language > > that > has templates, so this may be omitted). > > Among those four warnings the most useful are the first two ones. In C once > > the > unused variable warning of GCC has found at compile time a bug in my code (I > did > forget to increment that variable in the loop). So I have loved this warning > ever > since. > > Bye, > > bearophile > > If we make unused imports an error, how is anyone supposed to do import > someSmallLibrary.all? If you make unused imports an error, the collective > cost of > extra import declaration boilerplate will probably be larger than the GDP of > some > African countries.
I never understood this argument against flagging errors/warnings on unused imports. lib/a.d: void f() {} lib/all.d: public: import lib.a; import lib.b; import lib.c; unused.d: void g() {} user.d: import lib.all; import unused; f(); import lib.all should never flag an error/warning, because at least one symbol in lib.all is used. Public imports are treated as if they were declared in the module that imports them. import unused should flag an error/warning, since no symbol in unused is used by user.d. Do you see any problem with that? -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- It's not a lie, if you believe it. -- George Constanza