Prototyping what Swift can look like in educational settings

Jens -

I apologize for having annoyed you, but this thread has been very informative for me.

I was under the misconception that Swift was more similar to Java and .NET than to C, C++ and Obj-C. Your statement - The designers of Swift do not like exceptions. - clears up some of my misunderstanding of fundamental principles guiding Swift design. And thank you Brent Royal-Gordon - your explanation was of great help in furthering my understanding of those design decisions.

I was seriously considering moving toward the use of Swift as the programming language of the future for my companies' mission-critical business application systems, but the knowledge I've gained in this thread has disabused me of that.

Sincerely,
Don Wills
owner, Produce Pro, Inc. and Portable Software Company

···

On Jan 8, 2016, at 10:55 PM, Jens Alfke <jens@mooseyard.com> wrote:

On Jan 8, 2016, at 6:38 PM, Don Wills <don.wills@portablesoftware.com <mailto:don.wills@portablesoftware.com>> wrote:

All I am asking for is that the "throws" keyword on a method definition be optional - that is, a method can throw a <thingy> with the throw statement without specifying "throws", and it can be caught by a matching try/catch clause up the stack.

That’s asking for much, much, much more than making a keyword optional. You’re asking for the underlying error handling mechanism to be something completely different than what it is, i.e. stack-unwinding exceptions rather than returning an error value.

That is perfectly possible with LLVM and does not entail any ill-defined behavior.

There is a vast difference between machine code supporting something, and a language supporting it. You could say the same thing about nearly any language feature that Swift decided not to support. “But LLVM allows multiple inheritance!” “There’s nothing in LLVM preventing making all value bindings immutable!” “LLVM supports goto statements!"

The designers of Swift do not like exceptions. They decided not to include them in the language. Arguing for exceptions here is a tiresome religious war. When I worked at Apple I had some arguments about exceptions with people on the Cocoa and compiler teams. I definitely prefer exceptions to plain old return values (as in C or Go or Swift 1.x), but the compromise in Swift 2 is good enough that I’m happy with it, and I appreciate arguments like Brent’s about the overhead it saves. (If you’ve looked t the disassembly of exception-heavy C++ code, you can see all the code-size overhead it adds.)

All language designers have features they dislike and won’t add. Try arguing for late-binding dynamic dispatch to C++ gurus. Try arguing for explicit “free” calls in a Java forum. Tell the Haskell maintainers that mutable variables make coding so much easier. If you think language designers should give in and add every feature someone thinks is important, then you get the real kitchen sink you keep saying Swift is.

That’s the last I’m going to write about this. It’s stopped having any value. I’ve been around long enough to be sick of language flame wars, and that’s about all this is.

—Jens

Funny thing. I was moving towards swift and this discussion has helped me mcommit to more swift not less. I don't mind limitations if I understand them going in

···

Sent from Outlook Mobile<Bing;

On Fri, Jan 8, 2016 at 10:28 PM -0800, "Don Wills via swift-users" <swift-users@swift.org<mailto:swift-users@swift.org>> wrote:

Jens -

I apologize for having annoyed you, but this thread has been very informative for me.

I was under the misconception that Swift was more similar to Java and .NET than to C, C++ and Obj-C. Your statement - The designers of Swift do not like exceptions. - clears up some of my misunderstanding of fundamental principles guiding Swift design. And thank you Brent Royal-Gordon - your explanation was of great help in furthering my understanding of those design decisions.

I was seriously considering moving toward the use of Swift as the programming language of the future for my companies' mission-critical business application systems, but the knowledge I've gained in this thread has disabused me of that.

Sincerely,
Don Wills
owner, Produce Pro, Inc. and Portable Software Company

On Jan 8, 2016, at 10:55 PM, Jens Alfke <jens@mooseyard.com<mailto:jens@mooseyard.com>> wrote:

On Jan 8, 2016, at 6:38 PM, Don Wills <don.wills@portablesoftware.com<mailto:don.wills@portablesoftware.com>> wrote:

All I am asking for is that the "throws" keyword on a method definition be optional - that is, a method can throw a <thingy> with the throw statement without specifying "throws", and it can be caught by a matching try/catch clause up the stack.

That's asking for much, much, much more than making a keyword optional. You're asking for the underlying error handling mechanism to be something completely different than what it is, i.e. stack-unwinding exceptions rather than returning an error value.

That is perfectly possible with LLVM and does not entail any ill-defined behavior.

There is a vast difference between machine code supporting something, and a language supporting it. You could say the same thing about nearly any language feature that Swift decided not to support. "But LLVM allows multiple inheritance!" "There's nothing in LLVM preventing making all value bindings immutable!" "LLVM supports goto statements!"

The designers of Swift do not like exceptions. They decided not to include them in the language. Arguing for exceptions here is a tiresome religious war. When I worked at Apple I had some arguments about exceptions with people on the Cocoa and compiler teams. I definitely prefer exceptions to plain old return values (as in C or Go or Swift 1.x), but the compromise in Swift 2 is good enough that I'm happy with it, and I appreciate arguments like Brent's about the overhead it saves. (If you've looked t the disassembly of exception-heavy C++ code, you can see all the code-size overhead it adds.)

All language designers have features they dislike and won't add. Try arguing for late-binding dynamic dispatch to C++ gurus. Try arguing for explicit "free" calls in a Java forum. Tell the Haskell maintainers that mutable variables make coding so much easier. If you think language designers should give in and add every feature someone thinks is important, then you get the real kitchen sink you keep saying Swift is.

That's the last I'm going to write about this. It's stopped having any value. I've been around long enough to be sick of language flame wars, and that's about all this is.

-Jens

You don't have to take Jens's word for it. The fundamental principles guiding Swift design are all there for you to peruse at your leisure: https://github.com/apple/swift/tree/master/docs

The document entitled "Error Handling Rationale", for example, feels particularly apropos: https://github.com/apple/swift/blob/master/docs/ErrorHandlingRationale.rst

···

On Jan 9, 2016, at 12:28 AM, Don Wills via swift-users <swift-users@swift.org> wrote:

Your statement - The designers of Swift do not like exceptions. - clears up some of my misunderstanding of fundamental principles guiding Swift design.

--
Cheers,
-jemmons

Hi Don,

The other folks on this thread are essentially correct, though the tone wasn’t always helpful. It strikes me that you may not have seen the error handling rationale document. If that is the case, you should take a look, it describes many of these tradeoffs, including a number of specific mentions of the Java model and why we decided to go with something different:
https://github.com/apple/swift/blob/master/docs/ErrorHandlingRationale.rst

Overall, I think the Swift model has worked out really well. The only thing that I’m aware of that we’re seriously considering changing is to allow the ability to throw a single specific error type, instead of having type erasure take it all away. This is blocked on the resilience work landing, but it would be great to see it get implemented shortly after that.

-Chris

···

On Jan 8, 2016, at 10:28 PM, Don Wills via swift-users <swift-users@swift.org> wrote:

Jens -

I apologize for having annoyed you, but this thread has been very informative for me.

I was under the misconception that Swift was more similar to Java and .NET than to C, C++ and Obj-C. Your statement - The designers of Swift do not like exceptions. - clears up some of my misunderstanding of fundamental principles guiding Swift design. And thank you Brent Royal-Gordon - your explanation was of great help in furthering my understanding of those design decisions.