On Tuesday, 1 August 2023 at 18:14:56 UTC+1 DrGo wrote: Fair enough. But many would prefer shorter functions if there is no loss to explicitness or clarity.
I don't think putting the assignment and return statement on the same line is very clear. I would prefer the compiler to enforce something like the following: func CopyFile(src, dst string) error { r, err := os.Open(src) *orelse* { return fmt.Errorf("copy %s %s: %v", src, dst, err) } defer r.Close() w, err := os.Create(dst) *orelse* { return fmt.Errorf("copy %s %s: %v", src, dst, err) } err := io.Copy(w, r) *orelse* { w.Close() os.Remove(dst) return fmt.Errorf("copy %s %s: %v", src, dst, err) } err := w.Close() *orelse* { os.Remove(dst) return fmt.Errorf("copy %s %s: %v", src, dst, err) } } What do you intend to happen to the error instances after the orelse block? Are they valid outside the orelse block? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6dd26b81-23b3-4226-9eb9-3bc47b2bee54n%40googlegroups.com.