Monday, November 21, 2011

The Examples Speak For Themselves

In the previous two blogs, I've talked about the problems of XML and how Candle Markup addresses these problems. In this blog, I'll show you how Candle Markup can effectively express different kinds of structured data. "A good example is the best sermon." So I'll let the examples speak for themselves.
 
(due to the limited editing capabilities of Blogger.com, I have to post the examples at CandleScript.net)

 
From the examples, you can see that Candle Markup has a very expressive syntax and flexible data model, with which you can easily invent your own pseudo DSLs to suit your application and still enjoy all the benefits of a general markup format. Just to reiterate the advantages of a general markup format over a domain-specific format:
  • easier-to-learn: your application user do not have to learn all kinds of abstract domain-specific syntaxes;
  • easier-to-use: you'll be able to leverage the tools that supports advanced editing, validation, refactoring on the general markup format;
  • easier-to-process: you'll be able to use advanced scripting features, like schema, path selection, query, transformation and CRUD update on the general format;
Take note that the examples are created to demonstrate the syntactic expressiveness and readability of Candle Markup, rather than to set good examples for application or domain modeling in Candle. When you invent a very terse representation, it might not have a very structured data model behind it. For example, the math formula like x "=" +{ "-"b "+-" sqrt{b sup 2 "-" 4 a c}} over _{2 a} might be very readable but can be hard to process with flat lists of nodes. A more structured representation could be:

math {
  in {
    i{x}
    divide {
      plus-minus {
        minus { i{b} }
        root {
          minus {
            power { i{b} 2 }
            times { 4 i{a} i{c} }
          }
        }
      }
      times { 2 i{a} }
    }
  }
}
No matter you prefer a terse format or a structured format, the power is now in your hand. Candle supports both equally well, and can easily transform one into the other.
 

9 comments:

  1. You seem to be doing some incredible work here.
    I'm curious, there seems to be no organisation or institution behind you, is that correct?
    You also need adoption. Do you have a sense of how or who in this regard?

    ReplyDelete
  2. To be very frankly, YES, currently there's no organisation or institution behind Candle. It's very much my personal effort.
    But the biggest institution Internet, and the biggest organization OSS is behind me. :-)
    Yes, I agree that moving forward, Candle needs some kind of endorsement by some standards body. IEFT RFC is one option.

    ReplyDelete
  3. How would Candle fit as an alternative for the current syntactic XML support in Scala? Could you show what it would look like?

    ReplyDelete
  4. Below is a simple XML sample that I take from some Scala tutorial:
    def makeXML(id: String) = <span id={id}><strong>Hello,</strong> World!</span>

    When converted into Candle Markup, it would look like:
    def makeXML(id: String) = <span id={id}><strong>"Hello,"</strong> "World!" </span>

    Generally, for Scale to support Candle Markup, it has to be enhanced to support parsing Candle's syntax. It'll also need to introduce some option for user to specify whether the embedded markup is in XML syntax or in Candle syntax.

    ReplyDelete
  5. Projects like (http://anti-xml.org/) shows how scala.xml package can be replaced. To support Candle Markup in Scala. A similar package needs to be developed.

    ReplyDelete
  6. Henry, the Cancle Markup that you present for Scala disappoints me. It is basically the same as the old XML, including the repetition of the tag names at the closing tags.

    Let's make the Hello World XML sample slightly more complicated: the "ll" should be italic. The Scala version would then be

    <span id={id}><strong>He<italic>ll</italic>o,</strong> World!</span>

    I would hope a Lua version would be something like
    <span { id = {id} strong {"Hello" italic {"ll"}"o, "} "World!" }>

    What do you think?

    ReplyDelete
  7. You example in Candle element notation:
    <span id={id}><strong>"He"<italic>"ll"</italic>"o,"</strong>" World!"</span>
    Yes, it is very close to XML except that string are quoted.

    In Candle object notation:
    span {id={id} strong{"He" italic{"ll"} "o,"} " World!"}
    Very close to your Lua version.

    The element notation can be easily embedded in Scala. The object notation probably requires more change to Scala language.

    Another hybrid way might be as you used in your Lua example. Keep the outer most node in element notation, it serves as the delimiter to separate the markup from normal Scala script. Inside the element, object notation can be used for its terseness.

    ReplyDelete
  8. Excuse me; I wrote Lua when I meant Candle. And I made a mistake in the "Hello" part.
    Anyway, I really like the Candle Object Notation; I would prefer it much above the embedded XML in Scala.
    Maybe you should keep the outer "<" and ">" brackets so that the Scala compiler can easily parse it.

    ReplyDelete
  9. I'm glad we have consensus now. :-)

    ReplyDelete