Re: Value of type '[AnyObject]!' has no member 'Generator'
Re: Value of type '[AnyObject]!' has no member 'Generator'
- Subject: Re: Value of type '[AnyObject]!' has no member 'Generator'
- From: Graham Cox <email@hidden>
- Date: Tue, 06 Oct 2015 09:44:32 +1100
> On 6 Oct 2015, at 5:42 am, Jens Alfke <email@hidden> wrote:
>
> Optionals (under various names) have been in use in functional languages for a long time, e.g. Haskell, OCaml, Scala, ML. They’ve been added to Java recently and are being proposed for C++.
>
> Optionals are, among other things, a way to bring NULL pointers (which Tony Hoare, who arguably invented them, has called a “billion-dollar mistake”*) under control by adding them to the language’s type system. Null pointers are like the language saying “here’s a value, but it might crash your program if you try to use it without checking it first.” Optionals are like “here’s a value, and you have to check it first before using it, or you’ll get a compile error.”
>
> They do add new and exciting compile errors, but you can think of those as substituting for runtime errors/crashes that could be a lot harder to debug. You can think of the “!!” situation as the compiler saying “you dereferenced a property of a possibly-nil object, and the property value is an array that itself might be nil; how are you going to handle those cases?"
>
Now this is much more like it - an explanation that can be understood by a not-yet-Swiftian (and lets face it, how many people are familiar with all those other languages as well?). That’s not to criticise what Roland said, I’m sure once you’re into Swift it makes perfect sense, but for someone on the outside, it sounded like impenetrable jargon, as you get with any specialist field you’re not familiar with.
As for the “billion-dollar mistake”, I’m not sure what could have been done otherwise until recently - a pointer must be able to express “not pointing to anything” and zero is as good a value as any - just a pity that’s a valid address in many (most?) cases. Optionals may solve that more elegantly, but I bet they would have been way to much overhead in a 1970s system - even compilers were pretty half-baked at that time.
Anyway, thanks for the explanation, it does make a lot more sense now.
—Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden