Live data from Hacker News

SwiftUI Defaults Considered Harmful

tonsky.me

91–100 of 135 posts

Re: SwiftUI Defaults Considered Harmful

#91

SwiftUI has defaults because nobody knew what UIKit's were supposed to be. Some of them were fiddly secret layout guides in Interface Builder, and some were accessed through the magic "-" in a VFL constraint, but overall it was very difficult to actually know how much spacing things should have. And on Apple's platforms, this matters: users know what things should look like, and if you're off you just look out of pla…

UIKit has enough abstraction to allow not knowing the magic numbers and looking right. What with safe areas, margins and reading guides, all this has been possible for many years now.

The problem isn’t the API; it’s terrible product managers and designers, usually from the web world, who think they know better and ignore platform APIs for hard coded numbers. SwiftUI won’t save those clowns from themselves unless it completely takes control out of their hands, like WatchKit.

Re: SwiftUI Defaults Considered Harmful

#92

Earlier quoted context omitted.

Mostly the limited uptake (I anticipated that), and the maturity of the tools. I despise IB/Storyboard Editor, but it gives some serious control over a lot of stuff. I don’t mind doing programmatic tweaking, but on my machine, at least, I don’t get very reliable previewing. I have to run the app to get an idea of how my tweaks are working (to be fair, IBE is similar, but the preview is somewhat more reliable). I real…

Limited uptake by developers you mean? How do you determine that? I had two instances where the preview turned out to be a hassle (crashing, or hard to get it to work). First was a test project with Core Data. It was a hassle to set up the preview. So much so, that I often skipped it. Second instance was crashing; I'd created a View but the layout was based on something in UserDefaults, and I forgot about that. So wh…

Aw..heck. I'm not gonna get into back-and-forth.

I will say that I have been developing Apple software for 34 years, so I tend to be a little on the.."hard-boiled cynic" side.

I have taken OpenDoc and QuickDraw GX classes, because they were "The Next Big Thing."

I also busted my butt, making sure that my apps were "Copeland-ready" (Darn it, now I have to do fifty push-ups).

I've learned that it's a good idea to stand back a little, and let the eager beavers soak up the bullets.

I love Apple (see "34 years," above), but they are absolute Charisma 18 hype machine masters.

Re: SwiftUI Defaults Considered Harmful

#93
post #85

Earlier quoted context omitted.

Haven't we been going in the other direction in recent years? With integrated title bars in browsers, custom css, fonts etc.. Chrome on Windows, Mac, Linux etc. always looks like chrome but not native. Similarly webpages look "exactly like the designer intended" even if it is a very bad fit for your device. We used to do things generically, but changed to prescribing every little detail and this now breaks when our a…

Case in point: WhatsApp TestFlight betas recently gained support for dark mode, because they decided to do custom UI (and, honestly, not a terrible one) and it took ages for them to fix it up to support dark mode. Meanwhile, many native-iOS developers had dark mode support on day one, because they stuck closer to iOS conventions and didn't do as much custom UI.

Frankly I don't know what in the world you're talking about. WhatsApp is one of the best examples of a native iOS UI implementation. Looking at the app now, it clearly uses very lightly customized native UITabBarController, UINavigationController, UINavigationBarItem, UITableView, etc. The only examples of custom-built UI elements in WhatsApp only come from stuff like the camera view and the messages view. These are areas where Apple doesn't really provide ready-made UI classes in the first place.

Re: SwiftUI Defaults Considered Harmful

#94
post #84

Honestly, just use UIKit. SwiftUI is a bolt-on framework on top of UIKit to provide a React-like experience for web devs so they won’t rage too much when Apple inevitably bans ReactNative and Flutter.

SwiftUI is raising the abstraction layer and aiming to provide something much more productive than what UIKit currently offers. You've framed your comment as if web developers are cargo-culters who only know how to use React. The web has already experimented with classic MVC approaches (backbone etc.) and moved beyond it. Android's Compose is taking a similar approach, as is Flutter which as far as I can tell is not…

I don't believe they'll ban it. I do believe they'll increase friction to the point that it becomes a huge pain to use either for anything but prototyping.

