unused local functions

349 views
Skip to first unread message

Johann Höchtl

unread,
Apr 3, 2011, 3:17:38 PM4/3/11
to golang-nuts
Go helps me a lot to keep my code clean - unused variables, unused
labels.
I wonder if unused local functions should be an error too. With
multiple files defining the same package "namespace" impossible to
catch by the compiler?

Steven

unread,
Apr 3, 2011, 3:27:19 PM4/3/11
to Johann Höchtl, golang-nuts
That wouldn't make much sense. A function is a block of code that you can skip if you're not interested in it, so it doesn't really constitute clutter. And often, you write a function before you write the code that uses it, and you compile it to check if its correct. Removing as-of-yet unused variables and labels is one thing. Removing entire functions that just haven't been used yet is another.

Matt Joiner

unread,
Apr 4, 2011, 7:56:13 PM4/4/11
to Steven, Johann Höchtl, golang-nuts
I don't see the difference. It's both equally annoying and useful to
be warned about unused locals. Their type is irrelevant. Unused local
constants should warn too.

Russ Cox

unread,
Apr 4, 2011, 10:22:11 PM4/4/11
to Matt Joiner, Steven, Johann Höchtl, golang-nuts
I have been writing some C code with gcc -Wall -Werror recently.
It makes prototyping code somewhat difficult to be told
"you didn't use that function, go fix it" when you're just
trying to test what you've got so far, or commenting out
calls that are possibly causing trouble. Of course the same
is true for warning about unused local variables too.

The difference is that, in Go, because of :=, an unused
local variable is very often a bug, while an unused unexported
function is much less often a bug.

Russ

Camilo Aguilar

unread,
Mar 6, 2015, 8:00:53 PM3/6/15
to golan...@googlegroups.com, anac...@gmail.com, stev...@gmail.com, johann....@gmail.com, r...@golang.org
What about unused constants? I've been noticing the compiler doesn't say anything about them. Go 1.4.2 darwin/amd64
Reply all
Reply to author
Forward
0 new messages