|
|
|
|
|
by drakedrepar
1745 days ago
|
|
I understand the criticism from the author, but he missed a simple case to make the flow a bit better when a function returns a value and an error: From the article: if val, err := bar(); err != nil { // ERROR: val declared but not used
return err
}
fmt.Println(val) // ERROR: undeclared name: val If you want to use the val after the if, you could use it in an else: if val, err := bar(); err != nil { // ERROR: val declared but not used
return err
} else {
fmt.Println(val) // this is ok
} |
|