I have moved my blog to Wordpress at theunixgeek.wordpress.com. I will still be checking back periodically on this one as well, though. 19 April 2009


Merging Mkdir and Cd | 280 Slides Interview | I Switched to KDE 4

clickable portals

Tuesday, August 19, 2008

Why XAML is Powerful

XAML, Microsoft's eXtensible Application Markup Language, was released with the .NET 3.0 framework and works with the new technologies available in the once-called WinFx release of the framework, such as WPF (Windows Presentation Foundation), WF (Workflow Foundation), Windows CardSpace, and WCF (Windows Communication Foundation). Currently, I'm learning WPF, where XAML is used for building user interfaces.

Being a markup language, XAML is inherently powerful (object-oriented pun not intended) for the pure reason that you can write your interface in XAML and use it in a variety of projects in the most various languages (in Microsoft's case, C++, C#, and Visual Basic - I'm not sure if J++ and J# are still around). This way, a project doesn't need to have its interface written in one non-compatible language, but rather in XAML itself, allowing the code to be shared across various languages.

It would be especially useful if Linux distributions and APIs adopted this new markup-based way of marking up interfaces. Imagine if programmer is experienced in Python and at an intermediate levl in C and wants to write a GTK+ application, but wants some parts of the interface written not only in C but also in Python. The code would get confusing having one part of the interface in C and the other in Python (I'm not sure if this example is plausible, it's just an example) when the interface could be entirely written in a markup language, so that the two languages could easily access the markup file.

One could say XIB (on OS X Leopard) is copying off of XAML (on Windows XP SP2 and Vista) : they're both markup files used for interface implementation, but Xcode 3.0 development doesn't seem to have started until late 2006 or early 2007, while Avalon (the codename for WPF) was in development since before 2005. Recently, I've been finding Apple to be copying off Microsoft: OS X iPhone - Windows Mobile, XIB - XAML, icon size sliders in the Snow Leopard Finder (at least in the alpha version) - same feature was implemented in Vista's Finder. On the other hand, Application Services was copied by Microsoft and re-implemented as WCF. They both copy from each other, let's just put it at that ;-)


Paul A Houle said...

Something else cool about XAML: it's not tied to UI development!

XAML is a general framework for writing an XML file that initializes and configures a tree of objects. It's used in Windows Workflow Foundation to specify asynchronous workflows. It could be used in frameworks that build programs by composition, like the Java Spring framework.

The cross-language aspect of XAML might be hard to carry into the open-source world because XAML's cross-language ability is closely tied to how the .net framework works. It's possible to write programs in many languages, such as C#, VB and IronPython and compile them to the .net runtime. If these classes are 'partial' classes, part of them can be defined in a XAML file while the other part is defined in a .cs file.

Overall, XAML-WPF is an elegant way to implement the "Visual Basic" style of GUI builder. That whole approach depends a lot on having consistent appearance of controls, font metrics and stuff, and doesn't work so well in cross-platform environments where a few pixels here and a few pixels there can make your interfaces unusable.

Sam Griffith Jr. said...

XIB is not a coping of XAML. XIB is a XML equivalent of the binary serialization that Interface Builder uses to create it's NIB files. XIB is XML version of NIB. The NIB is just the interface saved. By that I mean in IB you are not just drawing a spec, but actually instantiating the real UI elements and can even run the instance. No code gen, no nothing. What you pull out is the real deal. The NIB/XIB is just that object graph saved.

XAML on the other hand is more of a UI spec language that is in line with it's use in a Builder pattern of creating the UI. They are different approaches to the same goal. XAML converts the spec into instantiating and connecting the UI components on the build of the spec. The NIB on the other hand is not building the UI, but de-serializing an already existing one. No spec parsing or build is being done on the load.

The binary NIB file is what interface builder has created since 1989 on NeXTStep on through today on OS X.

Creating a XML serialization of the Cocoa UI elements has allowed them to easily be able to check in the XIB into source control systems that do not deal with binary files easily and more importantly do diffs between different versions.

When the application is compilied the XIB is converted into a NIB aka the binary serialized version of the UI elements, for deploying and running the app.

Murat Yener said...

Actually XAML is copying MXML. Microsoft strategy has always been cloning the succesfull product. Like once they clone Java with .net/c#, all they do is trying to clone Flex with silverlight. How can XAML be powerful? even for a button component we waited for version2... and even xaml is powerful, it is so weak as long as it muct be used along javascript. I can't understand microsoft's idea of building a cross-browser or cross-OS platform with the language which is known to be most troublesome for that.

Rob Relyea said...

As one of the people behind XAML at Microsoft, I'm excited to see this article and discussion. We've published [MS-XAML], the specification of XAML Object Mapping so that it can be used for other purposes than WPF, Silverlight, XPS, and Windows Workflow.

Did XAML copy MXML
XAML is used by WPF and Silverlight. Silverlight v1 didn't have a button or full .NET support, Silverlight v2 does.

Saying that XAML is copying MXML is not true. We publicly announced XAML and WPF to the world in October 2003, and I believe we had briefed Adobe before that.

MXML, if I recall, didn't see the light of day until 2004.

Regardless, I believe the whole industry sees the value in moving to declarative formats for UI and many other things.

I have't spent much time understanding NIB/XIB. XAML, our XML based language, and BAML, the binary compacted form of XAML, sound similar. XML is used as "source code" and there is a more efficient runtime format. Much like code gets compiled to IL or machine specific code.

XAML Futures
We've got a bunch of great things in store around XAML, we'll announce some new things at the Professional Developers Conference in October 2008.

http://robrelyea.com/xaml has several links to information about XAML, including links to blog posts by me and others on the XAML team at Microsoft.

Thanks, Rob Relyea
Architect, XAML and WPF Teams

Anonymous said...
This comment has been removed by a blog administrator.
Will said...

Xaml is even more powerful than you think. Xaml is actually serialized object trees. So, with some reservations (I've never tested circular references, and collections require a little care) you can serialize anything to XAML. Its a crapton easier than xml serialization for objects, and more reliable. Workflow Foundation uses xaml to serialize workflow objects as well.

Will said...

Yeah, forgot. Markup Extensions can be created for your particular graph to handle circular references. Sweet.

Andrew said...

Glad someone else pointed out the NIB/XIB ancestry dating back before XAML. Although technically one could say XAML was possibly released before XIB, it is much easier to say that all platforms had been serializing/storing UI elements in a binary format for a long time. I think it was the much wider adoption of source code versioning software in the recent years that has pushed for a text-based format to be used instead of binary (as someone else stated).

As far as icon size sliding in OSX, I have it on Leopard right now and I'm quite sure it's been around since Tiger or before...

And as far as Windows Mobile coming out before iPhone, that is true, but there were plenty of cell phones out before Windows Mobile, just like there were other MP3 players out before the iPod. To say that the iPhone is a "copy" of Windows Mobile seems like an insult to the iPhone.

Pavel said...

The Java Enterprise platform leverages the robustness of the Java programming language that allows developers to write the code only once and execute the application on any platform. Presently more than two-thirds of web development managers use the Java Enterprise platform to develop and deploy their applications. The Java Enterprise platform provides a framework for developing and deploying web services on the Java platform. The Java API for XML enables Java developers to develop interoperable and portable web services. java software company | software development company | java web development | blackberry application development | iphone application development | android application development | java outsourcing | it outsourcing services | http://www.tenaxtechnologies.com