(Sharing publicly on request.)
Here's why I think having DSL in the name is a better idea compared to naming it @returnValueBuilder
or @functionBuilder
.
- From an implementors' perspective: I think the types already convey that the thing being built is being returned. If the value built was not being returned, the types would be different. The complexity for an implementor is in understanding when/how to use the different methods, and a name cannot remove that complexity. So the marginal benefit of having "returnValue" in the name for implementors is minimal.
- For a library user's perspective: For Swift programmers not familiar with the feature, I think naming it
@returnValueBuilder
makes it easier to fall into the trap of thinking that you need to return the value, even though as a library user you can certain create local bindings with the values created by a builder. - For people coming from other languages: Kotlin already has a similar term
@DslMarker
for a similar language feature. https://kotlinlang.org/docs/reference/type-safe-builders.html - General searchability: If I search for
return value builder
on Google, I get 124M hits with all kinds of random stuff. In comparison,DSL builder
gets 2M hits, out of which Kotlin shows up at #3. I think the phrase "returnValueBuilder" comes across as overly generic and it is not obvious that it is referring to jargon if it comes up in a conversation and you haven't heard about the feature before. - Sharing knowledge: More broadly, I think that explicitly connecting the work to the notion of DSLs is a good idea. There is a lot of work done in different language communities on DSLs and enriching the vocabulary of the subset of Swift programmers who are not familiar with the term "DSL" is actively helpful. It allows them to connect what they are doing with things people in other programming languages are doing, facilitating cross-pollination of ideas through use of common terminology.
Regardless of whether this is the case today, I strongly suspect that we will see libraries pivot to using this new language feature, even if it's not strictly necessary. This is based on my experience in the Haskell community, where some libraries make their common types monads (even when the monad instance is unlawful), so that clients can use the do-notation sugar. By adding this language feature, what is being implied (even if it is not explicitly spelled out) is "here is a blessed way to create DSLs in Swift, which will allow your library's clients to use this nice syntax". I think this warrants the feature having DSL in the name.