<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>full fathom five: Tag languages</title>
    <link>http://www.michaelstudman.com/fullfathomfive/articles/tag/languages?tag=languages</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>the blog of Michael Studman</description>
    <item>
      <title>Amnesiac Java: language features I forgot existed</title>
      <description>&lt;p&gt;
I've been developing in Java for pretty much since Java 1.0. While working on the ANTLR Java 5 grammar I was suprised to rediscover some features of the language I'd just plain forgot.
&lt;/p&gt;
&lt;p&gt;
First up, while working on annotation array initialisers, I was pleasantly reminded that the final element of a regular array can have a trailing comma:
&lt;/p&gt;
&lt;pre&gt;
    String[] foo =
        new String[]
        {
            "qwerty1",
            "qwerty2",
            "qwerty3",
        };
&lt;/pre&gt;
&lt;p&gt;
This is a nice little convenience for when you need to expand or contract the array elements in the initialiser - it means you don't have to fiddle with the final element to make sure there is no trailing comma.
&lt;/p&gt;
&lt;p&gt;       
Later I was reminded that interfaces may be package protected. For some reason i'd deluded myself into thinking interfaces could only be public:
&lt;/p&gt;
&lt;pre&gt;
    package foo;
    interface Bar {}
    ...
    package foo2;
    class Bar2
    {
       foo.Bar b;
           //compilation error: foo.Bar can't
           //be accessed from outside its package
    }
&lt;/pre&gt;    
&lt;p&gt;
Duh! How could I have lived without that one? I often complained to co-workers that I couldn't do this - by their response they obviously didn't know you could either.
&lt;/p&gt;
&lt;p&gt;
Finally, I was recently reminded that you can use the .class 'field' on primitive types:
&lt;/p&gt;
&lt;pre&gt;
    Class c = int.class;
&lt;/pre&gt;
&lt;p&gt;
I've long been aware of this 'field' on regular classes and interfaces (e.g. String.class) but when faced with the need to get the class of a primitve type I'd use the helper fields (e.g. Integer.TYPE). This forgotten feature is nicely consistent.
&lt;/p&gt;
&lt;p&gt;
I use quotations around the word field here because it's not really a field, just a few grains of syntactic sugar (decompile a class that uses the .class 'field' to see what I mean).
&lt;/p&gt;
&lt;p&gt;
What's your forgotten language feature?
&lt;/p&gt;</description>
      <pubDate>Thu, 26 Aug 2004 23:00:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:9ed0ce8d-cb48-41e6-8666-49b1a95db65b</guid>
      <author>Michael Studman</author>
      <link>http://www.michaelstudman.com/fullfathomfive/articles/2004/08/26/amnesiac-java-language-features-i-forgot-existed</link>
      <category>Java</category>
      <category>Java/J2EE</category>
      <category>codegargle</category>
      <category>languages</category>
      <trackback:ping>http://www.michaelstudman.com/fullfathomfive/articles/trackback/25</trackback:ping>
    </item>
    <item>
      <title>My Java 5 Antlr grammar</title>
      <description>&lt;p&gt;