Re: SwiftUI Defaults Considered Harmful

#95

Earlier quoted context omitted.

Limited uptake by developers you mean? How do you determine that? I had two instances where the preview turned out to be a hassle (crashing, or hard to get it to work). First was a test project with Core Data. It was a hassle to set up the preview. So much so, that I often skipped it. Second instance was crashing; I'd created a View but the layout was based on something in UserDefaults, and I forgot about that. So wh…

Aw..heck. I'm not gonna get into back-and-forth. I will say that I have been developing Apple software for 34 years, so I tend to be a little on the.."hard-boiled cynic" side. I have taken OpenDoc and QuickDraw GX classes, because they were "The Next Big Thing." I also busted my butt, making sure that my apps were "Copeland-ready" (Darn it, now I have to do fifty push-ups) . I've learned that it's a good idea to stan…

Leaning towards the careful end of the spectrum, I can respect that. Especially once you're fast with UIKit, and Auto Layout. And Auto Layout kinda proves your last point; there's absolutely nothing "auto" about it.

Re: SwiftUI Defaults Considered Harmful

#96
post #16

There are definitely a few things it does that are weird, and this article hits on a few of them. But, I'll call special attention to the whole "adaptive padding thing" as a broader signal for something I feel that SwiftUI does very, very right and more UI frameworks need to start thinking about. Its made to design iOS apps. iOS has a design language that (1) is relatively consistent, (2) changes over time, and (3) c…

Haven't we been going in the other direction in recent years? With integrated title bars in browsers, custom css, fonts etc.. Chrome on Windows, Mac, Linux etc. always looks like chrome but not native. Similarly webpages look "exactly like the designer intended" even if it is a very bad fit for your device. We used to do things generically, but changed to prescribing every little detail and this now breaks when our a…

We did use to do things generically, but more-or-less the wrong kind of generic.

Android is a great example of this. I don't know how things are done now, but for its first few years, they had screen size classifiers; ldpi (low dpi), mdpi, hdpi, etc.

Of course, devices got better. That set grew to ldpi, mdpi, hdpi, xhdpi, xxhpdi, and xxxhdpi. There's also tvdpi for televisions.

It was supposed to be generic. It became a mess, because they were operating at the wrong level of abstraction. But whats more; in the beginning, the `dpi` of a device was actually a consistent way to determine the screen size! I saw many apps in the day rely on this; they'd change the text sizes and paddings and even high level UI organization upon render by conditionally checking the dpi of the device. Its generic, right? Its not like I'm saying "if screen width is above 750px, render X" (cough css).

I know less about android as we approach closer to today, but I'm familiar with another problem they had concerning foldables. Android apps were never designed, from the start, to be able to respond to changes in screen size! So that required some new frameworks to be put in place, and old apps had to update.

Point being; our UIs have gotten more complex, because the problems they're solving have gotten more complex. We had HTML; a truly pure form of "generic UI design". But, it was designed for documents, not applications, so we built CSS and JS and wrote ourselves into the mess we're in today. Android had some ideas around generic UIs, but they too did not predict what people would actually be using their platform for and where technology was going.

SwiftUI is another stab at this, and maybe they'll get it right. I don't know. But, I think technology is settling a bit, and with that settling comes a greater understanding of what UI designers need from their frameworks.

Re: SwiftUI Defaults Considered Harmful

#97

Earlier quoted context omitted.

It’s hard to claim that JSX is more “just JavaScript” than SwiftUI. If anything I’d say it’s the opposite. Swift evolved the language hand in hand with SwiftUI so everything you see is standard there. And in my humble opinion they did a knockout job. And this is coming from someone whose spent a ton of time evangelizing React. SwiftUI is far more beautiful, pleasant to write, and well thought out. It does have a coup…

> It’s hard to claim that JSX is more “just JavaScript” than SwiftUI. If anything I’d say it’s the opposite. Yeah, that's fair. What I saw was that SwiftUI added special constructs to this DSL for if and ForEach statements, something which just isn't needed in JSX because it 'escapes' to JS fairly well. Definitely think they did a pretty decent job of it - I couldn't have done better (and I can't judge whether a bett…

