News for hackers. Stuff that matters.
Re:I Love Go; I Hate Go by andrewfromx on Tuesday August 02, 2016 @02:21AM (#12208097)
i was shocked by that at first too. Then I came to love it. It's sooooo go. Don't import stuff you aren't using. Don't declare a var and just leave it there un-used. When I go back to ruby and commit that crime, I see why golang did what it did. There's something magical about a golang program that will compile without error. It's worthy of checking in to git. And months later, there will be no unsed imports FOR SURE.
Re:I Love Go; I Hate Go by wruza on Tuesday August 02, 2016 @02:44AM (#12208190)
Stockholm syndrome in action. There are two phases: active development and release engineering. -Wall for former, -Wextra -Werror for latter. If someone is not disciplined enough to throw out unused variables/imports/whatever from release, Go will not save him from hell.
Re:I Love Go; I Hate Go by laumars on Tuesday August 02, 2016 @04:51AM (#12208575)
> Stockholm syndrome in action.

That's a very negative way of saying "that's not my personal behavioral preference"

> There are two phases: active development and release engineering. -Wall for former, -Wextra -Werror for latter.

Many of Go's idiosyncrasies are for code readability and maintainability, which is very much a part of active development. The point being to mitigate the likelihood you end up with spaghetti code (yes, I know you ultimately end up with code quality only as good as the developer, but some languages do still make the process easier than others)

> If someone is not disciplined enough to throw out unused variables/imports/whatever from release, Go will not save him from hell.

Except it does though, since that's the very behaviour you're complaining about.

Re:I Love Go; I Hate Go by ckastner on Tuesday August 02, 2016 @05:11AM (#12208655)
>> Stockholm syndrome in action.

>That's a very negative way of saying "that's not my personal behavioral preference"

In my experience, Stockholm syndrome is not used to describe personal behavioral preferences, but rather (unexpected) transitions between such preferences from the negative to the positive.

In the grandparent's own words:

>>> i was shocked by that at first too. Then I came to love it.

Re:I Love Go; I Hate Go by laumars on Tuesday August 02, 2016 @12:19PM (#12211027)
It's possible that's what he meant, but that's not how I understand the term.

Stockholm syndrome refers is a victim forming emotional bonding with his or her captor[1]. Which would mean in instances like this, where the "captor" is a voluntary choice of language, the term is used akin to "masochism" (albeit without the sexual element). In essence, saying "the pleasure from use feature x is derived from the pain of using feature x".

Which is why I commented that "Stockholm syndrome" is a needlessly colourful way if saying "I disagree".

[1] https://en.wikipedia.org/wiki/Stockholm_syndrome

Re:I Love Go; I Hate Go by junke on Tuesday August 02, 2016 @12:26PM (#12211077)
The "masochism" aspect makes Go part of Bondage and Discipline languages:

http://c2.com/cgi/wiki?BondageAndDisciplineLanguage

Re:I Love Go; I Hate Go by fauigerzigerk on Tuesday August 02, 2016 @08:21AM (#12209358)
Yes, but it requires that the victim has no way out. Stockholm syndrome is not just any unexpected change of preferences.
Re:I Love Go; I Hate Go by mtanski on Tuesday August 02, 2016 @09:41AM (#12209836)
The victim has no way out short of switching languages which may or may not be under their control.
Re:I Love Go; I Hate Go by fauigerzigerk on Tuesday August 02, 2016 @10:53AM (#12210370)
Stockholm syndrome, as far as I know, was observed in situations of physical threat to life or health with the only way out being death.
Re:I Love Go; I Hate Go by junke on Tuesday August 02, 2016 @05:11AM (#12208658)
> Except it does though, since that's the very behaviour you're complaining about.

No, the meaning was: if someone cannot handle unused things, that someone is screwed. Go will not save him in other aspects which require a little bit of discipline and are not checked by the compiler.

Re:I Love Go; I Hate Go by mcphage on Tuesday August 02, 2016 @07:55AM (#12209232)
> if someone cannot handle unused things, that someone is screwed.

So what you're saying is, there are two kinds of people—those who don't need the feature, and those for whom the feature isn't sufficient?

Re:I Love Go; I Hate Go by junke on Tuesday August 02, 2016 @08:28AM (#12209397)
User laumars was apparently misinterpreting part of a comment by saying that "unused" errors (not warnings, but errors) would in fact save the hypothetical "someone" that was claimed to be not disciplined enough to remove unused imports at release time. But the parent comment was in fact saying that the disability to handle something as simple as unused imports would prevent said programmer to accomplish the less trivial things that programmers are expected to do and for which no tools is a substitute for.

My personal view on this is that warning the user should be enough. The compiler designer is basically saying: I can't trust developers to fix warnings and it is my duty to protect them from their own laziness by enforcing a certain way of working. This apparently attracts a certain kind of people. I prefer to be the one telling the compiler what to do, instead of the reverse.

Re:I Love Go; I Hate Go by mcphage on Wednesday August 03, 2016 @11:13AM (#12218514)
> My personal view on this is that warning the user should be enough. The compiler designer is basically saying: I can't trust developers to fix warnings and it is my duty to protect them from their own laziness by enforcing a certain way of working. This apparently attracts a certain kind of people. I prefer to be the one telling the compiler what to do, instead of the reverse.

I'm with you there, I just was making a snarky comment :-)

Re:I Love Go; I Hate Go by sagichmal on Tuesday August 02, 2016 @06:22AM (#12208889)
This is literally the "perfect is the enemy of the good" fallacy.
Re:I Love Go; I Hate Go by sagichmal on Tuesday August 02, 2016 @04:39AM (#12208541)

    > There are two phases: active development and release 
    > engineering.
For you, perhaps. Go encourages you to think about your problem and develop it in the "release engineering" style from the very beginning. This is a virtue of the language, in my view.
Re:I Love Go; I Hate Go by junke on Tuesday August 02, 2016 @05:02AM (#12208620)
Ada is probably the most real-software-engineers-dont-hack language ever designed, and yet compilers have flags to control checks and warnings.
Re:I Love Go; I Hate Go by tigershark on Tuesday August 02, 2016 @09:20AM (#12209697)
No, there is no encouragement here. Go forces you to treat things that have always been just warnings in other languages as errors. And I wouldn't call a virtue something that doesn't give you a choice. I will be really pissed off if the language thinks that I'm so idiot that I need errors instead of simple warnings for the cases discussed here.
Re:I Love Go; I Hate Go by Klathmon on Tuesday August 02, 2016 @09:56AM (#12209926)
You are human, humans forget, humans get distracted, humans think that their situation is the exception that makes the rule.

A program doesn't suffer from that. Forcing these things to be showstoppers makes sure they NEVER become a problem, and the "cost" (in terms of the developer) is pretty small in the grand scheme of things.

Re:I Love Go; I Hate Go by tigershark on Tuesday August 02, 2016 @10:20AM (#12210107)
How in the world forcing someone to put an underscore before the import name or adding a dummy variable to use the import (both should be removed after the debugging) helps to avoid bugs instead of making easier to introduce them?
Re:I Love Go; I Hate Go by Klathmon on Tuesday August 02, 2016 @10:29AM (#12210195)
Adding a dummy var won't work, because then the dummy var will trip the "no unused variables" check.

Adding a _ to the front of an import is not the correct way to get around this "problem" during development, commenting out the whole import is the correct way. That way if you forget, it's not in your code anywhere (as it shouldn't be since it isn't used).

The underscore system is meant only to be used when you need to import for side effects (something that i've never actually needed to use).

Re:I Love Go; I Hate Go by tigershark on Tuesday August 02, 2016 @10:47AM (#12210326)
I have seen both suggestions in this thread: var _ = unusedImport

If you can't even agree among yourselves what is the right thing to do then I think that this is another sign that this go behaviour is not the proper solution.

Re:I Love Go; I Hate Go by Klathmon on Tuesday August 02, 2016 @11:42AM (#12210736)
If you have seen other people suggest that using a _ for an unused import that is unused because you commented out the variables using it, they are just doing more work for a worse result.

If you comment out code that uses an import, comment out the import too. It's not just the recommended way, it's the only logical way of doing things.

And how is having 2 opinions on how to do something a sign that this is not the proper solution? People still can't agree on tabs vs spaces (and probably never will be able to), that doesn't mean that all programming isn't a proper solution. There are also people that think using version control is a bad idea, but that doesn't mean that all version control is broken...

Re:I Love Go; I Hate Go by AnimalMuppet on Tuesday August 02, 2016 @12:46PM (#12211233)
> Stockholm syndrome in action.

So here's a language feature that you don't like. Other people don't like it and then, after they get more experience, decide they like it after all. And you call it Stockholm syndrome? By saying that, you're asserting that there is no possibility that the feature could possibly be anything other than harmful. That's... pretty arrogant, actually. Both the language designers and the users who like it are objectively wrong, and you're right?

Look, you don't like it. That's fine. It doesn't work with the way you like to develop. That's fine, too. But your assertion is that it is worse than useless for all users, and that's a bit more than you have the knowledge to assert.

Re:I Love Go; I Hate Go by zaphar on Tuesday August 02, 2016 @09:13AM (#12209656)
This may work for you code. But are you sure that all the libraries you use also follow that rule? Are you going to audit all of those projects and their dependencies to validate they follow the same best practices as you?

The end result of Go's opinion on warnings is that you know a certain class of bugs in not present anywhere in both your code and all of your dependencies. While it's true that people and teams that follow the best practices around warnings also tend to follow the best practices for other things but there is no guarantee for the ecosystem in a language that allows warnings, and no project lives in a vacuum.

Re:I Love Go; I Hate Go by hehheh on Tuesday August 02, 2016 @09:31AM (#12209767)
This is an easy problem to solve.

The Go compiler could simply include a bit in the resulting binary/library that indicates whether or not it was built with the "disable-unused-variable-error" flag. If you're using a library that was built with that flag the compiler can simply refuse to compile your code without that flag, forcing you to acknowledge the problem head-on.

Re:I Love Go; I Hate Go by zaphar on Tuesday August 02, 2016 @10:58AM (#12210408)
This doesn't solve the problem. It just makes you aware it might be there. It doesn't keep the ecosystem clean.

The result will be that everyone compiles with that flag on so they can use the libraries they want/need. It's in fact actively worse than just allowing warnings. At least if you allow warnings that way you aren't forced to lower your own codes protection just because one of your dependencies does.

Re:I Love Go; I Hate Go by wruza on Tuesday August 02, 2016 @07:01PM (#12214113)
Complaining about unused import doesn't solve anything IRL, if we talking about solving something. Problems in code are complex diseases, and cleaning unused entities is like washing your hands, not like taking a cure. And hand cleanliness checks is too idiotic measure to cure brain cancer. Of course all our problems are still here in both cases, but at least with Go we will die clean for sure.
Re:I Love Go; I Hate Go by hehheh on Tuesday August 02, 2016 @02:21PM (#12211965)
If a library is so popular that "everyone" uses the flag so they can use it, surely someone can be convinced to remove the unused import statement. If the ecosystem makes that difficult then we're talking about a totally different problem.
Re:I Love Go; I Hate Go by patates on Tuesday August 02, 2016 @03:07AM (#12208274)
Why on earth would the language hinder you from iterating fast with a flag, and then convert all the warnings to errors when you run the full tests?

For example, most JS linters do that check and as a general rule, the build servers would reject the commit when the linter complains. I actually have a (very hacky) plugin to ESLint that automatically removes unused variables before `hg push`. It's totally not optimal, as in, you can still run/compile/transpile/whateverify the code with default options, but a language with no backwards compatibility worries can just add a flag to override strict checks to make a developers life easier, can't it?

I understand not implementing something that perhaps may not fit the language well or is so complicated that it really needs a lot of thought (read: generics). But this decision seems to be dogmatic at best.

I have the exact love/hate relationship with Go as the author of the article.

Re:I Love Go; I Hate Go by millstone on Tuesday August 02, 2016 @03:35AM (#12208348)
Devil's advocate: if you can disable -Werror, then users will disable -Werror, and we'll end up in a C-like situation where everything warns all the time, and real problems get buried. Better to inflict some pain during development if it keeps the Go source corpus hygienic.

One under-appreciated consequence is that this policy limits Go to one implementation. Say I write an alternative implementation of Go, that has a different "unreachable code" detector. If I issue errors on new cases, then I'm incompatible with lots of existing Go code. If I fail to issue errors, then code developed against me may be incompatible with the standard Go. The effect is to suppress alternative implementations.

Better to just put my smarts into a linter, which is then just reinventing compiler warnings under a different guise.

Re:I Love Go; I Hate Go by patates on Tuesday August 02, 2016 @03:39AM (#12208354)
> Devil's advocate: if you can disable -Werror, then users will disable -Werror, and we'll end up in a C-like situation where everything warns all the time, and real problems get buried.

I already mentioned that case. To be more clear: Let it not build with default options. Make it not `go get`able.

Let me develop first, and not force me to optimize prematurely.

Re:I Love Go; I Hate Go by millstone on Tuesday August 02, 2016 @04:55AM (#12208588)
Enforcing -Werror at the "go get" phase would achieve 90% of the benefit with 10% of the pain. It would be a big improvement.
Re:I Love Go; I Hate Go by laumars on Tuesday August 02, 2016 @08:35AM (#12209434)
> Let me develop first, and not force me to optimize prematurely.

I'd argue that cleaning unused code as you work isn't optimisation. It's a part of the refactoring process of development which is something that must happen during the main development phase.

But arguments for and against aside, most developers don't see these kinds of compiler errors that often as you'd generally be commenting out unwanted code while you're prototyping. The biggest annoyance is easily the imports and pragmatically that still takes up such an insignificant amount of effort when compared with the overall time spent writing code in any particular language. Which is why many Go advocates are willing to put up with it.

Re:I Love Go; I Hate Go by patates on Tuesday August 02, 2016 @09:07AM (#12209621)
> It's a part of the refactoring process of development which is something that must happen during the main development phase

How is it refactoring if my code never builds in the first place?

> pragmatically that still takes up such an insignificant amount of effort when compared with the overall time spent writing code in any particular language. Which is why many Go advocates are willing to put up with it.

It's not a time problem. It's a focus problem. I'm working on something and then out of nowhere, receive compilation errors, which aren't urgent at all, but they distract me anyway. Even if this were indeed a very small problem, I still don't see why something most people see as a problem is pushed down the developers throat with false, dogmatic reasoning. Don't get me wrong: I have huge respect to the people who created go. I just don't like when people defend all the choices they made as "one true way".

Re:I Love Go; I Hate Go by laumars on Tuesday August 02, 2016 @09:52AM (#12209905)
> How is it refactoring if my code never builds in the first place?

Why would you be typing in imports that you've never used? I guess that could happen, but the more likely scenario you had used them at some point, even if just briefly, and then you're refactoring the code.

> It's not a time problem. It's a focus problem. I'm working on something and then out of nowhere, receive compilation errors, [...] pushed down the developers throat with false, dogmatic reasoning

Please don't be so melodramatic. It doesn't happen "out of nowhere" - you've purposely requested the compiler runs. And if you're compiling then you're doing so to either test your code compiles or test it runs - in either case your focus has already intentionally shifted from writing code to testing and debugging it.

> Don't get me wrong: I have huge respect to the people who created go. I just don't like when people defend all the choices they made as "one true way".

I'm not defending it. I'm saying people are being melodramatic about the actual inconvenience it causes. In all of the years I've been writing Go, I think I've spent just as much time coding around that annoyance than I've spent in this thread chatting about it. The difference being, occasionally that annoyance is useful where as the internet arguments about it literally serves no benefit to anyone.

Re:I Love Go; I Hate Go by patates on Tuesday August 02, 2016 @10:05AM (#12209995)
> Please don't be so melodramatic. It doesn't happen "out of nowhere". You've purposely broken your development focus to compile and unit test.

No, I'm compiling to see if my changes still allow the tests to pass. This is a huge problem if you're doing TDD. The main argument you make is that it's not such a big problem and I think the number of people complaining says otherwise. Or maybe we developers just like being melodramatic. I honestly can't tell. Maybe what triggers such passion is go being very close to a perfect tool for certain things and those annoyances look like small black dots in a perfectly white surface (That sounded dramatic as well, what's wrong with me? :) )

Re:I Love Go; I Hate Go by laumars on Tuesday August 02, 2016 @10:21AM (#12210115)
I don't have a great amount of experience with TDD specifically, so maybe I am underestimating the inconvenience this causes some developers. :)
Re:I Love Go; I Hate Go by coldtea on Tuesday August 02, 2016 @09:08AM (#12209625)
>Devil's advocate: if you can disable -Werror, then users will disable -Werror, and we'll end up in a C-like situation where everything warns all the time, and real problems get buried.

Isn't it implied that programmers are adults?

Re:I Love Go; I Hate Go by unscaled on Tuesday August 02, 2016 @11:21AM (#12210585)
Go's entire philosophy is that developers are a bunch of incompetent slobs, and it's the language's job to fix that.

I can't say I blame Rob Pike for not trusting developers, and I've definitely seen more than one case of a C/C++ codebase riddled with thousands of compiler warnings that were just ignored en masse during compilation.

There is another side of the coin, which is that experienced and disciplined developers who think they can take care of themselves, thankyouverymuch, would end up feeling limited by Go.

Re:I Love Go; I Hate Go by wtbob on Tuesday August 02, 2016 @09:19AM (#12209690)
> Isn't it implied that programmers are adults?

It's one of those irregular situations:

I'm a senior developer.

You're an adult programmer.

He's a stark raving juvenile lunatic.

Re:I Love Go; I Hate Go by twic on Tuesday August 02, 2016 @07:05PM (#12214135)
You set things up so you can't disable -Werror on the build server, and all this is moot.

The point about alternative implementations is interesting. Java has a comparable situation with unreachable code; the language specification has a simplistic definition of what unreachable code is, and makes it a compile-time error. A smart compiler can find more cases of unreachable code, but isn't allowed to make them errors. So it makes them warnings. It doesn't seem to be a big impediment to alternative implementations in practice.

Re:I Love Go; I Hate Go by ansible on Tuesday August 02, 2016 @10:04AM (#12209981)
Why on earth would the language hinder you from iterating fast with a flag, and then convert all the warnings to errors when you run the full tests?

There is a cost to this too. It is another option. Another thing to document and maintain. Another thing for developers to learn about. Another thing for newbies to be confused by. Another thing that will asked about on the mailing list.

Re:I Love Go; I Hate Go by junke on Tuesday August 02, 2016 @03:49AM (#12208390)
Define unused imports/variables as warnings but produce an executable that first prints "This program is for debugging purposes only, it built with 133 warnings." and beeps loudly.
Re:I Love Go; I Hate Go by nomel on Tuesday August 02, 2016 @04:32PM (#12213165)
Nothing like a little public shaming to keep your code in check.
Re:I Love Go; I Hate Go by greyskull on Tuesday August 02, 2016 @02:41AM (#12208175)
What about just really obnoxious compiler warnings that can't be disabled?
Re:I Love Go; I Hate Go by majewsky on Tuesday August 02, 2016 @04:29AM (#12208516)
More than once I've built some free software from source, only to witness literally thousands of warnings being spit out during the compile phase.
Re:I Love Go; I Hate Go by Sean1708 on Tuesday August 02, 2016 @07:14AM (#12209063)
I would argue that that's becuase checks had to be enabled not because they could be disabled.
Re:I Love Go; I Hate Go by barrkel on Tuesday August 02, 2016 @04:57AM (#12208601)
Unused Ruby variables stand out like a sore thumb, if you have a linter configured with your editor. I use emacs with rubocop through flycheck.