Archive for June 12, 2015

Friday, June 12, 2015

Swift 2 Error Handling in Practice

David Owens II:

It took me a little while for me to really appreciate the design of throws. At first, it was sheer disbelief that the Swift team created exceptions. Then it was mild irritation that a Result<T, E> type wasn’t used.

Brad Larson:

We aren’t the only ones that think Result, or a type like it, is a solid solution for error handling in Swift, so it took me by surprise that the Swift team went in a seemingly different direction with Swift 2’s new error model. That is, until I started working with it in my own code and found that it did almost everything my Result-based handling does and did it in a cleaner manner.

Swift 2 provides error handling by the means of several new keywords: do, try, catch, throw, throws. To indicate that a function or method can provide an error, you mark it with throw. Errors cannot be thrown within functions or methods that lack this marking. Similarly, error-throwing functions or methods cannot be used without using the try keyword before them. All errors must either be caught (using do/catch), or passed upward (at which point the function or method must be marked as throws).

Multiple error-throwing functions can be called in sequence, but the first to throw an error aborts execution at that point. An error being thrown acts more like a return statement than the older-style Objective-C NSExceptions, and plays nice with ARC.

My initial reaction was that Swift 2’s error handling is a bit of a hack, a lot of keywords and compiler magic to not give us real exceptions. But Swift fixes some of the problems with exceptions in other languages. And it fixes the main thing that was wrong with the Objective-C NSError model, which is that it was very verbose. Most importantly, it doesn’t turn ordinary code into a mess of types and closures, which is what I feared Apple was going to do.

I look at what it does to Larson’s code, and I’m impressed. And he hasn’t even showed what defer can do. So, although it’s unusual, I think this is going to work out well in practice.

There’s still work to be done, though. Swift still can’t handle actual exceptions raised by Objective-C code. They’re treated as runtime errors that bring down your whole program. So some important Cocoa APIs—plus anything with assertions—is off-limits.

See also: the two Swift books and my WWDC 2015 Links post.

Update (2015-06-12): I am going to miss the automatic stack traces that I would get with either true exceptions or my Objective-C NSError propagation macros.

Swift Libraries Not Included in iOS 9 or El Capitan

Chris Lattner (contra Mark Gurman):

There were no public statements that Swift 2.0 would eliminate that requirement (just some rumor sites claiming that) and in fact Swift 2 will continue to require the standard library in your app.

We are interested in making Swift ABI stable going forward, but will need more time to settle things out. In particular, we want to make sure that we get to incorporate ideas and feedback from the open source community before locking things down.

This is really good news for Swift in the long term. However, it does make deployment less attractive in the short term. Gurman says that the libraries for an application take up 8 MB. I found that a Hello World command-line tool is 3.6 MB. Regardless, this gets multiplied by the number of binaries in your application: background helper app, XPC service, Spotlight importer, Quick Look plug-in, Automator action, command-line tool, etc.

Update (2015-06-15): It is not always the case that there will be duplicate copies of the Swift libraries for each binary. For example, a .appex bundle will automatically link to the libraries in its containing app. Xcode 6 does not seem to do this automatically for other bundle types, but in theory a future version could. Any binary such as a command-line tool that could be moved, relative to the main application, probably needs to embed its own copy of the libraries.

Update (2015-07-27): Sam Marshall:

There is a build setting named EMBEDDED_CONTENT_CONTAINS_SWIFT which stores a boolean value. There is an Apple Q&A document that describes how to use this, however there are some assumptions made as to how this flag is to be used.

When enabling the EMBEDDED_CONTENT_CONTAINS_SWIFT flag on a target, a new step is added to the build process. This step runs the target’s build product through a tool called swift-stdlib-tool, which parses the binary header to get the list of linked dependencies (frameworks/libraries). It will then check the paths of these linked dependencies to see if any of them contain references to the Swift runtime libraries.

The Return of the iPad

Federico Viticci:

This, I believe, is an important distinction to make when assessing the iPad’s adoption of features that have been exclusive to desktop computers. The iPad’s improved capabilities in iOS 9 are options – deeply integrated with the operating system through gestures, but, ultimately, not the default way to interact with apps. Compare the new iPad multitasking to OS X: when you launch an app on the Mac for the first time, it defaults to window mode without taking up the entire screen; in iOS 9, iPad apps will launch in full-screen as usual and allow you to view a secondary app only when needed.

[…]

iOS 9 is going to be a watershed moment for iPad users. For many, the iPad is about to graduate from utility to computer. Apple is envisioning a future where users can do more with iPad apps without the inherent complexities of OS X – and they’re largely relying on developers to help build this future.

[…]

While Slide Over will be available on older iPad models, the more useful and versatile Split View will only be available on the latest iPad Air 2. Will that slow adoption among users stuck on older iPad models, or will it push people who want to do more on an iPad to buy a new one? How quickly will developers react and update their apps for multitasking? Is this going to revitalize the iPad productivity app market, which has been a bit stale and unimaginative in the past couple of years? Is it kind of obvious at this point that a larger iPad with more comfortable split view multitasking is coming?

Ted Landau:

For people who own (or are considering purchasing) an iPad, the forthcoming release of iOS 9 is the biggest most exciting event since the iPad was released in 2010.

[…]

