F3 and XML

Quite a few people have asked me why I didn't use XML markup for F3, or even whether F3 could be "translated" into XML.

Well, let me first tell you that it was intentional.

F3 is based on the idea that XML is not an effective syntax for a programming language that's supposed to be used by human programmers. Nevertheless, F3 provides the primary benefits other systems derive from XML and its supporting technologies, namely:

  • Declarative Syntax
  • Expression/Query Language with all of the power of XPath and XQuery

In addition, because F3 is a real object-oriented programmming language it allows you to factor your code the way we always have: namely be means of variables, subroutines, and class hierarchies.

Note that most if not all XML-based systems include some other embedded programming language, e.g. JavaScript or XPath or the EL of JSTL.

Finally, being a statically typed language F3 can provide IDE-support and compile-time error reporting equal in quality to what programmers are used to with Java. I'm not aware of any XML-based system that delivers a comparable user-experience for the programmer.

It may be surprising, however, to know that F3 was influenced by traditional web applications.

In a traditional web application you can "project" an HTML document from a set of Java beans by writing a "template". For example, in JSTL

<table>
   <tr>
     <th>
     Description
     </th>
     <th>
     Price
     </th>
   </tr>
   <forEach var="item" items="${cart.items}">
      <tr>
         <td>
         ${item.description}
         </td>
         <td>
         ${item.price}
         </td>
     </tr>
   </forEach>
</table>

Since, in traditional (non-AJAX) web-apps the page was regenerated every time, you could change your Java beans however you liked, and the page would appear to incrementally change without any additional programming (i.e, you didn't have to add "listeners" to the beans, respond to change events, and update the document yourself).

From my experience, the declarative syntax of the HTML template and the automatic regeneration of the pages, made writing web-based UI's way easier and faster than writing Swing programs.

In F3, the combination of declarative syntax, incremental evaluation, and list comprehensions brings that same ease of use to Swing and Java2D programming. For example, I can write a JTable in a manner similar to the one in the above example in F3 like this:

Table {
    columns: [TableColumn {text: "Description"}, TableColumn {text: "Price"}]
    cells: bind foreach (item in cart.items)
        [TableCell {text: bind "{item.description}"}, TableCell {text: bind "{item.price}"}]
}

As in the web-app example I can insert or delete items into/from the cart or modify the properties of an item and the table will automatically reflect my changes.

RSS Reader Demo

Having said all that, XML is still a reality and you may need to work with it in F3 programs. To enable that, we have an experimental add-on which plugs into F3 as an F3 class loader. This class loader reads XML Schema or WSDL documents and generates corresponding F3 classes (analagous to what JAX-B and JAX-RPC do for Java). The generated classes have methods to marshal and unmarshal XML documents and to invoke WSDL operations.

Below is an F3 program that uses this facility to create a simple RSS reader. It loads the RSS XML Schema and then reads the XML document at the URL you specify. This has the effect of populating corresponding F3 objects with the content of the XML document. Since these are first-class F3 objects, you can use F3 bindings on them as usual.

You can view the source code for this program by clicking its File->View Source menu.

Comments:

very cool!

Posted by guest on November 24, 2006 at 05:24 AM PST #

When you will allow us to play with it? It looks like F3 is very mature already (Java was waiting for this years).

Posted by Arek Stryjski on November 24, 2006 at 06:49 AM PST #

so...when do we get to play with it?

Posted by falcon on November 24, 2006 at 08:43 AM PST #

Probably when chaging the font for in interactive tutorial the example doesn't crash the applicaction. Or when the performance is better. That said the language looks very interessing, but i'm not so hot in the fact that all the examples given had no more than one source file. And the [] everywhere is fugly. But the bind keyword sounds divine!

Posted by guest on November 24, 2006 at 10:15 AM PST #

Oh and i'd like to know if any swing subclass already made in pure java can be used in the language. That would be very usefull.

Posted by guest on November 24, 2006 at 10:19 AM PST #

Did you consider using jruby?

Posted by Kees on November 25, 2006 at 01:16 AM PST #

Nice..i like it ; )

Posted by oyun,download,iddaa,resim on November 01, 2007 at 05:41 AM PDT #

Simple and Nice example !

Posted by شات on December 15, 2010 at 03:46 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

user12610627

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today