News for hackers. Stuff that matters.

Ask HN: Are compiler errors for unused code necessary?

Languages like Zig and Go refuse to compile when you don't use an argument in a function, don't use a local variable or have an unused import. This breaks the hypermodern C flow

An common suggestion is a '-no-warn-unused' flag, and the objection is 'if a feature exists, it will be used in production'

I haven't heard of someone suggesting to ignore dead code on 'go run .' and erroring on 'go build', but it looks like the perfect solution

( 3 comments | 2 points | on HN )
Re:Ask HN: Are compiler errors for unused code necessary? by dabinat on Tuesday February 17, 2026 @05:55PM (#47054610)
It can be useful at letting you know of things that might be bugs. Like maybe you intended to use x in a calculation but forgot. Or maybe you intended to call func2() but actually called func1() instead. I feel like it should be a warning more than a hard error though.
Re:Ask HN: Are compiler errors for unused code necessary? by mboon on Tuesday February 17, 2026 @05:37PM (#47054439)
A lot of users including myself run 'go build...' and execute the binary in development. It is recommended by systems file watching services like air.

I think the flag works fine as a solution.

Re:Ask HN: Are compiler errors for unused code necessary? by PaulHoule on Tuesday February 17, 2026 @05:46PM (#47054522)
I hate dead code. So many times I've spent two days understanding and maintaining some code and found that one of those days was wasted.