Wednesday, August 13, 2008

Beautiful concurrency

I had another interesting read yesterday:

Beautiful concurrency by Simon Peyton Jones of Microsoft Research

Modern computers have more than one CPU. In order to make good use of multiple CPUs, parallel programs must be written. A problem arises when a resource must not be used by multiple threads at the same time. This is conventionally solved by using locking (e.g. using synchronized in Java, or lock in C#).

The paper describes Software Transactional Memory, a new approach to programming shared-memory parallel processors in a more modular way.

posted @ 11:34 AM | Feedback (0)

Relax NG (relaxing)

Why?

The following quote from the paper XML Fever by Erik Wilde and Robert J .Glushko gives a good explanation:

XSDL's complexity allows a given logical model to be encoded in a plethora of ways (this fever will mutate into an even more serious threat with the upcoming XSDL 1.1, which adds new features that overlap with existing features). A cure for schema option paralysis is to use alternative schema languages with a better separation of concerns (such as limiting itself to grammars and leaving data types and path-based constraints to other languages), most notably RELAX NG.

How?

When writing a schema I prefer the compact syntax, emacs rnc-mode being a helpful aid.

Another very useful feature is the instant validation provided by emacs nxml-mode when opening an XML file and while editing it. All you need to do is feed it the rnc schema file.

Other validation tools I use:
For Java: Jing or MSV
For .Net : Tenuto

Beware of a bug in Jing when using javax.xml.validation as in the code example below:

import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import java.io.File;

public class RELAXNGValidation {
    public static void main(String[] args) throws Exception {

        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
        Schema schema = sf.newSchema(new File(args[0]));
        schema.newValidator().validate(new StreamSource(args[1]));
    }
}

A useful XML schema conversion tool is Trang.

Update: 29 Oktober 2008

James Clark is working on Jing again. Jing and Trang are now hosted on Google Code

posted @ 11:18 AM | Feedback (0)