News for hackers. Stuff that matters.
Re:Erlang and code style by a_bonobo on Tuesday May 20, 2014 @08:29PM (#7776042)
First of all, that wouldn't work in go, it would complain that you don't use the err variable, you could change it to:

    file, _ := os.Open("file.go")

The underscore tells the compiler to ignore the error. And yes, file is <nil> now!

As a sidenote, it would be more idiomatic to do this:

    if _, err := os.Open("file.go"); err != nil {
      //handle error
    }
    // Do stuff with file
This has bitten me before - if you use a non-existent key on a map of strings (or dictionary, or hash, however you call it) you get "" and an error back.

    my_hash := make(map[string]string)
    value, ok := my_hash["no_key"]
value is "", ok is 'false'.

What type you get back exactly from a bad request depends on the type of call, but you always get an error back! Maps storing ints return 0, maps storing strings return "", etc.

Go always forces you to look at each error, since errors are always different.

Re:Erlang and code style by jamwt on Tuesday May 20, 2014 @09:44PM (#7776304)

    file, err := os.Open("file1")
    // complains if you don't check err
    file2, err := os.Open("file2")
    // no problem, no need to check err.
Re:Erlang and code style by signa11 on Tuesday May 20, 2014 @11:54PM (#7776616)
if _, err := os.Open("file.go"); err != nil {

      //handle error

    }

    // Do stuff with file

but you need to split that into 2 lines, just like the good article says i.e.

   file, err := os.Open("abcd")

   if err != nil {

      // <handle os.Open(...) errors

   }
otherwise, outside the 'if {...}' block, 'file' is undefined.