Given another 4 years of experience since I wrote “Our 7 Goals for XAML”, here is my updated list of XAML Benefits:
XAML Describes Data in a Concise, but Human and Machine Comprehensible, Way
Declarative formats provide the best and most concise way to represent many types of data. Comprehension of a declarative format is better than a general purpose programming language.
| <BookList> <Book Author="J. K. Rowling" Title="Harry Potter and the Philosopher’s Stone" Year="1997" /> <Book Author="L. Frank Baum" Title="Wizard of Oz" Year="1900" /> </BookList> | BookList bl = new BookList(); Book b1 = new Book(); b1.Author = "J. K. Rowling"; b1.Title = “Harry Potter and the Philosopher’s Stone”; b1.Year = 1997; bl.Add(b1); Book b2 = new Book(); b2.Author = "L. Frank Baum"; b2.Title = “Wizard of Oz”; b2.Year = 1900; bl.Add(b2); |
XAML is Useful for Many Types of Data
Microsoft already supports XAML Vocabularies to describe UI ([MS-WPFXV], [MS-SLXV]), Workflow (WF) and Electronic Paper (XPS). Many other vocabularies are possible.
XAML 2009’s new Name Referencing enables object graph definition, which opens up the number of types of data that can be described. WF 4 leverages this for modeling Flow Charts. WCF 4 Services can be modeled in XAML more naturally as well.
XAML uses Typed Object Models for Better Programming and Validation
Systems that have a strongly-typed OM (object model) enable:
- Manipulation of objects after initialization with strong-typing, which enables compile time checking of code.
- Markup Validation using the OM as the Type’s schema, as opposed to having to build an additional schema.
class Book { string Author { get; set; } string Title { get; set; } int Year { get; set; } } | Works: b1.Year = 2000; Compile Time Error: b1.Year = "6/1999"; | Validation Error: <Book Year="6/1999" /> |
XAML is Extensible and Version Tolerant
Systems that are extensible through class inheritance can be modeled easily in XAML. Since BookList can hold Books, and since one can derive a PaperbackBook from Book, I can use PaperbackBook wherever a Book is allowed, in code or markup.
class PaperbackBook : Book { } | <BookList> <Book … /> <my:PaperbackBook … /> </BookList> |
XAML's default is that every tag and attribute must be known, while HTML defaults to ignoring any mistyped element name, attribute name or attribute value. While there is a place for this ignoring to allow for forward compatibility, XAML uses Markup Compatibility and Extensibility (ECMA-376 Part5) for backward/forward compatibility.
XAML is Toolable
Systems described in XAML will be creatable and consumable by a wide set of tools. This goal drives our decisions throughout XAML, from our XML representation to schema and beyond.
XAML is XML
In .NET 3 and Silverlight, all valid XAML files must be valid XML files. The opposite isn't always true…all XML files are not XAML files. This bet on XML is important because it enables an ecosystem of tools, systems, APIs and developers familiar with XML to get a strong start on understanding XAML.
.NET 4 is broadening what it means to be a XAML document. We’re introducing a XamlReader and XamlWriter abstraction in System.Xaml.dll which enables anybody to provide or store XAML based data. We’ll provide readers and writers for XML, BAML, and object graphs, but many other storage or in memory representations are possible. We believe that our XML representation shipped with .NET 3.0 in 2006 will continue to be the most common representation of XAML documents, but time will tell.
XAML Enables Event Driven Programming Models
XAML enables description of object graphs which include the setting of properties and the wiring of events. This enables systems which need an event driven programming model.
XAML is Compiled or Interpreted
XAML is sometimes treated as source code, sometimes as runtime instructions. Different frameworks will make different choices around this: WPF chooses to compile XAML into a binary representation which gets embedded inside an assembly; Silverlight chooses to validate the XAML at compile time, but it embeds the original XAML file into a .XAP file. Either WPF or Silverlight can also interpret at runtime a XAML file that is not downloaded with the “application”.