News for hackers. Stuff that matters.
Re:Why I’m not leaving Python for Go by belorn on Sunday September 23, 2012 @08:41PM (#4562685)
I would guess that most (99%) of C programmers are lazy or has an rapid programming style then. Its a rare thing to see C source code that even do the simple thing like wrapping every write/read/print call with a loop that detects eintr. In my years of programming, I have yet to stumble on a other programer who even knows that one should be doing this.

Looking at c libraries and their example code, almost every time, the example lacks error handling. Its almost like people avoid doing error checking in C code because of the cumbersome amount needed to be done in order to check each and every time. If an example code would include error checking, the number of lines can easy increase 3-4 times the original size.

Re:Why I’m not leaving Python for Go by kisielk on Sunday September 23, 2012 @11:11PM (#4563036)
In Go if you use the return value of a function you must also assign the error to something, either a variable or explicitly ignore it by assigning it to _. It was designed this way specifically to avoid the problem of not checking error conditions in C code.
Re:Why I’m not leaving Python for Go by osi on Monday September 24, 2012 @08:51AM (#4564350)
This breaks down when the method you call has no return value other than an error. In that case it is easy to forget.
Re:Why I’m not leaving Python for Go by xal on Sunday September 23, 2012 @09:31PM (#4562809)
That's true but also C's error reporting differs greatly between libraries. Each library has a learning curve in how it wants it's errors checked. From the top of my head, 10 years after writing any C code there is check against NULL - guess the error, check against minus values - lookup minus values in a table, check against 0 - call method to get error string and many more.

Go standardises this in a super clean way. Every method that can error will return an error. If you try to write a method that calls methods that can error and you don't return an error then you will be extremely aware of that. After a few days of Go it will be physically painful to write code that eats errors.

So what Go did was to take the return parameter style of error reporting, mix in multiple return values to make that not suck and then optimize towards the local maxima of programming comfort within this paradigm.

The result - as anyone who has been writing go for a few months can tell you - is something that works incredibly well. I'd say it works better then exceptions style all but that may be my personal preference.

Re:Why I’m not leaving Python for Go by slurgfest on Monday September 24, 2012 @12:04AM (#4563158)
I don't doubt that Go is usable and reflects an attempt to rationalize C's (non) conventions, which is a goal I appreciate. but it certainly isn't false for Python that 'the result - as anyone who has been writing [Python] for a few months can tell you - is something that works incredibly well.'
Re:Why I’m not leaving Python for Go by ams6110 on Sunday September 23, 2012 @08:56PM (#4562723)
To be fair, most sample code I've seen, regardless of language, usually does not include error handling. Why not? Probably because it would detract from the main point being illustrated.
Re:Why I’m not leaving Python for Go by davvid on Monday September 24, 2012 @04:47AM (#4563779)
In my years of programming, I have yet to stumble on a other programer who even knows that one should be doing this

That's a bold statement. Nice to meet ya! I'm no PC-Luser! ;-)

The PC-lusering problem is mentioned in "worse is better", so I would hope a fair number of folks know about it. Every good code base I've seen uses EINTR wrappers, but it is true that many folks I've met don't know about it.

Hey now.. it's not just C programmers, though. We have to use the same EINTR-retry loops in python too, sometimes:

https://github.com/git-cola/git-cola/blob/master/cola/decora...

I like C, Python, and Go. There's no reason to take sides, IMO. These are all highly effective tools.

Re:Why I’m not leaving Python for Go by pm215 on Monday September 24, 2012 @07:24AM (#4564079)
EINTR is a flaw in Unix's syscall model: it forces on every single application the responsibility for dealing with something that should have been handled at a lower level. That's unrelated to C's error handling style; it would be just as ugly if every write() call had to be wrapped in a try-catch block to retry when an InterruptedException was thrown, and people would still forget to write that ugly boilerplate.