Thursday, September 29, 2022
HomeiOS DevelopmentSwift wants a greater language reference – Ole Begemann

Swift wants a greater language reference – Ole Begemann


In August 2020, I posted a rant on the Swift boards in regards to the poor state of Swift documentation. Nothing got here of it, however I need to reiterate one level I made then: the Swift undertaking sorely wants a searchable, linkable language reference.

To be honest, Swift does have a language reference: the eponymous part in The Swift Programming Language (TSPL) accommodates many of the info I’d anticipate from such a useful resource. However that part isn’t properly structured to function an precise reference:

TSPL is just not searchable

The TSPL web site doesn’t have a search discipline. Even when it had one, I think about it will be a full-text search over your complete website, as is widespread (and applicable) for a guide. A language reference wants a special search engine:

  • Looking for key phrases (if, case, the place) should reliably discover the documentation for the key phrase as the highest outcome. I don’t need to see the tons of of pages that comprise the phrase “if” of their physique textual content.

  • I’d love to have the ability to seek for punctuation. Think about in case you might seek for an emblem reminiscent of # and it will present you a listing of all syntax components that use this image. This might be very informative and an effective way to discover the language, not only for inexperienced persons — particularly with good IDE integration (see beneath). Swift is such a giant and complicated language that most individuals received’t know each language characteristic.

A language reference wants a search engine that is aware of to deal with key phrases and punctuation.

TSPL is just not linkable

Pages in TSPL are typically lengthy, with many separate objects crammed right into a single web page. For instance, all compiler attributes are documented on a single web page.

Sharing a hyperlink to a particular attribute, reminiscent of @resultBuilder, is troublesome if you realize your means round HTML and just about not possible in case you don’t (to not point out the dangerous URL).

As a reader, opening such a hyperlink is disorienting because it drops you in the midst of a really lengthy web page, 95 % of which is irrelevant to you.

The reader expertise is even poorer once you arrive from a search engine (as most individuals would as a result of the positioning has no search operate): TSPL is without doubt one of the high outcomes for swift resultbuilder on Google, nevertheless it drops you on the high of the superlong web page on Attributes, with no indication the place to seek out the knowledge you’re on the lookout for.

Each language assemble, key phrase, attribute, and compiler directive ought to have its personal, linkable web page.

TSPL is structured unsuitable

The Language Reference part in TSPL is organized as if it was written for parser or compiler builders. It makes use of the language’s grammar as a place to begin and branches out into expressions, statements, declarations, and so forth.

For instance:

I don’t learn about you, however as a consumer of the language, that’s not how I take into consideration Swift or how I seek for documentation.

Along with a very good search engine, a language reference wants an alphabetical index of each key phrase or different syntax factor, with hyperlinks to the respective element web page.

IDE integration

I used to be cautious to make this a criticism in regards to the documentation for Swift and never in regards to the (equally poor) state of Apple’s developer documentation. Swift is just not restricted to app improvement for Apple gadgets, and I imagine it’s important for Swift to place itself as a standalone undertaking if it needs to be perceived as a viable general-purpose language.

It’s good that TSPL is hosted on swift.org and never developer.apple.com, and that’s additionally the place this new language reference I’m envisioning ought to dwell. (I additionally suppose it’s unsuitable to host the Swift API documentation on developer.apple.com.)

However as soon as we’ve got this language reference, Apple ought to in fact combine it into Xcode for offline search and context-sensitive assist. Think about in case you might Choice-click not solely identifiers however any token in a supply file to see its documentation.

A number of examples:

  • Clicking on if case let would clarify the sample matching syntax.
  • Clicking on in would explains the varied closure expression syntax variants.
  • Clicking on #fileID would present you an instance of the ensuing string and examine it to #file and filePath.
  • Clicking on @propertyWrapper would clarify what a property wrapper is and how one can implement one.
  • Clicking on @dynamicMemberLookup would clarify its objective and what you need to do to implement it.
  • Clicking on < in a generic declaration would clarify what generic parameters are and the way they’re used.
  • Clicking on ? would present all language components that use a query mark (shorthand for Optionals, elective chaining, Elective sample matching, strive?).
  • Clicking on /// would checklist the magic phrases Xcode understands in doc feedback.

You get the thought. This might be such a giant assist, not just for inexperienced persons.

To summarize, that is the unhappy state of trying to find language options in Xcode’s documentation viewer:





Xcode documentation viewer showing no result when searching for 'propertywrapper'


Xcode documentation viewer showing meaningless results when searching for 'guard'
guardian let me watch youtube else { throw match }

Xcode documentation viewer showing no result when searching for '#fileID'


Xcode documentation viewer showing no result when searching for '@available'


Xcode documentation viewer showing meaningless results when searching for 'associatedtype'
Nope, this isn’t what I used to be on the lookout for.

And this mockup reveals the way it might be:


Mockup of an imagined Xcode documentation popover for #fileID
Sure, I rebuilt Xcode’s documentation popover in SwiftUI for this mockup, syntax highlighting and all.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular