Live data from Hacker News

SwiftUI After 7 Years

ykvm.com

171–180 of 343 posts

Re: SwiftUI After 7 Years

#171
post #137

Earlier quoted context omitted.

Not just does the computer not do functional. UI is also very much not functional, and in fact the lack of progress in UI the last 30-40 years can largely be traced to trying to create UI with procedural/functional programming languages, an instance of linguistic-architectural mismatch. Further reading: Programs = Data + Algorithms + Architecture: Consequences for Interactive Software Engineering -- Stéphane Chatty.…

> UI is also very much not functional, I disagree, and I believe that the complete stagnation of GUIs is due to ignoring this. There is no good reason why a GUI system isn't: Description->Pack->Apply events->Generate assets->Render assets. At each point you reify the result into an artifact that is everything the next stage needs. This has a couple of nice properties. One property is that everything is deterministic…

>> UI is also very much not functional,

> I disagree, and I believe that the complete stagnation of GUIs is due to ignoring this.

I disagree with your assessment.

>Description->Pack->Apply events->Generate assets->Render assets.

1. What does that even mean? I don't see a UI in there at all, at best some graphics (Render).

2. That's not "functional". If anything, it looks like a pipeline, so dataflow. But then again, see (1)

3. Not sure why reification, that is turning things into objects, is functional to you. Reification, that is turning things into objects, is object-oriented.

4. MVC was actually created on 5.8 MHz machines with 128KB of RAM (including the display buffer). And still works beautifully today.

https://en.wikipedia.org/wiki/Xerox_Alto

Re: SwiftUI After 7 Years

#172

Earlier quoted context omitted.

