4 ms·
That Kotlin page calls them "Groovy-style", perhaps because many of those working on Kotlin (e.g. James Strachan, Alex Tkachman) used to develop the Groovy Lang
by vorg 14y ago
That Kotlin page calls them "Groovy-style", perhaps because many of those working on Kotlin (e.g. James Strachan, Alex Tkachman) used to develop the Groovy Language.
But doesn't Ruby also have those builders? Wouldn't it be easy enough for Scala to implement them in a library if they haven't already? Wouldn't Python also provide this type of syntax? E.g. a possible translation into Python from the Kotlin code on the linked page...
html:
head:
title {"XML encoding with Python"}
body:
h1 {"XML encoding with Python"}
p {"this format can be used as an alternative markup to XML"}
// an element with attributes and text content
a(href = "http://python.org") {"Python"}
// mixed content
p:
"This is some"
b {"mixed"}
"text. For more see the"
a(href = "http://python.org") {"Python"}
"project"
p{"some text"}
// content generated by
p:
for (arg in args) arg
So what are they called "Groovy-style" builders for?
- meddlepal 14y agoI program in Groovy daily. "Groovy-style" builders are just sugar over the Builder pattern via heavy use of closures - so in reality they can be used anywhere an Object needs to be constructed. So yea, any language which supports closures should be able to do "Groovy-style" builders.
- bartonfink 14y agoPresumably because, among the languages (and standard libraries) you mentioned that have implemented this pattern, Groovy is the language that is most tightly associated with the JVM (which Kotlin is obviously targeting).
- vorg 14y ago> Groovy is the language that is most tightly associated with the JVM That could've been very true 6 years ago, when Groovy 1.0 was released, but I'd have to challenge that for 2012 (and 2013).