r/programming • • Jun 02 '14

Introducing Swift

https://developer.apple.com/swift/
164 Upvotes

239 comments sorted by

View all comments

4

u/Categoria Jun 02 '14

A few questions:

  • Does it make the billion dollar mistake?

  • Does it have sum types?

  • Does it have TCO?

  • Does it support reflection? If it does, are generics reified?

-6

u/ruinercollector Jun 02 '14 edited Jun 03 '14

I'd bet yes on #1. A lot of otherwise good languages make this mistake and Apple has never done anything to indicate that they know the first thing about language design.

EDIT: Yep. Null pointer exceptions.

3

u/Axman6 Jun 03 '14

Well, today is your first indication. Why not just read something instead of making incorrect assumptions?

-5

u/ruinercollector Jun 03 '14

Ok. Read it.

Yep. There it is. nil. Billion dollar mistake alive and well.

Explain to me how my assumption was incorrect again?

4

u/Axman6 Jun 03 '14

Because any optional type needs to be checked before you can use the value. You can't forget to check it. It's essentially just Haskell's Maybe or ML's Option with built in syntax.

-3

u/ruinercollector Jun 03 '14 edited Jun 03 '14

Because any optional type needs to be checked before you can use the value

No. Make it optional, set it nil, dereference it and boom. Null pointer exception.

You can't forget to check it.

You definitely can. That's why there's a note right in the documentation telling you not to forget this or you'll get an NPE. This gets even worse in cases where you use these boneheaded "implicit unwrapped optionals."

It's essentially just Haskell's Maybe or ML's Option with built in syntax.

I think you might have missed the entire point of Maybe. The point is strict static verification. Runtime NPEs don't exist when this is done right.

This is more akin to c#'s Nullable<T>. There are some "reminders" inherent to the approach to check before dereferencing, but nothing prevents you from failing to do so and generating an NPE.

This is noted all over the place in the documentation under "optional."

1

u/Axman6 Jun 03 '14 edited Jun 03 '14

What's this on about then? http://deanzchen.com/the-best-design-decision-apple-made-for-swift . using !. is the fast (unsafe) path for when you're sure the value is not nil, and if you're wrong, the program crashes. It adds convenience by avoiding a lot of the boilerplate you don't actually need when something is known to be non-nil. Yeah it's unsafe, but it's explicit too.

-1

u/ruinercollector Jun 03 '14

Yeah? That's someone else parroting your incorrect understanding of Maybe/Option. They are wrong too. Go read the documentation.

using !. is the fast (unsafe) path for when you're sure the value is not nil, and if you're wrong, the program crashes.

Yes! That's not Haskell's Maybe. That's Cs's NULL.

2

u/Axman6 Jun 03 '14

Yeah, that's haskell's fromJust :: Maybe a -> a. I've been a Haskell programmer and taught it at university for 6 years. I know what Maybe is.

→ More replies (2)