News for hackers. Stuff that matters.
Re:Playing with Go: Embarrassingly Parallel Scripts by drivebyacct2 on Monday December 03, 2012 @10:54AM (#4865935)
So many ignored errors. :(
Re:Playing with Go: Embarrassingly Parallel Scripts by stusmall on Monday December 03, 2012 @11:25AM (#4866124)
This is one of the things I love about go. If he wants the return value but doesn't want to address the errors, he has to actively do it. It makes you think twice when you are putting a _ for an error return. And now to another programmer coming in to maintain it, they stick out like a sore thumb.
Re:Playing with Go: Embarrassingly Parallel Scripts by saraid216 on Monday December 03, 2012 @06:26PM (#4868568)
I know zero Go (it's a little far down on the to-learn list), and maybe he edited it, but I went back and read the GP's code and didn't see anything that looked like ignoring errors.

Is it the two ", _" things?

Re:Playing with Go: Embarrassingly Parallel Scripts by stusmall on Monday December 03, 2012 @07:08PM (#4868735)
So for this line of code:

file_in, _ := ioutil.ReadFile("domains.txt")

It says call ReadFile. In go a function can return multiple values. ReadFile returns an byte array and an error value. Normally you'd check to see if err is nil, if it is then no error happened. If it isn't you can check it out for information about the error and handle it.

A unique feature about go is that declaring a variable and never using it is an error and not a warning. Actually there aren't even compiler warnings. Either it is right or wrong. This means if he had called:

file_in, err := ioutil.ReadFile("domains.txt")

but never checked err it would not build. So to get the byte array but not the error you use the _ symbol to tell it to throw away that return value. This is what I was on about in that you have to actively ignore error handling if you want a return value.

Re:Playing with Go: Embarrassingly Parallel Scripts by saraid216 on Tuesday December 04, 2012 @05:08AM (#4870210)
> A unique feature about go is that declaring a variable and never using it is an error and not a warning. Actually there aren't even compiler warnings. Either it is right or wrong.

Ahhh. Nice. That sounds like a feature I could get behind, too. Thank you.

Re:Playing with Go: Embarrassingly Parallel Scripts by frou_dh on Monday December 03, 2012 @09:34PM (#4869223)
It seems tantalising for the compiler to also protest when return values of type error are not assigned to anything. An obvious inconvenience being that use of fmt.Println and similar would suddenly become noisy.
Re:Playing with Go: Embarrassingly Parallel Scripts by jameskilton on Monday December 03, 2012 @11:04AM (#4865985)
It's a one-off script, I didn't really care about errors. If this was something run regularly inside of a bigger application yes I'd have full error handling.
Re:Playing with Go: Embarrassingly Parallel Scripts by ImJasonH on Monday December 03, 2012 @04:23PM (#4867926)
But tiny throwaway scripts get built up into huge applications all the time, sometimes by other people who don't have the mental TODO to go back and handle errors.