Yesterday, during yet another interview, we didn't deliver quite the finest explanation of what an XML Namespace is. Today, we're using them to parse a Stack Overflow feed so clearly we understand them, however, if part of the question's purpose is to assess our ability to express this simple idea simply then shitehawks! #fail
Take this feed, for example, which is the RSS for a useful post on Volatile vs. Interlocked vs. lock. In order to to be able to use XPath with XDocument to retrieve the question we rely on XmlNamespaceManager.
[code:c#]
var xDoc = XDocument.Load("http://stackoverflow.com/feeds/question/154551");
var xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
xmlNamespaceManager.AddNamespace("atom", "http://www.w3.org/2005/Atom");
var postedQuestion
= xDoc.XPathSelectElement("/atom:feed/atom:entry/atom:summary", xmlNamespaceManager);
[/code]
This is another example of Stack Overflow brilliance. The feeds are in chronological order so that we can guarantee that the first item (or entry) is the original post. Following the Volatile trail leads to a Joe Duffy post on Volatile Reads and Writes, and Timeliness. For example, he writes the C# documentation for volatile is highly misleading with reference to the following MSDN documentation:
The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.
Unfortunately, I can't find this specific RSS item within the Technology feed and the same is true for the RSS feed for this blog. Although it's possible to score a reference to the item if it appears within the list of entries as they each have a unique ID, should the category contain too many entries then the older posts don't show up. Soon I'll show why this might matter but I digress.
The quoted paragraph above came as some surprise and a few hours reading suggests that:
- This stuff is hard!
- It would take *years* at the exclusion of a whole lotta stuff to have a legitimate claim to deep understanding of the intricacies of threading in .NET
- A solid handle on this C# Threading series of posts might just be enough (for now).
The real trick, however, might be recall during interview. There's definitely a theme here.