<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>java rants &#187; admin</title> <atom:link href="http://www.javarants.com/author/admin/feed/" rel="self" type="application/rss+xml" /><link>http://www.javarants.com</link> <description>Rants about Java and other internet technologies by Sam Pullara</description> <lastBuildDate>Sun, 09 Oct 2011 23:29:31 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Static-typing is a powerful metadata database, exploit it!</title><link>http://www.javarants.com/2010/06/16/static-typing-is-a-powerful-metadata-database-exploit-it/</link> <comments>http://www.javarants.com/2010/06/16/static-typing-is-a-powerful-metadata-database-exploit-it/#comments</comments> <pubDate>Thu, 17 Jun 2010 00:20:47 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[Technology]]></category> <guid
isPermaLink="false">http://www.javarants.com/?p=1331</guid> <description><![CDATA[Today someone decided to pretend they knew something about how a modern statically typed language developer works.  Perhaps they are big emacs fans or something because they felt that static-types leading to autocomplete in an IDE was somehow a feature &#8230; <a
href="http://www.javarants.com/2010/06/16/static-typing-is-a-powerful-metadata-database-exploit-it/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Today someone decided to pretend they knew something about how a modern statically typed language developer works.  Perhaps they are big emacs fans or something because they felt that static-types leading to autocomplete in an IDE was somehow a feature in the language FOR THE IDE.  The IDE gets no benefit, in fact, editors like emacs and TextMate are much simpler. But I can tell you that the developer gets a tremendous benefit by having this metadata database not only present in the code and easily queryable but heavily exploited by her tools.  What is amazing about this metadata database is that it is actually populated by that same IDE.  There are very few times that I even type a Type &#8212; 90% of those times are when declaring a new Type &#8212; the rest of the time the IDE is very patiently maintaining and leveraging that database for me.  Even better, when someone else is looking at the source code, or even using the library, they instantly get 80% of the documentation. All that is left are the semantics of the calls. Perhaps we need to have some sort of meetup where we look over each others shoulders and actually understand how someone who is on the other side really works rather than dynamic-typing language people assuming that the programmer is maintaining the huge metadata database present in the static-typing language developers code.  And on the otherside that static-typers are assuming that the dynamic-typing language developer is memorizing all kinds of arcane method call names, argument shapes and the shapes of all the libraries they are using. Do you really memorize all that trivia?</p> ]]></content:encoded> <wfw:commentRss>http://www.javarants.com/2010/06/16/static-typing-is-a-powerful-metadata-database-exploit-it/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Building the ideal web application template engine</title><link>http://www.javarants.com/2010/06/16/building-the-ideal-web-application-template-engine/</link> <comments>http://www.javarants.com/2010/06/16/building-the-ideal-web-application-template-engine/#comments</comments> <pubDate>Wed, 16 Jun 2010 18:02:03 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[Technology]]></category> <guid
isPermaLink="false">http://www.javarants.com/?p=1327</guid> <description><![CDATA[A month and a half ago I had put out a call for what I was calling the &#8216;ideal web application template engine&#8216; along with a list of requirements that I thought would be present in such a system.  Since &#8230; <a
href="http://www.javarants.com/2010/06/16/building-the-ideal-web-application-template-engine/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>A month and a half ago I had put out a call for what I was calling the &#8216;<a
href="http://www.javarants.com/2010/05/03/the-ideal-web-application-templating-system/">ideal web application template engine</a>&#8216; along with a list of requirements that I thought would be present in such a system.  Since then I looked a bunch of them and decided that I like the simple markup that <a
href="http://mustache.github.com/">mustache</a> defined but none of the implementations were up to doing what I wanted.  This led me to embark on building a new engine with for that markup for my chosen platform, Java, which I called creatively, <a
href="http://github.com/spullara/mustache.java">mustache.java</a>.  Though it claims to be &#8216;logic-less&#8217; I would say that it has some amount of logic. It will loop over a set of objects and it will check booleans, but I think it is about as close to logic-less as you would want to be in a template language.  So, let&#8217;s look at each of the requirements and how I ended up implementing them:<br
/> <span
id="more-1327"></span></p><ul><li><em>Works well with HTML5/CSS3 progressive enhancement</em></li></ul><p>This one is straight-forward.  Because I put no limitations on the generated text you can actually generate almost anything with mustach.java, in fact, I am using it in another <a
href="http://github.com/spullara/avrocompiler">project</a> to generate Java source for Avro objects.  It is really overkill for that project but it is so easy to use that I used it anyway.</p><ul><li><em>Allows mock data within the template that is replaced at runtime</em></li><li><em>Client-side version that leverages the mock data for shift-reload debugging</em></li></ul><p>These I implemented somewhat differently from the requirement because the mustache template language is not tag based.  I have actually thought about whether it might make sense to make it tag-based and get the full requirement, but I digress.  What I did get to is a system that is easy for a frontend developer or designer to use without having the whole system running on their machine.  Included with mustache.java is a mini-server (called <strong>handlebar</strong>, thanks for the name <a
href="http://lukew.com">Luke</a>) that combines mock json data with mustache.java templates. This lets them view a fully rendered version of the page they are working on with the required templating information that will be used in production but without running a big production system. In fact, because mustache.java dynamically generates and compiles Java code, they can fire up <strong>handlebar</strong> in directory along with their mock data and just keep reloading the page to see the effect of changes they make.</p><ul><li><em> Composable components, not monolithic pages</em></li><li><em><em>Very little or no business logic in the templates</em></em></li></ul><p>The choice of mustache as a base template language ensured that this would be the case.  Including a partial within a template is easy and makes pages very easy to compose. I still miss the Django template style <em>extends/block</em> system and may extend mustache to support it. Having to remember to include things like the header and footer on every page doesn&#8217;t seem necessary.  As I said above, I think that mustache has the minimum reasonable logic.</p><ul><li><em>Concurrent evaluation possible</em></li></ul><p>This one was very important to me from a performance perspective. My implementation makes every effort to be as low latency as possible for the end user.  At every possible point in template evaluation things are actually executed in separate threads or purely asynchronously in the case of external I/O like HTTP requests to other services.  The one last thing I am going to do here is to allow not only a straight-line evaluation of the template but the possibility of specifying a timeout so that you can return different markup if evaluation doesn&#8217;t return in time. It may be unnecessary to have this in the base template engine though, still looking at the design of the feature.</p><p>So how easy is using the template system?  I think I can answer that question by looking at the relevant portions of the <a
href="http://github.com/spullara/mustache.java/blob/master/handlebar/src/main/java/com/sampullara/mustache/Handlebar.java">implementation of </a><strong><a
href="http://github.com/spullara/mustache.java/blob/master/handlebar/src/main/java/com/sampullara/mustache/Handlebar.java">handlebar</a>:</strong></p><pre>final MustacheCompiler mc = new MustacheCompiler(new File("."));
....
Mustache mustache = mc.compile(new BufferedReader(new FileReader(filename)));
FutureWriter fw = new FutureWriter(res.getWriter());
File file = new File(mocks, base + ".json");
if (file.exists()) {
  BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
  JsonParser parser = jf.createJsonParser(bis);
  JsonNode json = parser.readValueAsTree();
  mustache.execute(fw, new Scope(json));
} else {
  mustache.execute(fw, new Scope());
}
fw.flush();</pre><p>The most interesting part of this is the FutureWriter. The future writer lets mustache write evaluated templates completed out of order in template order.  The scope is essentially a sophisticated context object that knows how to pull data from Java objects of various types, including raw object fields and methods, Maps and Json objects. Conveniently, you can also store values in it directly. There are some things I would like to extend at some point, however, for all practical purposes the template system is finished.</p> ]]></content:encoded> <wfw:commentRss>http://www.javarants.com/2010/06/16/building-the-ideal-web-application-template-engine/feed/</wfw:commentRss> <slash:comments>14</slash:comments> </item> </channel> </rss>
