November 2004 Archives

The Cafes

| No Comments | No TrackBacks |

Elliotte Rusty Harold has started a new site called (not surprisingly) "The Cafes" - for articles "longer than a typical Cafe con Leche news item, but much shorter than a full book". Here is the RSS feed. Subscribed.

Why is XML case-sensitive?

| 9 Comments | No TrackBacks |

Sriram Krishnan asks strange question:

I see someone flaming someone else for not being XHTML compliant. Tim Bray - if you're reading this, I want to know something. Why is XML case-sensitive? No human-being ever thinks in case-sensitive terms. A is a. End of story. So now, I have a situation where writing <html> </HTML> wouldn't be XHTML compliant. And what do I get out of XHTML apart from geek-bragging rights and this strange idea of 'standards-compliance'? Does it give me more freedom? Does it help my viewers? My customers?
Well, this guy is definitely heavily sloppy-HTML-contaminated. What? <html> </HTML> isn't XHTML complaint? Thanks GOD! Anyway, Tim Bray does answer his question:
XML markup is case-sensitive because the cost of monocasing in Unicode is horrible, horrible, horrible. Go look at the source code in your local java or .Net library.

Also, not only is it expensive, it's just weird. The upper-case of e' is different in France and Quebec, and the lower-case of 'I' is different here and in Turkey.

XML was monocase until quite late in its design, when we ran across this ugliness. I had a Java-language processor called Lark - the world's first - and when XML went case-sensitive, I got a factor of three performance improvement, it was all being spent in toLowerCase(). -Tim
Nice.

Beta MSN search runs XHTML

| No Comments | No TrackBacks |

Scoble says "MSN is XHTML". Well, not really msn.com, but MSN search (beta version) - beta.search.msn.com. Good news anyway.

Here is what I learnt from Jackie Goldstein's talk on .NET Worst Practices at the .Net Deep Dive conference in Tel-Aviv last Thursday. There is a subtle, but hugely important difference between how .NET and Java re-throw a caught exception and I missed that somehow when been learning .NET. Not that I didn't know what "throw;" does in C#, I was mistaken about what "throw ex;" does!

In Java, when you do "throw ex;", ex is being re-thrown as if it wasn't caught at all - no informantion about re-throwing is ever recorded and original stack trace info is preserved. If you do want to start exception's stack trace from the re-throwing point - oh, that's completely different story, you need to refill exception's stack trace using fillInStackTrace() method.

In .Net however, when you do "throw ex;", ex is being re-thrown, but the original stack trace info gets overriden. The point where exception is re-thrown is now becoming the exception's origin. Here is what I mean. If you do follow your Java habits and write

using System;
public class MyApp
{    
    public static void F() 
    {
        throw new NotImplementedException("Too lazy to implement!");
    }

    public static void Main() 
    {
        try 
        {
            F();
        } 
        catch (Exception e) 
        {
            Console.WriteLine("Exception {0} has occured!", e.GetType());
            throw e; //Line 18
        }        
    }
}
you'll get:
Exception System.NotImplementedException has occured!

Unhandled Exception: System.NotImplementedException: Too lazy to implement!
   at MyApp.Main() in d:\projects\test\class2.cs:line 18
See, you've lost the original exceptions's stack trace and now you gonna have really hard time to figure out what was wrong actually, where the exception was thrown at the first place.

So in .NET you have to use "throw" keyword ("Throw" in VB.NET) with no argument to perform a pure re-throwing of an exception - change the line 18 to just "throw;" and the result will be

Exception System.NotImplementedException has occured!

Unhandled Exception: System.NotImplementedException: Too lazy to implement!
   at MyApp.F() in d:\projects\test\class2.cs:line 6
   at MyApp.Main() in d:\projects\test\class2.cs:line 18
Now you can see the full exception stack trace.

