Google's new "Go" language
Posted Nov 12, 2009 6:42 UTC (Thu) by
nevyn (subscriber, #33129)
In reply to:
Google's new "Go" language by epa
Parent article:
Google's new "Go" language
As another poster pointed out, having to check return values manually is incredibly losing compared to exceptions.
I disagree. 99% of the time exceptions occur for things that aren't "exceptional", so you have to work around it by catching them everywhere (or create helper functions which catch and return error values). They are also completely invisible exit points from functions, where you have no control over the state of the program ... so if you catch them at higher levels you can't do much more than print a nicer traceback.
With a bit of imagination they could have done something to satisfy both the pro- and anti- exception camps.
I don't see how you can think your success() example is better than their "multiple return values, one of which is an error indicator". But even if you do, you can easily convert from their style to win3^W yours.
A good thing to think about is probably the problem of "open". Pro-exception people tend to want this to throw FileNotFound and PermissionDenied ... because a majority of the time you are reading files that are there and readable.
Anti-exception people tend to hate exceptions here because: 1) Not being "a majority" isn't even close to "exceptional". 2) Putting an exception here makes it ugly as hell to do "open if you can" type operations. 3) #2 often means the resulting code is worse, generally (Eg. python is so bad it's common practice to just use os.path.exists and have a race condition).
Then you have the general complaints for things like at least 99% of the time it's just not that hard to check the return value of open() and dtrt. and anyone with a little experience does it. And that having exceptions on open means that if you add an open call to existing code you need to make sure it can handle the file exception being thrown there, or more likely you have to catch it anyway and do something else (thus. you just have more lines of code to always check the return value anyway).
(
Log in to post comments)