--
Is this an obvious programmer error?const debug = falsefunc main() {if debug {log.Println("Launching application")}...}
Hrmph. This seems like a place where the compiler could help prevent programmer error. I didn't think "I use this as a debugging technique" was a valid answer in response to incorrect code (see: unused variables). The code is clearly incorrect as a part of a final program, which is why the compiler drops it.The C# compiler warns about this, which has saved me on several occasions when I inadvertently edited valid code to cause a branch never to be called, and that's why I was surprised not to see an error from Go's compiler, since Go's compiler has always seemed to be proactive about preventing obvious programmer error.And to be honest, I don't really care what C does. We're not programming in C.
The C# compiler warns about this, which has saved me on several occasions when I inadvertently edited valid code to cause a branch never to be called, and that's why I was surprised not to see an error from Go's compiler, since Go's compiler has always seemed to be proactive about preventing obvious programmer error.
--
I suggest you review the md5 package for a non contrived, non trivial use of this feature.
http://tip.golang.org/src/pkg/crypto/md5/md5block.go
I suggest you review the md5 package for a non contrived, non trivial use of this feature.
Le 1 oct. 2013 06:10, <bradp...@gmail.com> a écrit :
>
> Just wondering if there was some sort of consensus on this (dead code in cases where it really isn't going to come alive - like after a return). IMO it seems contrary to the approach employed toward unused variables - where it's an error. One could argue that those are useful too while your editing your code...
>
There is a consensus: it is not an error and it is not going to change. You are also replying to a very old conversation which may not have anything to do with the current situation.
> If it's just an open issue and it is what it is, then fine. But as new comer to the language it struck me as odd and not totally in keeping with the rest of the Go philosophy (which is, by and large, awesome).
>
That's unfortunate. The rules are not going to change in Go 1.x because libraries that compile under Go 1.0 must continue to do so.
There is now a warning in govet about this.
Rémy.
Profiling can get this information, for some profilers. Will pprof do this?