You can map over things much like react, the ForEach is not quite as clean but you can still write your .map function in the body function and then just pass it where you want. I think the strict typed nature makes some of these things a little less flexible but it wins in many other categories.

I’d say give it a twist! If you like React you’ll like it, just has different trade offs.

Re: SwiftUI Defaults Considered Harmful

#98
post #16

There are definitely a few things it does that are weird, and this article hits on a few of them. But, I'll call special attention to the whole "adaptive padding thing" as a broader signal for something I feel that SwiftUI does very, very right and more UI frameworks need to start thinking about. Its made to design iOS apps. iOS has a design language that (1) is relatively consistent, (2) changes over time, and (3) c…

The point isn’t that adaptative spacing does a good job most of the time, it’s that it’s doing things it isn’t telling you about in code and you “just need to know” for when it isn’t doing a good job. Think about having to remember UI padding voodoo the couple days after you back from a vacation. The UIkit shouldn’t try and hide language normal commas, it shouldn’t try and imply “smart” or “magic” padding.

Similarly, We've all seen incomprehensible ten-thousand line CSS styles sheets, with layers of inheritance, where you're forced to grep through to find that one line on some ancestral class that controls the left padding for every h1 on the site... except this specific one, which I guess is using !important on its own class? Damn it.

So, what'll it be? We're talking about inherent complexity. Should it be application specific? Or should the platform take a stance on the Right Way? If we have a rule that holds in 95% of cases, embedding that rule into the platform itself does make sense, as long as you can escape hatch out in those 5% of cases it doesn't hold. It reduces the complexity developers have to hold in their head. Its no longer "Oh, yeah, I need padding on that, how much? 4 pixels I guess. Is that standard? Wait, no, i think we moved to 8px recently. Or, wait did we move this to 'em'?". Its just "I need padding. I'm adding padding. On to the next thing."

Your company isn't special. The problems we're each solving are more alike each other than not. Embrace the magic. Learn it. It'll make your life easier, and your software better.

Re: SwiftUI Defaults Considered Harmful

#99
post #31

Earlier quoted context omitted.

That said, current iOS 13 adoption rate is already at 93%...

Citation? I just checked " rel="nofollow">https://mixpanel.com/trends/#report/ios_13> and it shows iOS at 85%. About a month ago, I started releasing versions of our app on iOS 13 in TestFlight (I wanted to use the new SF Symbols) only to discover there are a lot of iPhone6 models out there. My first reaction, was "c'mon, that's a 6 year old iPhone, time to move on!" until I found that Apple kept selling the 6 all th…

I asked this question because I still use an iPhone 6, and can't update past iOS 12. My MacBook Pro from 2013 can upgrade to Catalina and handle developing with it, but I'd rather have a compatible device than rely on the phone simulators.

Re: SwiftUI Defaults Considered Harmful

#100
post #40

Earlier quoted context omitted.

Surely JSX is ... well it's something that looks a lot like XML, hence the name. It's not just JavaScript, is it? It's pretty much the definition of embedding a DSL. I've not used SwiftUI but I've used TornadoFX which is similar, but with Kotlin instead of Swift. There's no weird syntax or DSLs (even though they call it that). It's all just functions and lambdas, so the language is always there and the syntax is alwa…

JSX is 'just' an XML-like syntactic sugar for making nesting function calls nicer in Javascript. Yes, its a DSL, but it keeps the "domain" extremely small and it transpiles in a very straightforward way down plain javascript madeofpalk // is syntactic sugar for React.createElement(Container, null, React.createElement(Text, { weight: "bold" }, "madeofpalk"), React.createElement(Image, { src: profilePic }) ); Whenever…

I guess I'm not sure why this is better than the Kotlin/Tornado/SwiftUI approach of allowing you to move a lambda in the last parameter visually out of the function. So:

    container {
        text(weight = "bold") { "madeofpalk" }
        image(src = profilePic)
    }
It seems more logical and consistent with the rest of the language. The only reason for the HTML-like syntax is JavaScript's tight connection to the web, after all.
Post reply on HN