Basically MSIL (CIL) has two instructions - "throw" and "rethrow" and guess what - C#'s "throw ex;" gets compiled into MSIL's "throw" and C#'s "throw;" - into MSIL "rethrow"! Basically I can see the reason why "throw ex" overrides the stack trace, that's quite intuitive if you think about it for a moment. But "throw" syntax for "rethrow" instruction is not really intuitive. It smells stack based MSIL, which is obviously under the cover, but actually should be kept there. I guess they wanted to keep number of C# keywords small, that's the reason. So you just better know this stuff - use "throw;" to re-throw an exception in .NET.

Head First books

| 1 Comment | 3 TrackBacks |

Hey, that's cool stuff - check it out. Apparently, O'Reilly have found new way to sell more books. It's a sort of modern version of the "X for complete idiots" series - actually they call it "Head First". The main idea as far as I understand is to set out material in a form of a story abundantly filled with fun weird (while in fact attention-grabbing) images (which are more memorable than words). Here is an official description:

If you've read a Head First book, you know what to expect--a visually-rich format designed for the way your brain works. Using the latest research in neurobiology, cognitive science, and learning theory, Head First Design Patterns will load patterns into your brain in a way that sticks. In a way that lets you put them to work immediately. In a way that makes you better at solving software design problems, and better at speaking the language of patterns with others on your team.
Hmmm, neurobiology... loads directly into my brain... I'm not sure if I like it actually. We need some brain-access security here!

Anyway that looks pretty interesting. There are only four books in "Head First" series published already - on servlets/JSP, Java, EJB and Design Patterns. All Java-oriented, but that last one:



is an universal of course, so I just ordered it. Check out sample chapters, especially this one - they are awesome.

PS. Oh, and I think Rory should sue O'Reilly for stealing his idea of presenting tech info along with weird images mixed with hand-written text.

XML encoding pedantry

| No Comments | No TrackBacks |

BTW, as nicely pointed out by Michael Kay, XML document with no XML declaration, in encoding other than UTF-8 or UTF-16 is not necessarily malformed! In fact XML spec allows encoding information to be provided externally (e.g. via Content-type HTTP header).

"Mathematical Notation: Past and Future" by Stephen Wolfram - amazingly interesting article.

[Via Sean Gerety]

Another elections disappointed

| 17 Comments | No TrackBacks |

Well, it's not about USA elections. It's about elections in Ukraine, the country where I was born and grew up. The president elections were just terrible. Calling them fraudulent is saying nothing, they ware super-fraudulent. Violence, intimidation, abuse of state resources in favor of the prime minister, frauds such as "in some areas 5 percent of voters had been added to the lists on voting day, many of them with certificates allowing them to vote away from their place of residence.". My friends and relatives in Ukraine confirm all that, basically from my experience there is no doubt it's all true. Ukraine is still far from democracy. A prime minister can spend lots of state's budget and organize a fraud campaign just to be elected as a president. And what's funny, everybody knows it. That's a normal practice in ex-USSR states. And that's terrible. Russian's observers are happy and called the elections open and honest. Russian's president sent his congratulations to the ukraininan prime minister even before the official election results were published! All western observers called the elections a farce and all western governments refuse to recognize the results. What a mess!

Oh, well, I left that country 5 years ago... No regrets.

Calling document("") in .NET

| No Comments | No TrackBacks |

There was recently an interesting thread in the microsoft.public.dotnet.xml newsgroup on document("") function call in .NET. A guy was porting some app from using MSXML to .NET. Something didn't work... You know these common bitter (and usually completely lame) complaints:

It is strange, this all works just fine using MSXML4 objects instead of XML.NET I guess between the implementation of MSXML4 and XML.NET they forgot the purpose of the special case document('').
...
W3C spec or not, it is too bad that XML.NET is intrinsically tied to the file system. My program has access neither to write nor read from the file system. I guess I will use MSXML4.
So what's wrong with document("") in .NET comparatively to MSXML?

New XSLT-related blog - xsltblog.com

| No Comments | No TrackBacks |

M. David Peterson, coordinator of the x2x2x.org community open-source project (known by the Saxon.NET, AspectXML, and xameleon projects) started a blog at xsltblog.com. The blog's description is "An ongoing weblog of current topics from the XSLT development community & other XML/XSLT related news items. Hosted, maintained, & edited by M. David Peterson.". Subscribed.

