|
It's Not Magic
Writings of a techie wizard
|
|
Category: rants
Tue, 25 Sep 2012
Python v. Go Redux: Error Handling
Some time ago I posted about Go vs. Python with regard to delimiters. I now have another reason to prefer Python to Go: Go's error handling (hat tip: Hacker News). To briefly see the issue, consider the following snippet of idiomatic Python:
What happens if the
Now consider the corresponding snippet of Go, taken from the blog post linked to above:
Two things jump out at me by comparing the above snippets (leaving aside all the stuff about delimiters, etc. that I ranted about last time). First, if the file open fails, Python guarantees that the "do something with f" code will not execute; Go depends on the programmer putting something in the "handle failure to open file" code that does that. Of course, fixing that particular wart is easy:
Which of course begs the question, why didn't the blog post write it that way? Perhaps because the poster expected the "do something with f" code to test for a valid file object? In other words, they really intended to write this:
(I'm assuming that testing for a non-nil This by itself may not be a huge issue; but now consider the second thing
that jumped out at me. In Python, I only need to wrap the Why might you not want to? Suppose I'm writing a library to open and parse a particular type of file. This library might be used by a variety of applications; some might be end-user apps for editing the file, while others might be server-side apps that just want a parsed object they can use to read attributes from. The way that a failure to open the file should be handled is very different for these two types of apps: the end-user app needs to display a message to the user (at least if it wants to be usable), while the server-side app probably should just log the error and go on, or perhaps send an urgent page to a sysadmin. If I'm writing this library in Python, handling all this is simple, because
error handling is uncoupled from normal functionality. Each app's code simply
catches the So once again, while it's great that people are trying new things with programming languages, I'm still sticking with Python. Wed, 22 Aug 2012
I Miss Konqueror
I recently came across this from Jamie Zawinski, and one of his gripes with Firefox struck a huge chord with me:
Thu, 08 Mar 2012
Delimiters Suck
A while back I explained why I use Python, not Lisp. However, after reading this review of Go, I realized that I left out something important, something that sets Python apart from pretty much every other language out there, and certainly from every "C-oid" language, which is all that the author of the review seems able to find himself wishing for. Sat, 03 Mar 2012
One Rant Deserves Another
Cary Sherman, the CEO of the RIAA, is upset. He says those mean and nasty Internet companies shut down SOPA and PIPA by spreading misinformation and claiming it was fact. Well, after reading his recent op-ed in the New York Times, I will certainly concede that Mr. Sherman ought to know about that sort of thing, since he is evidently an expert at it. Just for fun, I thought I would post some examples. Mon, 09 Jan 2012
The Latest From The SOPA Front
Tue, 29 Nov 2011
Don't Tread On Our Internet: The Sequel
Wed, 23 Nov 2011
Yet Another Reason NOT To Tread On Our Internet
This is just a quick update to yesterday's post. According to Ars Technica,
Tue, 22 Nov 2011
No, Really, DON'T Tread On Our Internet
I've posted twice now about the Protect IP Act, or SOPA (the former is the Senate version, the latter is the House version), which is the latest attempt on the part of big media companies to put a stranglehold on the Internet. Sat, 10 Sep 2011
Why I Run Linux
Having spent enough time using all three of the major OS's to have a decent understanding of their flaws, it's easy to explain why I use Linux whenever I have a choice: its flaws are much easier to manage. Mon, 08 Aug 2011
Two Cultures Redux: But Wait, There's More
The New York Times, which is certainly a bastion of the liberal arts types if anywhere is, has been running a debate about law school that is similar to the one about college in general that I discussed in my post a couple of weeks ago on the two cultures. |
Wizard Projects
Open Source Development
Open Source Releases
Python Recipes
Fun Stuff
Shameless Plugs
Copyright © 2011-2013
by Peter A. Donis All Rights Reserved |