I wonder if there was (or still is) a way to do something similar for Swift and SwiftUI.
I wonder if there was (or still is) a way to do something similar for Swift and SwiftUI.
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 couple awkward points but it’s not the “DSL” or it’s defaults (it’s just Swift) which is fine, it’s all on the dev tooling, performance, debugging, random bugs, and error messaging side of things (ie, maturity).
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 better job could have been done, I know next to nothing about Swift, hence my initial question), but it does strike me as unfortunate that they needed to specially re-create basic language features.
I’d say give it a twist! If you like React you’ll like it, just has different trade offs.
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 always consistent with what you use elsewhere. It's not like React/JSX where UI code syntactically looks different.
<Container>
<Text weight="bold">madeofpalk</Text>
<Image src={profilePic} />
</Container>
// is syntactic sugar for
React.createElement(Container, null,
React.createElement(Text, { weight: "bold" }, "madeofpalk"),
React.createElement(Image, { src: profilePic })
);
Whenever you need 'logic', you just escape out to javascript with braces <Container>
{ isVerified ? <Tick /> : null }
<Text weight="bold">madeofpalk</Text>
<Image src={profilePic} />
</Container>
JSX has no conditional syntax, no ternaries or any extra constructs apart from how to nest children. This is I think a simplicity that would have been nicer to see in SwiftUI. 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.JSX does not have conditionals or loops in its syntax. SwiftUI does.
This is all UI logic. Should a button be displayed or not. How large should this rectangle be. React encourages you to place that logic close to where it's used so it's easier to understand.
The line React devs has used is when people look at JSX and shout "separation of concerns", what they're really grasping at is "separation of languages".
e.g.:
<Foo var={'a'}>
<Bar />
</Foo>
Becomes something like: React.createElement(Foo, { var: 'a' }, React.createElement(Bar))
It all boils down to React.createElement(component, props, ...children)
https://reactjs.org/docs/react-without-jsx.htmlSwiftUI is a definite move away from interface builder.
Why wouldn’t Apple be able to switch XML with a Swift DSL and keep the Interface Builder UI intact after most of the biggest SwiftUI issues get fixed?