News for hackers. Stuff that matters.
Re:A Year’s Worth of Opinions about Objective-C by pnathan on Saturday December 14, 2013 @12:13PM (#6906228)
No, er, it's worse than Python.

`[nil methodname]` returns nil. Python et al have the decency to crash to the ground, look embarassed, and stop running.

Re:A Year’s Worth of Opinions about Objective-C by drewcrawford on Saturday December 14, 2013 @12:26PM (#6906271)
A better comparison here is with C/C++/go, e.g. other languages that are designed to be fast and compiled.

In any of those, dereferencing a null pointer is undefined. The compiler can literally emit code that plays Nethack in this situation [0]. ObjC's "nothing will happen" behavior is a significant improvement in safety against similarly-situated languages.

[0] http://feross.org/gcc-ownage/

Re:A Year’s Worth of Opinions about Objective-C by frou_dh on Saturday December 14, 2013 @12:34PM (#6906305)
You're incorrect about Go. It's in the spec that derefing a nil pointer will cause a runtime panic (~ an exception).

http://golang.org/ref/spec#Address_operators

Re:A Year’s Worth of Opinions about Objective-C by drewcrawford on Saturday December 14, 2013 @12:46PM (#6906344)
I stand corrected.
Re:A Year’s Worth of Opinions about Objective-C by pnathan on Saturday December 14, 2013 @04:05PM (#6907114)
Not defending "undefined" here, at all. I'd rather see the definition be, at least, exit(0xff) (or some other mechanism that reliably denotes "method not found", "message not found", etc).

I'm pretty sure I'm on record in HN for ranting about the fact that C & C++'s undefined & funny behavior literally created multimillion dollar industries in building analysis tools to cove their gaping problems. Which is why I am tend to boost Rust when possible (designed for correctness and determinism! woo!).

Dropping errors is not IMO better or worse. Both are silent failure modes.

Re:A Year’s Worth of Opinions about Objective-C by aaronbrethorst on Saturday December 14, 2013 @01:43PM (#6906567)
I find it far more convenient to type something like

    NSArray *a = [self somethingThatProducesAnArray];

    if (a.count > 0) {
      // do something
    }
    else {
      // do something else
    }
than

    NSArray *a = [self somethingThatProducesAnArray];

    if (a && a.count > 0) {
      // do something
    }
    else {
      // do something else
    }
Re:A Year’s Worth of Opinions about Objective-C by jawngee on Saturday December 14, 2013 @12:47PM (#6906346)
Well, first, you aren't calling a method, you are sending a message. It's different. So, of course, sending a message to somebody that isn't home is going to yield you an empty response.

Again, message, not method.

Re:A Year’s Worth of Opinions about Objective-C by pnathan on Saturday December 14, 2013 @04:00PM (#6907094)
Er... I would hope that I get some sort of Not At This Address notification (in some fashion - exception, special return value, option type, etc, etc, etc.). Dropping the ball like that by default is really not helpful in building correct systems.