First, I still support @resultBuilder as a suitable name. Previous posts outline my thoughts, so I won’t revisit them here.
But I also understand people’s concerns with the name, especially since I initially had many of the same reservations, so I wanted to explore another avenue.
In the previous review @michelf had brought up the possibility of naming the feature @adjectiveBuilder with the qualifier based on some other attribute besides what is being built.
That possible approach has stuck with me since I read it, and to paraphrase @JJJ, the naming discussion has also led me to think more about the nature of the feature itself.
Along these lines, I went back to the first time I learned about this feature, which was in the SwiftUI Essentials session at WWDC 2019.
The session doesn’t reference the feature directly, but it talks about the key benefit that it enables:
This is because SwiftUI defines its views declaratively as opposed to imperatively.
…
Declarative code involves building a result by describing what you want but letting someone else figure out how to make it for you.
Regardless of the mechanics of how it accomplishes its task, it seems like the central purpose of this feature is to allow a result to be built using a declarative syntax.
With this in mind, I think @declarativeBuilder might also be a suitable name.
The name doesn’t try to explain exactly how it gets its job done, which I think might be impossible to do both accurately and succinctly for a complex feature like this.
But it does tell you the main reason a type with this annotation exists: to allow a result to be built declaratively.
The name also highlights the significant effect this feature has on Swift code, enabling a declarative dialect of Swift that is only valid in the context of one of these builders.
I am not sure of the full implications of staking out the word declarative for use in the name. But, I think it is very unlikely a different declarative builder syntax would be introduced and without a supporting language feature a Swift developer can’t create a different declarative builder syntax. So, I think it is a unique name with little chance of future collision.
(Note that I considered @declarationBuilder, but I think it suffers from the fact that this feature does not create declarations and also that declaration has a very specific definition and central role in Swift grammar.)
I still support @resultBuilder as a suitable name for the attribute and feature.
But I also think @declarativeBuilder might be a suitable alternative that addresses the concerns expressed about @resultBuilder.