After years of toying with Antlr but never actually doing anything useful with it; and after months of merely skimming articles on new Java 5 language features I thought I&amp;#8217;d deepen my understanding of both and update the Antlr Java 1.4 grammar to recognize the new language features.
&lt;/p&gt;
&lt;p&gt;
Suprisingly it only took about a week to polish off, and most of that was spent just cleaning up the grammar and deciding between different ways to structure the output &lt;span class="caps"&gt;AST&lt;/span&gt; (rather than strugling with Antlr tool itself).
&lt;/p&gt;
&lt;p&gt;
For anyone interested, my grammar can be found on &lt;a href="http://www.michaelstudman.com/files/java15/index.html"&gt;my site&lt;/a&gt; and it&amp;#8217;s also hosted at &lt;a href="http://www.antlr.org/grammar/1090713067533/index.html"&gt;antlr.org&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
As for how well tested it is: I&amp;#8217;ve used it to successfully recognise the entire Java 5 source base, jdigraph&amp;#8217;s source base (an early adopter of generics) and some custom tests I developed. I found the accompanying &lt;span class="caps"&gt;AST&lt;/span&gt; recogniser (as opposed to the token stream recogniser) is a good tool for confirming your tree is structured as you expected it to be. I also visually inspected the &lt;span class="caps"&gt;AST&lt;/span&gt; to ensure its structure was what I expected. An alternative to visual inspection would be great to automatically ensure the grammar stays correct over a lifetime of modifications. I&amp;#8217;d love to hear from anyone who&amp;#8217;s worked on such a tool. A testing framework that used XQuery or XPath querying/assertions on &lt;span class="caps"&gt;DOM&lt;/span&gt;-adapted &lt;span class="caps"&gt;AST&lt;/span&gt; (similar to &lt;span class="caps"&gt;PMD&lt;/span&gt;&amp;#8217;s &lt;span class="caps"&gt;AST&lt;/span&gt; interface) would be my first approach. Comments or experience anyone?
&lt;/p&gt;
&lt;p&gt;
More comments on Antlr and Java 5&amp;#8217;s new language features later.
&lt;/p&gt;</description>
      <pubDate>Sat, 24 Jul 2004 23:00:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:9f39d8d3-0f2a-4a33-af5c-faea0b54dc73</guid>
      <author>Michael Studman</author>
      <link>http://www.michaelstudman.com/fullfathomfive/articles/2004/07/24/my-java-5-antlr-grammar</link>
      <category>Java</category>
      <category>Java/J2EE</category>
      <category>antlr</category>
      <category>grammar</category>
      <category>languages</category>
      <category>codegargle</category>
      <trackback:ping>http://www.michaelstudman.com/fullfathomfive/articles/trackback/45</trackback:ping>
    </item>
    <item>
      <title>I'm a Grammar God</title>
      <description>&lt;p&gt;
According to &lt;a href="http://quizilla.com/users/BaalObsidian/quizzes/How%20grammatically%20sound%20are%20you%3F/"&gt;BaalObsidian&lt;/a&gt; , I&amp;#8217;m a grammar God!
&lt;/p&gt;
&lt;p&gt;
Here&amp;#8217;s their &lt;span class="caps"&gt;HTML&lt;/span&gt; badge to prove it: &lt;br /&gt;
&lt;img src="http://images.quizilla.com/B/BaalObsidian/1080162080_cturesgod3.jpg" alt="Image of Grammar God!" /&gt;&lt;br /&gt;You are a &lt;b&gt;&lt;span class="caps"&gt;GRAMMAR GOD&lt;/span&gt;&lt;/b&gt;!
&lt;br /&gt;&lt;br /&gt;If your mission in life is not already to&lt;br /&gt;preserve the English tongue, it should be.&lt;br /&gt;Congratulations and thank you!
&lt;br /&gt;&lt;br /&gt;&lt;a href="http://quizilla.com/users/BaalObsidian/quizzes/How%20grammatically%20sound%20are%20you%3F/"&gt; How grammatically sound are you?&lt;/a&gt;&lt;br /&gt;brought to you by &lt;a href="http://quizilla.com"&gt;Quizilla&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
I think they mean the American English tongue, though.
&lt;/p&gt;</description>
      <pubDate>Sat, 12 Jun 2004 23:00:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:d4221d5d-c939-47a0-abaa-60df74b4fa05</guid>
      <author>Michael Studman</author>
      <link>http://www.michaelstudman.com/fullfathomfive/articles/2004/06/12/im-a-grammar-god</link>
      <category>Miscellaneous</category>
      <category>grammar</category>
      <category>badges</category>
      <category>codegargle</category>
      <category>languages</category>
      <trackback:ping>http://www.michaelstudman.com/fullfathomfive/articles/trackback/55</trackback:ping>
    </item>
  </channel>
</rss>
