3 ms·
I still have no idea where macros fit into a project, or why I would want to use them. They seemingly built this functionality for SwiftUI previews maybe?! and
by jarjoura 2y ago
I still have no idea where macros fit into a project, or why I would want to use them. They seemingly built this functionality for SwiftUI previews maybe?! and didn't really consider how this could be a core part of the language.
At least with rust, you can just lightly add them in the same module and at a minimum use them to avoid boilerplate code duplication. Macros in rust work as a core language feature because of the way the borrow checker works. You can't really break apart some methods since you need to establish ownership. So, you can easily end up with duplicated code that gets noisy. Macros are the escape hatch to do that, and yes, they are also complex to write, but at least I know when I'd want to use them.
Swift doesn't really document how to create macros, and they didn't really spend energy explaining how they would be valuable to a project and worth the engineering cost of implementing them.
- pjmlp 2y agoThey fit into the same way as C, C++, Lisp, Scheme, Rust, Scala... macros, Java and Kotlin compiler plugins, .NET code generators, do fit into a project. There are several WWDC sessions about how and why.
- jen20 2y agohttps://docs.swift.org/swift-book/documentation/the-swift-programming-language/macros/ https://docs.swift.org/swift-book/documentation/the-swift-pr... seems to do both to me?