With Split View (available only in the iPad Air 2 for now), Slide Over and Picture in Picture, you can finally interact with two apps simultaneously. With the new QuickType “trackpad simulator,” you can move the cursor around much like you do on a Mac, eliminating the need for the loupe tool. There’s now a system-wide shortcut toolbar. There’s even a Mac-like app switcher than you can call up with Command-Tab on a Bluetooth keyboard. I’ve tested all these out with the iOS 9 beta and can attest that they work pretty much as advertised.

Update (2015-06-19): Lukas Mathis:

This seems to add additional inconsistency to an already odd implementation of the split window feature.

This reminds me of 90s Internet mystery meat navigation, except that there’s not even any mystery meat, and you’re just randomly dragging around and tapping on things to trigger actions that might or might not be supported by the application you’re actually trying to use. You could argue that split view is a power user feature, and power users can just go watch a YouTube movie that explains how the feature works, but I’ve now watched this section of the keynote twice, forgotten how it works once already, and I’m completely sure that I will have forgotten how it works again by tomorrow.

This is exactly the kind of magical user interface that people have faulted Windows 8 for, except it’s even more confusing. In Windows 8, you only had to remember to swipe in from the screen edges. Once you did that, the UI was visible, and guided your actions. In iOS 9, it’s layers of hidden UI magic. The one advantage Apple has is that you don’t need to know any of it to use iOS, but still. I think we should expect better of Apple.

Freemium Is Hard

Shuveb Hussain:

Amazingly, people were finding Comfy Read solely via the App Store search without me having to do anything. I cannot overstate its importance.

[…]

With Apple making analytics available on iTunes Connect, I was amazed to see that Comfy Read was having conversion rates of anywhere between 6 and 9%. Pretty amazing for an up-front paid app, I thought.

[…]

Will v2.0, the freemium app that a lot more users are downloading beat v1.0, the older version, financially? Not by a long shot.

Marco Arment:

Freemium is hard. Its effectiveness depends on where you can put that purchase barrier in your app. Many app types simply don’t have a good place for it.

[…]

I spent months debating which features should be behind Overcast’s in-app purchase. If I limited the number of subscribed podcasts for free users, I’d be discouraging people from trying new podcasts. If I put Smart Speed, Voice Boost, and my smart playlists completely behind the paywall, most users would never experience my best features and wouldn’t think my app was very good. But if I kept the paywall too easy to avoid, like showing ads with a purchase to remove them, it wouldn’t sell well. (No-ads upgrades never sell well, by the way.) And whatever features I limited would be free in many competing apps, including the one Apple includes on every iPhone for free.

Hermann Zapf, RIP

Bruce Weber:

Hermann Zapf, whose calling in life — “to create beautiful letters,” as one of his students put it — found expression in lush, steady-handed calligraphy and in subtly inventive typefaces that have brought words to readers on paper, on signposts, on monuments and on computer screens for more than half a century, died on Thursday at his home in Darmstadt, Germany. He was 96.

[…]

Working with these elements, Mr. Zapf evoked beauty as well as clarity, cleverness without hubris, invention without distraction. A master calligrapher who could reproduce a typeface by hand, he brought an admiration of the art of the pen to the art of the font. And conscious of history, he felt that type should both acknowledge tradition and reflect modernity.

Anna Quito (via John Gruber):

In his long and prolific career, Zapf worked on many fonts, but his personal favorite was the humanist sans serif typeface Optima, the lettering chosen for the Vietnam Veterans Memorial wall in Washington, DC.

[…]

Zapf was among the pioneers of computerized typography, experimenting with computer-aided typesetting from the 1960s. He led a seminal design program at the Rochester Institute of Technology where collaborated with computer scientists and became acquainted with IBM and Xerox. Zapf invented a typesetting program called Hz-program, which later informed the design of the desktop publishing software Adobe InDesign.

Adam Twardoch (via Hacker News):

But his contributions went way beyond that — Hermann Zapf served as typographic advisor to both Dr. Peter Karow (URW) and Professor Donald Knuth (TeX), the pioneers of computerized typography whose legacy we all benefit from today. Hermann had as much mastery in writing and drawing letters as he had in arranging them. The typographic arrangements that he devised are full of joy, beauty, balance and harmony — and deserve to be studied meticulously.

afard:

Palatino, Optima, and Melior were heavily used, I would say overused, in the late 1970s and early 1980s. A friend who went to Rochester Institute of Technology when Zapf was there (as a visiting professor, I think), said that in a lecture Zapf said that he had never intended Palatino to be used for body text, producing some gasps from the audience.

Why I Don’t Rely on Time Machine

Joe Kissell:

A couple of weeks ago, not long before my new book was published, Time Machine displayed the following helpful error message on my Mac: “Time Machine couldn’t complete the backup to ‘Backup Drive’. Unable to compete backup. An error occurred while creating the backup folder.”

[…]

When my backups become suddenly inaccessible for unknown reasons and I’m offered no solution but starting over, that sort of diminishes my faith in the software.

Then yesterday, Morgen’s laptop, which backs up to a completely different destination (a Time Capsule), displayed yet another error message: “Time Machine completed a verification of your backups on ‘Zora’. To improve reliability, Time Machine must create a new backup for you. Click Start New Backup to create a new backup. This will remove your existing backup history. This could take several hours. Click Back Up Later to be reminded tomorrow. Time Machine won’t perform backups during this time.”

I’ve encountered both of these errors, the first one with probably 10 different backup destinations, so I don’t think it can be blamed on hardware.