Live data from Hacker News

SwiftUI Defaults Considered Harmful

tonsky.me

61–70 of 135 posts

Re: SwiftUI Defaults Considered Harmful

#61
post #43
post #38

Earlier quoted context omitted.

After reading this I agree that SwiftUI terrible. I still don't get why it's considered "harmful" though.

This is basically a clickbait title at this point. After a now-famous CS letter by Dijkstra, "Go To Statement Considered Harmful"[1], the title format expanded dramatically. I'm personally a large fan of Meyer's '"Considered Harmful" Essays Considered Harmful'[2] as a explanation and satire of the genre. Wikipedia also has a decent summary[3]. 1: https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.p... 2: http…

This letter was also a classic example of how writers don't always choose titles, editors do.

Edsger Dijkstra's original title was "A Case Against the Goto Statement". Niklaus Wirth was editor of the Communications of the ACM (Association for Computing Machinery) at the time and changed the title to the now infamous "Go To Statement Considered Harmful".

Re: SwiftUI Defaults Considered Harmful

#62
> I hope you have a wide enough monitor to read this. Not only does this seem ad-hoc and unpretty, but it also doesn’t allow you to put more than 10 elements in a container! All because someone in charge of API design was afraid of lists and had more power than someone in charge of Swift language.

This explanation doesn't sound right to me coming from other statically typed languages where you're stuck either using codegen or arity hardcoding. Currying also gives a nice solution where your DSL simply builds up a function A->B->C->...

Hard-coding each level of arity is done so that your generics keep upstream type knowledge.

Here's an example in Elm, though it has to keep renaming the function due to lack of arity overloading.

https://github.com/elm/json/blob/063aaf05e0dc5a642bacbdaae59...

You can't use variadic functions because then you function doesn't even know how many arguments it has at compile time much less any specifics about them.

That Swift doesn't require commas between closure returns seems like a different point.

You'd still need this solution even if you were just spitting out generic TupleView, TupleView, etc.

Unless, of course, you don't actually care about type info the same way you don't care how many arguments are passed to a variadic max(1, 4, 66) function.

Another comment says there will be a variadic viewbuilder function once Swift gets variadic generic functions which will still throw away type info, so this seems to be the case. Still, I don't see the relationship with commas.

Re: SwiftUI Defaults Considered Harmful

#63

Earlier quoted context omitted.

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…

So it's reinventing PHP and Java Server Pages?

I’d say it’s a re-creation of what E4X brought to ECMAscript / Actionscript. Saying JSX is similar to PHP / JSP is a gross mischaracterization imho.

Re: SwiftUI Defaults Considered Harmful

#64
Just to point something out: his first complaint is over needing to have up to 10 generics, this will be going away with variadic ViewBuilders that should be coming soon, towards swift 6 perhaps. And will also remove the limit for number of children. This is mostly a limitation in swift generics, not swiftui it self

Re: SwiftUI Defaults Considered Harmful

#65

I'm in no hurry to start using SwiftUI. I'm giving it another year. That doesn't mean that I don't like it. I think it's a great idea. It's just having a hard time clambering out of the bassinet.

> It's just having a hard time clambering out of the bassinet What are the reasons for you to have this opinion?

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 really want this to work. I’m glad to see KVO getting some love on iOS.

Re: SwiftUI Defaults Considered Harmful

#66
I really don't agree with most of this post but I do find the function builder[0] feature that was introduced to support SwiftUI fairly overkill. I don't fully understand why they didn't use a lighter abstraction based on arrays and normal return values like React does instead of adding all this "magic", maybe there's a really good reason that I am not seeing.

All the other "magic" and defaults are excellent ideas because they encode Apple's Human Interface Guidelines[1] straight into the framework which helps you create apps for the different Apple platforms that will fit in and feel at home. With a web or React Native/Flutter/Cordova/... context this might seem jarring but the whole point is that an app it shouldn't be a completely free form canvas and the frameworks should make it easy to build a best in class HIG compliant Apple app.

