[Haskell-cafe] coding standard question

wren ng thornton wren at freegeek.org
Wed Jun 24 21:27:33 EDT 2009


Magnus Therning wrote:
> Erik de Castro Lopo wrote:
>> In Haskell there is an easy way around this. Variables can
>> be name a, a', a'' and so on. Since these aid in clarity
>> without forcing you to think up new variable names, I would
>> suggest that its a good idea to fix these warnings.

+1 (depending on context). If a more-helpful name than a' presents 
itself, I'll use that instead so as to avoid the problem of accidentally 
leaving off the apostrophe when typing quickly.

The only times I'd typically run into name shadowing and it's not a 
bug(!) is when doing worker-wrapper functions. In these cases I tend to 
use "go" as the name of the worker, as per Don Stewart's tradition. 
Again, if a more-helpful name presents itself then I'll use that. (And 
if a more helpful name presents itself, that usually means the lambda 
can/should be floated out.)


> Speaking from experience it's good to fix all warnings, since otherwise 
> there will be enough of them to cause a few "terminal pages" to scroll 
> by when you compile and then there's a real danger of not noticing real 
> errors.  I'd pass '-Wall -Werror' to ghc to force myself to do this :-)

+1.

When there are many "spurious" warnings, users often ignore everything 
so long as the compiler appears to have exited successfully. Which in 
turn means that "real" warnings which can't manage to halt compilation 
will make it through unnoticed. When these bugs are platform-dependent, 
it makes tracking them down _very_ annoying.

If certain warnings truly are spurious and unavoidable, then it's best 
to document this explicitly in the code by pragmas to disable the 
relevant warnings. This way the spurious nature of the warning is 
documented (for future maintainers, including yourself) and the 
distracting output of the compiler is removed as well. Unfortunately, 
GHC only gives whole-file scope for disabling warnings, but that could 
be fixed with enough work.


> Also from experience, I get a good feeling about software that compiles 
> without warnings.  It suggests the author cares and is indicative of 
> some level of quality.

+100.

As a user, if I receive code that does not compile cleanly, I consider 
it to be extremely suspect. Whenever possible I will avoid that code and 
find something better maintained (writing it myself if need be). If it's 
research code (and it usually is for me), then the authors' bozo-bits 
tend to flip on because I have little patience for computer scientists 
without software development experience.

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list