MVC is not bad, but it is not a silver bullet. Calling MVC an ultimate solution to UI is oversimplification. Just looking at the steps you listed I can ask: How do you collect all notifications on step 2 to fire them on step 3 such that UI does not re-render itself too much? E.g. updating a title of each item in a list of 100 items should not trigger 100 renders. Or 100 layout calculations (which I think is harder to…

I never claimed MVC is a silver bullet. Just that it solves "... incredibly easy to forget an edge case in your update logic." > UI does not re-render itself too much? Glad you asked! In my Blackbird reference architecture (which is an instance of MVC), I use a coalescing queue to capture the updates. The coalescing is two-level: first, simple duplicates are weeded out. Second, if the update queue gets very full, it…

How do you handle UI state vs. underlying data (model) state, and dependencies between them? By UI state, I mean things like scrollbar position and selection state. When displaying a scrollable and selectable list of items, then for example when the number of items changes, the selection may need to adjust, and the scroll position may need to adjust. Depending on which items are added or removed (or reordered), the selection and scroll position may need to change differently for the apparent UI state to look stable for the user. If only the model is changed, a previous UI state like selection or scroll position may become invalid in relation to the new model state. Who updates the UI state accordingly to make it valid again? In the general case, application code needs to be involved in choosing the desired valid UI state when the underlying model state changes. How is the corresponding application code prevented from triggering further events?

Re: SwiftUI After 7 Years

#173
post #89
post #74

Maybe unrelated, but as an Android dev, a few years ago I wanted to look into SwiftUI. But now I feel like for most apps, I should be fine with Compose Multiplatform and Kotlin Multiplatform. I don't see the point of learning SwiftUI anymore.

Well you could do android apps using SwiftUI ¯\_(ツ)_/¯

But then I would have to endure the Apple developer experience...

Re: SwiftUI After 7 Years

#174
post #3

The problem with complex systems is that you can be dead long before you realize you're dead. Things can continue to seem "pretty good" for a long time just from the inertia of past good decisions and built-up infrastructure. You see some fraying or cracks but everything looks fundamentally sound, until it isn't. Apple's inability to deploy a new UI framework that's better than the previous one is troubling. This is…

The problem with ObjC was mainly syntax, bolted on over many years on top of a C core. It was grown rather than designed, and it shows. But there's nothing wrong with the runtime. Swift should have just been a much improved syntax over that same runtime. It would have avoided so many headaches. For one they wouldn't have made the awful decision to have return-type overloading and completely ruin the typechecker's per…

> Swift should have just been a much improved syntax over that same runtime

That's exactly how Objective-Smalltalk started, and it's still very good at being just that.

https://blog.metaobject.com/2019/12/the-4-stages-of-objectiv...

However, it has grown to be, er, a bit more.

https://2024.splashcon.org/details/splash-2024-Onward-papers...

https://objective.st

> SwiftUI should have unapologetically been a convenient, reactive wrapper over UIKit and AppKit,

I am also working on a UI "framework" I call InterScript that is (for starters) a wrapper over UIKit and AppKit, and basically solves what I perceive to be the biggest problems of Cocoa:

1. UI specification using object literals. This makes UI-creation very compact and readable. The following example (mostly) reproduces a SwiftUI "Form" example from Apple documentation:

    #Grid{ frame: (20@20 extent: 400@340), #rows: [
       [ #Label{ text: 'Name' },          #TextField{ stringValue: 'Taylor', frame: (200@24) } ],
       [ #Label{ text: 'Email' },         #TextField{ stringValue: 'taylor@example.com', frame: (200@24) } ],
       [ #Label{ text: 'Notifications' }, #NSSwitch{ state: 1 } ],
       [ #Label{ text: 'Sounds' },        #NSSwitch{ state: 1 } ],
       [ #Label{ text: 'Summary' },       #PopUp{ items: [ 'Daily', 'Weekly', 'Monthly' ] } ],
       [ #Label{ text: 'Color scheme' },  #NSSegmentedControl{ segments: [ 'System', 'Light', 'Dark' ] } ],
       [ #Label{ text: 'Text size' },     #Label{ text: 'Default' } ],
       [ #Button{ title: 'Reset All Settings' } ],
    ] }.
   
There are actually even better ways of accomplishing this, but this should give you an idea.

2. Better communication between model and UI by using the support in the language for polymorphic identifiers and dataflow. Because dataflow is in the language, it can be expressed succinctly without making it hidden magic like in SwiftUI. With dataflow and polymorphic identifiers, you also get a dataflow-constraint mechanism similar to Cocoa Bindings, but again with proper support and less magic.

Essentially the solution to this:

https://blog.metaobject.com/2014/03/the-siren-call-of-kvo-an...

There is more, for example cross-platform, MDA/Naked Objects/Direct2Web style simplification and web integration with HTMX and HTMXNative.

Re: SwiftUI After 7 Years

#175

Earlier quoted context omitted.

I never really tried out Cocoa. What did you like about it?

At least for me, it just had/has the right mix of abstraction and simplicity. It just "ticked" in a way that for example MFC didn't. But I also really liked Objective-C.

Cocoa and Objective-C are both great, but I think there's one huge problem that they never managed to solve well: responsive layouts.

Classic iPhone apps have fixed layouts, and classic Mac apps have a big dynamic document in the centre with mostly fixed toolbars around the sides, and dialogs with fixed layouts. Making a really dynamic layout with OS widgets is a huge pain, so most apps sidestepped it.

As Apple gradually added more and more slightly different sizes of iPhone and iPad, making good UI layouts got harder. Even handling screen rotations is a huge hassle! If iOS had proper support for resizing from the start, screen rotation would be trivial, just another window resize.

Xcode had Interface Builder and autolayout, but I found those to be disastrously fiddly and unusable. Maybe some people like them?

HTML has many problems of its own, but it does have good support for responsive layouts. CSS isn't perfect, but it's vastly better than anything you can find in macOS, iOS, Android or Windows.

It seems to me that SwiftUI was trying to tackle two problems at once: React-style declarative UI, and responsive layout. Those are both good ideas, but trying to tackle both in a single uber-framework and deprecating the lower layers was too ambitious. As somebody said elsewhere in this thread, SwiftUI could have been decent as just an optional helper on top of the existing UIKit / AppKit.

Re: SwiftUI After 7 Years

#176
post #137

Earlier quoted context omitted.

> UI is also very much not functional, I disagree, and I believe that the complete stagnation of GUIs is due to ignoring this. There is no good reason why a GUI system isn't: Description->Pack->Apply events->Generate assets->Render assets. At each point you reify the result into an artifact that is everything the next stage needs. This has a couple of nice properties. One property is that everything is deterministic…

>> UI is also very much not functional, > I disagree, and I believe that the complete stagnation of GUIs is due to ignoring this. I disagree with your assessment. >Description->Pack->Apply events->Generate assets->Render assets. 1. What does that even mean? I don't see a UI in there at all, at best some graphics (Render). 2. That's not "functional". If anything, it looks like a pipeline, so dataflow. But then again,…

Functional is all about reification. You take a set of things in, you apply/map/collect/fold/whatever, you eject a set of things out. That is 100% functional--every time you supply the same inputs you get exactly the same outputs. The point of functional programming is that you avoid mutation and hidden state.

And, um, side note: dataflow programming is almost always considered functional programming.

Object oriented, by contrast, is all about hidden state and mutation. I send a message or call a function on that object over there and fingers wiggle and magic happens. But I don't know what or when or even if it actually happened.

And increasing evidence suggests that MVC doesn't work beautifully today because it doesn't parallelize, and it scatters state between uncooperative things. Just ask every single GUI that exists--every single one hangs because somebody made an oops and put too much work on the single, blessed primary thread. Or they have janky scroll. Or resizes leave gunk on the screen. Or your system flashes and jiggles because it's too busy reflowing everything in the universe. Or ...

Re: SwiftUI After 7 Years

#177

I would only take this article seriously if you have to support old iOS versions. NavigationStack has been around since iOS 16, @Observable since iOS 17. and I'm not sure if the author is aware that GeometryReader hasn't been necessary since iOS 18 added onGeometryChange modifiers. Nearly 100% of users are on iOS 16+. I'm doing some fairly complex work with SwiftUI and I find most components work identically between…

> I'm not sure if the author is aware that GeometryReader hasn't been necessary since iOS 18 added onGeometryChange modifiers.

I think the author does not understand how and why to use GeometryReader at all. He literally said "you find yourself wrapping everything in a GeometryReader" which is a different thing from simply measuring. For measuring you could always put GeometryReader into `.background()` and use that to avoid messing with the view layout. Also, "wrapping everything" is a good sign you are doing something wrong.

Edit: by the way compiler timeouts are not a SwiftUI issue: it is a Swift issue. You can create a timeout situation in pure Swift. For SwiftUI specifically this situation is addressed in the upcoming OS27 SDK.

Re: SwiftUI After 7 Years

#178

Earlier quoted context omitted.

Do you have an example of where "the ideas don't combine well"? Or where an imperative approach is truly better? In my experience the solution is often to use the appropriate architecture underneath your UI layer. Basically you build a data structure that represents your UI and always hand this entire structure to the declarative UI layer. Underneath the UI layer, you can still use imperative code to manipulate the d…

One example of where I think imperative generally does better is UI that requires substantial setup or customization. In SwiftUI, that means endless chains of modifiers, and in Compose this means monstrous constructors and modifier chains. Both get really ugly and painful to read quickly, and there's not a lot that can be done about it apart from breaking everything out into smaller views (which only goes so far). Th…

>in Compose this means monstrous constructors and modifier chains.

Which is now being fixed by the Styles API (https://developer.android.com/develop/ui/compose/styles) which are easily reusable.

Re: SwiftUI After 7 Years

#179
I have recently completed building a large native macOS app and my take is that, for 90% of work, SwiftUI is good but for the 10% you would need AppKit.

For my app which is a AI chat app, I needed to load and show a large number of chat items in a list, SwiftUI is really bad at this. Another issue is, most of Swift markdown libraries don't perform perform well because each elements are rendered as SwiftUI views which introduced a lot of issues So I built my own renderer using TextKit. Even basic things like Settings window is broken. But I still prefer using SwiftUI as It gets the work done faster and I can always fallback to AppKit.

I find that web tech like React are worst than SwiftUI. React also has re-rendering and state management issues

Re: SwiftUI After 7 Years

#180
post #122

Earlier quoted context omitted.

7 Years of release on Swift UI, 12 years for Swift. This isn't 7 years of development, but 7 - 12 years after release . And to most these past 7 - 12 years are an ongoing beta development. It is unfinished, unpolished with no end in sight. And I have been extremely critical since the beginning. But the problem runs much much deeper. It isn't the technology that is the problem, not the devs who are making it. It is th…

I agree with you. Swift should have been a modernized Objective-C. It should have kept the best parts of it, which made it a joy to use, and leave the archaic and the weird things behind. it would have been a great language, meanwhile they decided to throw everything out and created a language that it is overcomplex, and it is failing to gain any traction outside iOS / Apple's ecosystem. Basically, if you weren't req…

> Swift should have been a modernized Objective-C. It should have kept the best parts of it, which made it a joy to use, and leave the archaic and the weird things behind.

That's what Objective-Smalltalk is, or rather, what it started out as.

https://blog.metaobject.com/2019/12/the-4-stages-of-objectiv...

It has now gone further to actually implement Brad Cox's idea of a "Software IC", by taking on ideas from software architecture and metaobject protocols.

https://2024.splashcon.org/details/splash-2024-Onward-papers...

> SwiftUI, should have been a rendering template/library integrated with UIKit.

Do you mean it should have used some sort of XML-ish/HTML-ish templating mechanism? For Interscript, I keep looking at that approach, but so far haven't gone down that road (except for HTMXNative, but there it actually is HTML, so...).

Post reply on HN