0: https://www.swiftbysundell.com/articles/the-swift-51-feature...

1: https://developer.apple.com/design/human-interface-guideline...

Re: SwiftUI Defaults Considered Harmful

#67
I was really excited about SwiftUI after having done a lot of React development recently. The declarative style is so much nicer than the MVC/procedural code that regular UIKit code becomes.

After 30 minutes of updating Xcode I was able to start writing SwiftUI code. Then another 2 hours upgrading our Swift project to the latest version of Swift. I googled for documentation, found barely anything and the code samples on developer.apple.com were already outdated. I finally got something up and running, but _nothing_ in the semantics worked as expected. Getting a button to render nicely was insanely complex (which view should have the background color? font? trying different things didn't work at all). Oh and recompiling took a minimum of 30 seconds each time.

All this prompted me to finally give react-native a try. In under 15 minutes I had a working example. After making a change I saved the file, alt-tabbed to the simulator and the changes were already applied. And it works instantly on Android, I can try it out on my phone using expo without any hassle.

I just can't comprehend if and how Apple will catch up with that experience?

Re: SwiftUI Defaults Considered Harmful

#68

Earlier quoted context omitted.

> I hope you have a wide enough monitor to read this. Perhaps they're merely unaware of how their website looks?

Yeah, I did think it was amusing reading that on my 27" 2550px wide monitor monitor that the site formatted it so narrowly. https://i.imgur.com/VG31Kpj.png

For body copy that line length is pretty much ideal (for readability), but the code blocks could definitely benefit from being as wide as possible...

Re: SwiftUI Defaults Considered Harmful

#69
I really don't think this is a good criticism of SwiftUI.

The author is confused about the whole approach to SwiftUI and spends a lot of words complaining about issues arising out of that confusion. E.g., SwiftUI doesn't use Swift's DSL capability to avoid commas. It uses it to have a declarative DSL integrated into Swift programs. You could argue about the entire approach, but instead the author complains about commas and ifs. The things about the ifs and other potential control flow constructs makes it clear that the author doesn't get what a declarative approach really means.

Likewise, the section about "wraps" where the author feels the SwiftUI API is inconsistent because stacks "wrap" and padding "wraps" so they should use the same syntax. But I think that's just a misunderstanding of the author's. "wrapping" isn't a fundamental concept of SwiftUI so there's no particular reason for the API to be organized around it. (I would say stacks arrange a list of views and padding pads a view. Also, bold() operates on Text and returns Text because Text holds styled text and bolded Text is still Text. padding operates on any View and returns some View. The types flow naturally from the problem domain, so that's good.)

Also the conclusion: "The solution…is to be dumb and explicit!" That's really asking for a completely different framework. It seems a little off to criticism SwiftUI for not being what it was never intended to be.

I think there is good criticism in here, though. SwiftUI introduces a LOT of patterns, concepts, many of which will not already be familiar to many developers. It's concise and reads pretty intuitively, but many developers won't get far before hitting a lot of new stuff... that means steep learning curves and confusion, like the author. I don't know if that makes it bad, but it's certainly anyone consider using it needs to be aware of.

Re: SwiftUI Defaults Considered Harmful

#70

I was really excited about SwiftUI after having done a lot of React development recently. The declarative style is so much nicer than the MVC/procedural code that regular UIKit code becomes. After 30 minutes of updating Xcode I was able to start writing SwiftUI code. Then another 2 hours upgrading our Swift project to the latest version of Swift. I googled for documentation, found barely anything and the code samples…

”after having done a lot of React development recently […] All this prompted me to finally give react-native a try. In under 15 minutes I had a working example“

I agree SwiftUI is poorly documented and (from what others say), probably, not quite production ready, but I also guess that comparison is a bit unfair. Or are react and react-native completely different beasts?

Post reply on HN