Hi all,
On Tue, Nov 24, 2009 at 12:21 AM, inspector_jouve <
kaush...@gmail.com> wrote:
> Still, an argument can be made in favour of syntax ^:=fmt.Print().
> When we invoke fmt.Print, there are 3 alternatives:
> - ignore the error
> - handle the error
> - return error to caller
>
> We need consistent syntax for these alternatives, which is:
> _:=fmt.Print(...)
> err:=fmt.Print(...)
> ^:=fmt.Print();
>
> What's wrong with idiom
> if err := fmt.Print("something"); err != nil { return err; }
>
> is not that it requires boilerplate, but rather that its meaning
> (invocation of fmt.Print) gets obscured by this boilerplate; there
> shouldn't be any "if" here. The form ^:=fmt.Print(...) is much more
> readable, not just faster to type.
I am surprised to find myself in relative agreement on the surface of
things. I've been writing lots of lines that amounted to this "return
the error (if any)" mantra, so a shorter way of doing this would be
welcome.
I *do* have a problem with hiding a pretty major control-flow decision
in a tiny piece of syntax that doesn't even remotely look like
control-flow. But I *could* get over that. :-D
But "return err;" may not be workable if you return multiple results.
A better translation might be
if locallyUniqueName := fmt.Print("something"); locallyUniqueName !=
nil { realErrorResultName = locallyUniqueName; return; }
which opens a whole new can of worms since now you're making even more
implicit. And what if you are inside a function that returns *two*
os.Error values? Now you have to say something like
realErrorResultName^ := fmt.Print("something")
or some other variation that makes the name explicit. :-/
So while I could be happy with the ^ syntax, the language purist in me
is queasy. And I think the proposal has little chance of gaining a
following @
golang.org because of trouble like that.
Cheers,
Peter
--
Peter H. Froehlich <
http://www.cs.jhu.edu/~phf/>
Senior Lecturer | Director, Johns Hopkins Gaming Lab