Here-docs

One of my favorite little features of scripting languages, like perl, ruby and groovy, is their support for here-documents. A here-document is a lot like a <pre> tag in html, but instead of declaring text for display you are declaring the contents of a string - line endings and all.



Instead of writing:




static String test =
"This is line 1\r\n"+
"This is line 2\r\n" +
"This is line 3\r\n" +
"This is line 4\r\n";



You get to write:




static String test = <<<END_OF_BLOCK
This is line 1
This is line 2
This is line 3
This is line 4
END_OF_BLOCK



This is a great little feature for embedding little languages like HTML, XML or the alternate regular expression syntax I've been talking about within another language.



There's a JSE for the feature on Sun's Java developer site. Please vote for it if you agree it's a good idea.

Comments

Popular posts from this blog

Shark Crackers

Running roughshod or ripshod

Axis, Axes, Axii?