fixed up bad markdown :)
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
== Warning experimental APIs
|
## Warning experimental APIs
|
||||||
|
|
||||||
This package contains a couple of alternative experimental implementations of string templates.
|
This package contains a couple of alternative experimental implementations of string templates.
|
||||||
|
|
||||||
These are not yet integrated into the language, but are here to compare implementation details,
|
These are not yet integrated into the language, but are here to compare implementation details,
|
||||||
suitability, code size, complexity and efficiency.
|
suitability, code size, complexity and efficiency.
|
||||||
|
|
||||||
=== Aims
|
### Aims
|
||||||
|
|
||||||
* make it easy to generate various kinds of output such as text, text with internationalisation, HTML/XML, JSON, URL/URLs or make JDBC calls while reusing the same language templates with $ expressions
|
* make it easy to generate various kinds of output such as text, text with internationalisation, HTML/XML, JSON, URL/URLs or make JDBC calls while reusing the same language templates with $ expressions
|
||||||
|
|
||||||
=== Issues
|
### Issues
|
||||||
|
|
||||||
* how many objects are created per call?
|
* how many objects are created per call?
|
||||||
* how extensible & easy to reuse the concept of String Templates in other library features
|
* how extensible & easy to reuse the concept of String Templates in other library features
|
||||||
@@ -17,7 +17,7 @@ suitability, code size, complexity and efficiency.
|
|||||||
* avoid where possible lots of "if (value is SomeType)" runtime checks to determine what encoding strategy should be used
|
* avoid where possible lots of "if (value is SomeType)" runtime checks to determine what encoding strategy should be used
|
||||||
|
|
||||||
|
|
||||||
==== experiment1
|
#### experiment1
|
||||||
|
|
||||||
Here we convert a string template into a function on some kind of builder object where we invoke the text() method for static text and expression() for dynamic expressions
|
Here we convert a string template into a function on some kind of builder object where we invoke the text() method for static text and expression() for dynamic expressions
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ Pro:
|
|||||||
* we can only use this strategy if the template expression is passed to a function and we can detect the function parameter takes a fn: (T) -> Unit; and T has suitable text() and expression() methods.
|
* we can only use this strategy if the template expression is passed to a function and we can detect the function parameter takes a fn: (T) -> Unit; and T has suitable text() and expression() methods.
|
||||||
(We can use extension methods to allow regular builder-like classes such as java.lang.StringBuilder to be used to minimise redundant object creation) - so the code generation is a bit more complex
|
(We can use extension methods to allow regular builder-like classes such as java.lang.StringBuilder to be used to minimise redundant object creation) - so the code generation is a bit more complex
|
||||||
|
|
||||||
==== experiment2
|
#### experiment2
|
||||||
|
|
||||||
Here we create a single StringTemplate object containing the constant text array and the values array. Then we use functions or extension functions as ways to do other things.
|
Here we create a single StringTemplate object containing the constant text array and the values array. Then we use functions or extension functions as ways to do other things.
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ Cons:
|
|||||||
* requires runtime instanceof checks on each expression value
|
* requires runtime instanceof checks on each expression value
|
||||||
* fair bit of object construction per call (2 arrays, a template object, then the string builder and lots of index lookup of arrays
|
* fair bit of object construction per call (2 arrays, a template object, then the string builder and lots of index lookup of arrays
|
||||||
|
|
||||||
==== experiment 3
|
#### experiment 3
|
||||||
|
|
||||||
The idea is we create a FooTemplate object with the static constant strings inside; so we can easily cache the immutable stuff on startup. Then we basically use pseudo code like
|
The idea is we create a FooTemplate object with the static constant strings inside; so we can easily cache the immutable stuff on startup. Then we basically use pseudo code like
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user