Minor EXSLT.NET update

| No Comments | 1 TrackBack |

Just for the record: I updated EXSLT.NET to support for omit-xml-declaration attribute on the exsl:document element. If somebody desperately needs it, it's in the source repository already.

TopXML is reblogging

| 2 Comments | No TrackBacks |

TopXML launched XML News Reblogger service. It's basically XML blogs and news aggregator, similar to the Planet XMLhack. They aggregate selected XML-related news feeds and blogs (127 currently, including mine :) twice a day and provide a way to read all that jazz on their web site. They don't provide aggregated RSS feed currently, but as Sonu Kapoor (the guy who wrote the Reblogger) informed me, that's definitely just a matter of time.

Norman Walsh on XML 2.0

| No Comments | No TrackBacks |

Amazing new essay by Norman Walsh on XML 2.0. Worth reading and contemplating. The crux is "simplification". XML is too complex, who knew it six years ago :)

Fifth anniversary of the XSLT and XPath

| No Comments | No TrackBacks |

Here are some 5-years old news:

http://www.w3.org/ -- 16 November 1999 -- The World Wide Web Consortium (W3C) today releases two specifications, XSL Transformations (XSLT) and XML Path Language (XPath), as W3C Recommendations. These new specifications represent cross-industry and expert community agreement on technologies that will enable the transformation and styled presentation of XML documents. A W3C Recommendation indicates that a specification is stable, contributes to Web interoperability, and has been reviewed by the W3C membership, who favor its adoption by the industry.

"Anyone using XML can now take advantage of XSLT, a powerful new tool for manipulating, converting or styling documents," declared Tim Berners-Lee, W3C Director. "XPath adds a simple way of referring to parts of an XML document. Together, they strike a fine balance between simplicity of use and underlying power."

Happy birthday to XSLT and XPath and congratulations to James Clark and Steve DeRose, editors of these the best so far XML applications.

Breaking news from Altova GmbH (maker of famous XML Spy IDE):

Altova has compiled a collection of free tools and technical resources to help develop solutions for today's business challenges.
That includes: Altova XSLT 1.0 and 2.0 Engines, Altova XQuery Engine, XMLSpy® 2005 Home Edition, Authentic® 2005. All Windows-only apparently.

XSLT and XQuery ones are the new and the most interesting. Altova XSLT 1.0 engine is well-known XSLT engine used when debugging XSLT within XML Spy, now they just release it as a free (but not open-source of course) standalone utility (Windows 2000/XP/2003 command line executable), "suitable for use in both client- and server-side application development". Altova XSLT 2.0 engine is a similar utility, which claims to implement November 2003 XSLT 2.0 working draft. It's schema-unaware processor and doesn't support user defined types and validation. Some functions and elements aren't supported either (yet?).

Altova XQuery Engine is also available as free command line Windows 2000/XP/2003 exe, which implements July 2004 XQuery 1.0 working draft. The same here - no support for schema importing, validation and user-defined types. No support for static type checking, external functions, character normalization either. XQuery library modules are supported though. More info about limitations here.

The tools are available "for you to use both for your own purposes and to integrate into your solutions without paying any royalties or license fees." The license: Altova XSLT/XQuery Engine developer license agreement.

Sounds awesome. I just downloaded the tools, but didn't give them a whirl yet. I wonder why there is no support for schema, actually XML Spy has a very decent schema processor for years now. Hmmm, very cool tools anyway.

Imprinting on "randomness"

| 2 Comments | 1 TrackBack |

Well, that's just a simple level 100 quiz aiming to imprint "standard random number generators are not really random" program to those who still lack it. What will produce the following C# snippet?

System.Random rnd = new System.Random(12345);
System.Random rnd2 = new System.Random(12345);
for (int i=0; i<1000; i++)            
if (rnd.Next() != rnd2.Next())
    Console.WriteLine("Truly random!");