News for hackers. Stuff that matters.
Re:Go proposal: Leave “if err != nil” alone? by butteroverflow on Friday June 28, 2019 @01:46PM (#20306926)
>PHP

Oh no, don't even put them in the same sentence. I am no fan of Go, but its error handling approach is beautiful compared to PHP. Every time I call an internal function I have to go through the docs — does it return a NULL, an int, a boolean, or something else? Does 0 signal an error condition, or is it a valid value? Do I have to perform a strict check for NULL/false then? Or is it -1 (see link below)? The situation is generally better with third-party libraries though — they tend to just throw exceptions (if that matches your definition of "better").

https://www.php.net/manual/en/function.openssl-verify.php

Re:Go proposal: Leave “if err != nil” alone? by alyandon on Friday June 28, 2019 @02:41PM (#20307538)
Rightly or wrongly, many PHP functions are thin wrappers around third-party C libraries and they tend to return values without interpretation of the results.

For your example of openssl_verify see https://linux.die.net/man/3/x509_verify_cert

It can certainly be confusing but at least it is documented.

Re:Go proposal: Leave “if err != nil” alone? by PhasmaFelis on Friday June 28, 2019 @04:10PM (#20308375)
I'm curious who it was who first started implementing those wrappers and thought "Yeah, this is good enough."
Re:Go proposal: Leave “if err != nil” alone? by mkr-hn on Friday June 28, 2019 @04:22PM (#20308476)
The late '90s and early '00s were a strange time. It had plenty of shotguns aimed at feet and no one to suggest a better approach. At least no one with enough reach.

Also [1]:

>> "I don't know how to stop it, there was never any intent to write a programming language [...] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way"

I assume he's better at it 16 years later.

[1] https://en.wikipedia.org/wiki/PHP#History

Re:Go proposal: Leave “if err != nil” alone? by mey on Friday June 28, 2019 @02:24PM (#20307366)
PHP is a bit of hyperbole, but otherwise correct. :) Ruby, Python, Javascript all support exceptions. PHP does support exceptions, but it's core libraries do not use them. Gotta trust PHP to do the worst of both worlds approach. Perl 6 has it but not sure where the world is in the 5 -> 6 migration. I'm not going to count eval(...) as exception handling as a language feature in Perl 5. :)
Re:Go proposal: Leave “if err != nil” alone? by chromatic on Friday June 28, 2019 @02:48PM (#20307621)
I'm not going to count eval(...) as exception handling as a language feature in Perl 5. :)

You should. It's a perfectly valid exception handling mechanism. It's unfortunate that the name "eval" is overloaded for two separate behaviors:

  * catch exceptions thrown as strings or objects

  * compile and execute code from a string
Other than the name, they're different behaviors.
Re:Go proposal: Leave “if err != nil” alone? by mey on Friday June 28, 2019 @03:14PM (#20307872)
I am not a Perl expert. Only worked on some simple install tools written it a couple years ago. Re-reading docs, eval(...) traps exceptions (die), but requires manual inspection of error state, instead of automatically halting. It operates more like Go/C/PHP in that regard.