137 points · by tosh · 6y ago · 112 comments
Instead of waiting for Apple to fix SwiftUI, it's completely viable to bring your own abstractions, from React to Reason to Elm, to the web. And the cottage community that works on the most niche web abstraction is bigger than the Apple team allocated for SwiftUI.
It has its downsides, and sometimes we're all too eager to beat the drum of how bad the web can be, but it's also important to recognize the web as a fluke of history where we still have some control.
That said, I give Apple some credit for moving their own platform forward in a way that clearly borrows from what we've been doing with things like QML and React. I look forward to the day when my SwiftUI apps work well on both macOS and iOS. And it will be interesting if we reach a point where we don't need UIViewRepresentable because APIs like WKWebView have been adapted for the new declarative model.
Outside of web-based technologies, what would you consider a "desirable option" for making UIs?
How did people make iOS/macOS apps before SwiftUI? i.e. before 2020?
The idea of frame hierarchy is much more concrete in the autolayout world - which I guess helps the most.
Or one of the various alternatives... Flutter, React Native, Cordova, maybe a few others. There are also game app engines for games and game-like apps).
There are definitely fewer decent alternatives than for the web, but you aren't exactly starved.
Also, the context here is bug fix release cycles... no matter what you choose there will be bugs and release cycles that don't always match what you want for your app.
This is even true for script languages for instance. This is what make Javascript or Python more powerful than the language let them be. Being able to 'fallback' to C if things are not working the way they should.
Having SwiftUI or React are ok, if you can call imperative UIKit api's or web DOM when you need it.
Im very skeptic that this model will be feasible for the more "hardcore" cases of applications. So its important to have a powerful way to control things in details.
In hindsight, the modularity and the power that the web UI api gives you today is something to admire.
Its hard to have other examples where the bazar model ended up with better tools than the cathedral model. Especially if the cathedral model had time to do it later with the technological advantage only experience gives you.
Developing GUIs in various form factors since the late 80's and I rather have a window context to draw whatever I need than faking menus with list items.
Project Houdini, WebGL + Web Assembly for the second coming of Flash alike tooling is thankfully already taking off.
Sure, they're technically building on top of the native UI frameworks, but only by completely ignoring all of their functionality.
https://developer.apple.com/library/archive/documentation/Co...
UIKit/AppKit is layered on top of Core Animation which is layered on top of Metal. Skia, the 2D graphics library that Chrome's rendering engine uses, is built on top of Metal (or at least transitioning to Metal from OpenGL on macOS).
So browsers have the same flexibility in principle as native UI toolkits and they are just as close to the metal. There is no inherent disadvantage. But flexibility is a double edged sword. It includes the ability to diverge from the platform look & feel. So that's where the debate has been raging on for decades.
In terms of performance I think any debate about optimisation of UI stacks pales in comparison to the question of where the data lives, who generates it, and how it gets to the CPU/GPU for processing and display.
If people want to use web technologies on the desktop, there is Electron.
The converse is not true.
Recall the early days of Mac OS X. It is easy to look back at something like version 10.6 and see how “nice” AppKit worked but it had already evolved quite a bit by then, over many years. If you go back further, like 10.2, you see many rough edges as the APIs were rapidly evolving.
In the beginning, Cocoa was clearly powerful but also surprisingly lacking in some areas compared to Carbon (at least, from a Mac-like UI point of view, as opposed to NeXT). Interface Builder had different UI element libraries for both APIs. Even the common UI elements between the two APIs were not necessarily identical: there were things you could do in one API but not the other. Furthermore, converting a Carbon program to a Cocoa program was a monumental task, requiring things to be downright rewritten for just a basic Cocoa foundation to work properly.
The big difference this time, in favor of Swift and SwiftUI, is that it is possible to integrate brand-new stuff very quickly. Right now, I can integrate: Objective-C, C++, AppKit, Swift, SwiftUI, and a wide variety of other things, and they all compile and link and run. There is nothing requiring me to rewrite 98% my Objective-C app just to integrate my first SwiftUI View. While YMMV, compared to past endeavors this appears to be a much more practical solution for jumping to a new technology.
I started programming on NeXT in 1991 and AppKit was already very nice (not "nice") back then.
Target/action, for example, was a revelation, together with the responder chain. Miles ahead of everything at the time as well as most if not all the stuff that followed. Now we're back to tightly coupling everything and calling it "progress".
I had a similar sentiment as the author here but am a little more bullish on it being ready for production. SwiftUI is clearly the future for Apple, it still has a lot of issues to work out, but you can start using it today pretty easily because there's a nice interface for integrating UIKit with SwiftUI.
But using a thin font in grey on a white background makes that quite impossible.
Please have some pity on people whose eyes aren't perfect.
https://beta.trimread.com/articles/38118
(you can also go to the main page of this site and enter the URL there)
So a post showing how v2 of SwiftUI's limitations is a useful read because it's a reminder that it has more to go on the Mac - I expected that, and I bet he did. So it's positive in the sense that he wasn't disappointed, but that it met the (admittedly low) expectations of the author
I've been using SwiftUI for design and prototyping since release on iOS, to the point where it's faster for me to prototype on SwiftUI rather than Figma or Sketch. Particularly with animations and overall experience.
The problem for new people is the error reporting is still pretty bad, and it gets flakey if your views are too big. The key is to keep views small and compose them. It's also hard moving to a declarative model for UIKit devs who haven't done React.
I revisited the project after WWDC and found that some of the things I was frustrated with were improved and others just required a break and a fresh perspective to figure out. I recommend SwiftUI.
Swift's core team recently found out that they don't understand the type system they've created - they were fixing compiler 'bugs' for months without getting anywhere, until one of them finally realized hey, I should probably attempt to understand what we've built, not just 'fix' a never ending stream of bugs we seem to be having.
Turns out, the type system they built guarantees 100% that type checking is undecidable (in software developer terms, you can crash the compiler by typing perfectly legal Swift code and nobody at Apple knows how to fix it without breaking existing code because they didn't even know they built a language that has this property up until very recently). They figured this out after announcing a stable ABI by the way. Upon discovery, some of the core team members said the discovery was great/nice work.
It's not like we have people who use mathematics to prove properties of type systems without any shadow of a doubt or anything. I wonder how many of them are working on Swift or are employed at Apple, within their multi-billion dollar R&D budget... I wouldn't at all be surprised if the answer was zero, given that it was a software developer who knew a little math who made this discovery.
Even so, "undecidable" doesn't need to be a problem. It would be possible that the undecidable Swift program is such a random mess that nobody would be likely to write it by accident.
However, it is worth looking into more practical aspects of how Swift's type system works, and there I share your concerns. Swift is the _only_ language I have ever used where I have ever seen the error message "the type checker was unable to infer the type of this expression" etc. - sometimes on dead simple code. Worse, I once tried to write an expressive, generic, functional framework, only to discover that it was completely unusable because the type errors that Swift returned were simply wrong and to fix it you had to put in type annotations in a bunch of places (without necessarily knowing where, just from the error messages), making the whole API extremely verbose and not particularly declarative anymore.
It's more common than you'd think: https://typing-is-hard.ch
> the type errors that Swift returned were simply wrong and to fix it you had to put in type annotations in a bunch of places (without necessarily knowing where, just from the error messages)
The diagnostics engine was completely overhauled in Swift 5.2, so this shouldn't happen anymore: https://swift.org/blog/new-diagnostic-arch-overview/
Undecidability means there's no algorithm that is guaranteed to terminate, not that any algorithm will crash. In this case, using a completion procedure to convert the same-type constraints into a confluent rewrite system should be sufficient. If completion fails an error can be diagnosed. This shouldn't break any real code in practice.
Someone found this in Java as well. Accidental Turing completeness crops up everywhere, it's actually rather hard to ensure decidability. It's a favorite pastime of people in this area; I'm somewhat disappointed you didn't find it to be interesting. In any case, personal attacks against the Swift compiler engineers (many who are quite competent at the things you are claiming they are lacking) are not appropriate.
Working at FAANG is an abject lesson in learning that assuming 'competence' (i.e. knowing mastery-level detail, taking responsibility everywhere, and going off on world-creating tangents rather than fixing bugs) is damn rare, nearly all of my career's achievements have come of accepting that and doing deep dives into problems.
How is it that a single person named Edwin Brady can think of, implement and have a programming language with a decidable type system that is more complex than Swift, working on it part-time?
I'm sorry, I consider a company worth a trillion dollars, sitting on billions of dollars it doesn't know what to spend on, that spends billions per year on R&D, to know the basic properties of the type system their most actively developed programming language uses.
That's just me.
(It should be clear, but this is both factual and a joke. The core team is good people, Slava is good people, Slava is not on the core team.)
The tone sounds histrionical because it is way ahead of the herd's perception. It's been terrifying to have feet in multiple communities, have a strong foot in Apple's community, and see how things are done over there and gotten worse over the years, particularly after Swift's release.
https://forums.swift.org/t/swift-type-checking-is-undecidabl...
I think that’s generally pretty reasonable but in my experience you won’t even be able to reach the end of your hobby app without hitting some wall where a feature you want is simple in UIKit and not supported at all yet in SwiftUI. SwiftUI is great, the paradigm is refreshing but unfortunately it just isn’t ready yet.
> I feel we won't see "complete" SwiftUI apps for another 2 years or so, maybe thats the intention?
Unsure about intention but it is definitely the expectation :)
Sadly, excitement lasted 1 month after I realized that it's not ready. Obscure error messages, random bugs in controls and other annoyances turned my initial excitement into frustration. I managed to make things work but had this feeling of it being fragile.
I see the potential, hopefully in a few years.
https://twitter.com/InvadingOctopus/status/12792872846265794...
It's amazing just how little effort and code is required to build complex scalable layouts that Just Work.
Yes, it does require you to Think Different and you will have to change how you approach UI design if you're coming from legacy frameworks.
That's where the most frustrating aspect of SwiftUI lies, apart from the early bugs and lack of consensus, and this is where some people give up: having to change how you think. Just like Swift itself.
> Of the 10 seconds captured, 30 percent of them are used for the various retain/release and malloc calls in Swift and Objective-C
This is not indicated in the profile screenshot, though I will concede that perhaps it's showing up from the "inverted" view or something.
* Different Betas changing the layout and style and meaning of different attributes. The change isn’t so bad as the documentation. Most of the functionality is sparely documented so it’s impossible to tell if something “broke” or was “fixed” in a new beta. Stuff like .overlay() vs ZStack and how they appear. Stuff like how .padding() is calculated with the default args. Stuff like what the default list modifier does.
* Last beta forgot to ship some symbols in SwiftUI.framework and .toolbar (a modifier to draw a toolbar) was missing. The fact that it slipped notice and nobody talked about makes me suspect nobody is actually using it.
* Common functionality like creating a new window with a different layout is missing. In fact it seems to revolve iOS where new window means same view in a new window.
* Weird quirks like if you dismiss a modal sheet before falling a background task would cause layout issues and random state changes. But if you dismiss the sheet after calling GCD it doesn’t happen. It’s likely a race condition somewhere. Another example https://stackoverflow.com/questions/58404725/why-does-my-swi...
* Missing components like the activity indicator and the new settings tab design for TabView
* You either have no control over the layout or so much control it overwhelms you. For example if you wrap a View with Form it generates a right justified label and left justified field. It works for checkboxes and pickers but it doesn’t work for every component. If you want the same alignment for everything you have to throw away the work done by Form and completely define your own layout rules for everything.
* If you look up how to do anything, the “accepted” answer always feels hacked together and nobody can explain why it works. For example, if you look up how to force center alignment on any object there’s a blog post that’s about 20 pages that propose some solution that’s 200 LOC.
* Day to day, I feel very limited by the framework. At almost every point, I had to compromise the design vision with “what’s possible” in SwiftUI. And note this is a very “simple” app that manages VMs and allows you to change settings. Everything uses basic controls and there’s nothing exotic.
All this aside I still enjoyed using SwiftUI on most days. When it works, it feels like the future. Unfortunately v1/v2 is still very early and it’s filled with bugs. But people need to use it to find and report the bugs. I hope, like Swift, we’ll eventually be at a point where everyone uses it because it’s an upgrade from the previous technology without any compromises.
Many of the bugs probably have more to do with the unshippability of macOS at the moment.
I'm fairly certain that the elegance and flexibility of the UIKit model, and its uncompromising focus on user experience over developer experience was a key contributor to iOS's success over its competitors.
I'm very sad that with SwiftUI Apple gave in to the tide and started catering to React devs with this gimmick immediate-mode framework on top of their existing retained-mode toolkit. The original NeXTSTEP engineers wouldn't have let this happen...
There are literally senior vice presidents, who I assume had to sign off on SwiftUI, who were NeXTSTEP engineers.
though to be honest, i liked the bindings model in appkit better (much more component and visually driven)... shame it never came to be on iOS...
swift ui is pretty cool, but somehow i feel like im laying out an html webpage instead of an app... maybe its just me
Who?
(because some of them are still at Apple, including Hair Force One :)
I assume based on this Swift code can't be swizzled for some reason?
https://twitter.com/jckarter/status/1135730593537249282?lang...
Yep, the blazing speed of reference counting over tracing GC.
https://github.com/ixy-languages/ixy-languages
As for Electron, as React Native team has proven, Electron isn't the best example of JavaScript performance or memory usage, quite the opposite.
I can hardly wait the day that they manage to convince the VSCode team to migrate to React Native.
I wanted to build a Mac native product but decided against it. Maybe in a couple of years.
Most people tend to confuse good design and good software, unfortunately.
There are obvious cons, like (previously) having to learn a new language, Objective-C, which has it's quirks. Documentation may not be very good in some instances. Tooling (Xcode/Interface Builder) may not be as good, or as complete, as tools like Visual Studio.
But of the pros, AppKit/UIKit do A LOT of work for you once you understand things. Things may not be consistent between UIKit/AppKit due to some ability to start over a bit with UIKit plus just different form factors and things, but they are consistent amongst each other and the UI components are all very high quality and flexible. The support libraries are also incredibly good.
SwiftUI should probably be labeled beta given it's not able to do everything UIKit can do, but they've made big strides with the OS releases coming this fall.
As a general rule, I don't like the way Apple wants to drag people into their walled garden, with a tech stack that will be mostly useless outside of it.
Swift is like Objective-C of Metal, we can discuss their respective merits, but it will never hide the fact that they are all bad cases of the infamous NIH syndrome.