3 ms·
> structs in Swift are the same as structs in Rust, and a class is a heap-allocated reference counted box, like an Arc<Box<T>>. Yeah, and by representing the d
by ii41 3y ago
> structs in Swift are the same as structs in Rust, and a class is a heap-allocated reference counted box, like an Arc<Box<T>>.
Yeah, and by representing the differences this way, Rust allows you to easily decide whether an object is used directly or is wrapped in a rc box when its used, instead of when it's defined, often not by you, and when you change your mind you don't need to change all methods or functions than mutates it and all their call sites.
> Result builders are a language feature and not part of SwiftUI
I admit that this is the first time I see the term result builders. This is never mentioned in any SwiftUI documentation I've seen, so I guess I should extend my complaint to include quality of docs :p. Whatever this is called you seem to agree that the syntax is hacked and it can get hard to understand what something means
- slavapestov 3y ago> Yeah, and by representing the differences this way, Rust allows you to easily decide whether an object is used directly or is wrapped in a rc box when its used, instead of when it's defined, often not by you, and when you change your mind you don't need to change all methods or functions than mutates it and all their call sites Changing a value type into a reference type is a pretty fundamental transformation because your local mutations now become non-local. Its not clear the Rust approach makes this any easier either, since you’d still have to update all call sites that perform mutation if suddenly one of your value types was now always wrapped in a box. > Whatever this is called you seem to agree that the syntax is hacked and it can get hard to understand what something means Result builders are just a way to build data types from the results of top-level expressions (hence their name). It’s not just a SwiftUI thing, they’re also used for regular expressions for example: https://github.com/apple/swift-evolution/blob/main/proposals/0351-regex-builder.md https://github.com/apple/swift-evolution/blob/main/proposals...
- plorkyeran 3y agoThe regex result builder is awful. It's very obviously a feature which was developed to make SwiftUI look good in WWDC presentations at the expense of everything else, and no one's found anything that they're actually useful for even with some effort to pretend that it's not just there for SwiftUI.
- bsaul 3y agothis trend of apple building api that only serves to make good-looking wwdc talks but fall short under real life usage is one of the worst things... It has now reached a point where people don't trust anything apple dev say during those presentations, because they know there's a limitation hidden somewhere.
- cdcarter 3y agoI spent some time with Swift-on-the-server last year and definitely felt like the class/struct difference made sense. But I have to agree, from a novice eye at least, result builders look to be a feature added to support SwiftUI and limited other use cases. Have you seen many examples of third party libraries successfully using them? And while we're here, do the introduction of macros in Swift 5.9 allow room for replacing result builders with something more uniformly useful?
- jurip 3y agoResult builders are pretty popular in third party libraries, too. There's good use of them in Pointfree's libraries Parsing (https://github.com/pointfreeco/swift-parsing https://github.com/pointfreeco/swift-parsing) and Composable Architecture (https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/migratingtothereducerprotocol/ https://pointfreeco.github.io/swift-composable-architecture/...). A quick search in the package index also finds things like these: - https://swiftpackageindex.com/davidcaddy/DCSettings https://swiftpackageindex.com/davidcaddy/DCSettings - https://swiftpackageindex.com/tdeleon/relax/2.1.0/documentation/relax/definingrequests https://swiftpackageindex.com/tdeleon/relax/2.1.0/documentat... - https://swiftpackageindex.com/mkj-is/PathBuilder https://swiftpackageindex.com/mkj-is/PathBuilder - https://swiftpackageindex.com/Saelyria/Artemis https://swiftpackageindex.com/Saelyria/Artemis - https://swiftpackageindex.com/FluidGroup/MondrianLayout https://swiftpackageindex.com/FluidGroup/MondrianLayout etc.