4 ms·
Save for the Windows requirement, I think the author would actually really like Objective-C. The compiler checks types. Messages to `nil` resolve to `nil` (0),
by MaxGabriel 13y ago
Save for the Windows requirement, I think the author would actually really like Objective-C. The compiler checks types. Messages to `nil` resolve to `nil` (0), so no null-pointer exceptions. Automatic Reference Counting gives you memory safety.
- Strilanc 13y agoI don't think objective-C satisfies any of those constraints. It kinda gets close, but I don't think it does. The compiler checks types... but there's no generics. Given that the author is coming from C++, they probably want a type system that can represent 'vector of ints' vs 'vector of strings'. Nil doesn't cause null pointer exceptions... but it causes silent bugs, where you thought something was happening but it wasn't. The real problem (all types have an extra misbehaved value) is still present. Automatic reference counting gives you memory safety... but it can't handle cycles automatically, and obviously it doesn't apply to the C subset.
- protomyth 13y ago> but it causes silent bugs, where you thought something was happening but it wasn't. In Objective-C, it could be a silent bug or just intended behavior to send messages to a nil object. It is explained here: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/WorkingwithObjects/WorkingwithObjects.html http://developer.apple.com/library/ios/#documentation/cocoa/...
- Strilanc 13y agoOf course, the behavior may be intended. I've certainly taken advantage of nil doing nothing. I've also accidentally had a nil where it wasn't expected, and lost time figuring out why particular effects weren't occurring. More time than I would have lost if the mistake had caused an immediate exception. The same type of mistake is still possible (unexpected value), though the consequences are different, so I don't think it makes sense to say nil solves the null problem.