PROPOSAL: Templated Construction Expressions (i.e., Expressions Embedded in Strings) (original) (raw)
Per Bothner per at bothner.com
Mon Mar 30 19:20:25 PDT 2009
- Previous message: PROPOSAL: Templated Construction Expressions (i.e., Expressions Embedded in Strings)
- Next message: PROPOSAL: Templated Construction Expressions (i.e., Expressions Embedded in Strings)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 03/30/2009 05:39 PM, John Rose wrote:
For Java, to extend the string syntax and emphasize that a new string is being constructed, I recommend this:
new "$foo, ${bar}s."
A big advantage of templated strings is that they lend themselves nicely to Localization. That is a big advantage over using
- between strings. We did this for JavaFX:
http://openjfx.java.sun.com/current-build/doc/reference/ch02s03.html http://jfx.wikia.com/wiki/Proposal_for_the_string_literal_translation http://learnjavafx.typepad.com/weblog/2008/01/string-literal.html
If you allow templated strings it is temping to also allow multi-line templated strings, because then you have a nice template engine for free. If we allow multi-line strings it seems a good idea to have distinct open and closing string delimiters, to catch errors and help IDEs. For example (wild off-the-top-of-my-head idea) <" and ">
String x = <"Name: $(name) Address: $(address)">;
(The proposal to use """ for both open and closing delimiters is very IDE-unfriendly. Imagine trying to do syntax highlighting and checking as the user is entering a program or makes a typo ...)
You'd mark a localized string with some extra marker, for example:
String x =
<"Name: $(name)
Address: $(address)">;
--Per Bothner
per at bothner.com http://per.bothner.com/
- Previous message: PROPOSAL: Templated Construction Expressions (i.e., Expressions Embedded in Strings)
- Next message: PROPOSAL: Templated Construction Expressions (i.e., Expressions Embedded in Strings)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]