I've seen a couple of negative blog posts recently about WebMatrix and LightSwitch. See for example this post
Microsoft's WebMatrix - Why You Aren't Going To Use It
I don't think the criticism is entirely fair. It's all about diversity, providing an entry point and targetting as many people as possible.
The blog post above contrasts two examples, one in PHP and one in WebMatrix/C#.
First the PHP version
$xml = simplexml_load_file('http://picasaweb.google.com/data/feed/base/user/114741487348646937381/albumid/5494564502704076449?kind=photo'); foreach ($xml->entry as $entry) { $media = $entry->children('http://search.yahoo.com/mrss/');
$thumbnail = $media->group->thumbnail[1]; echo '<img src="' . $thumbnail->attributes()->{'url'} . '">'; }
Then the C# version
@using System.Xml @{ var xml = new XmlDocument(); xml.Load("http://picasaweb.google.com/data/feed/base/user/114741487348646937381/albumid/5494564502704076449?kind=photo"); var nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("media",
"http://search.yahoo.com/mrss/"); foreach(XmlNode node in xml.SelectNodes("//media:thumbnail", nsmgr)) { Response.Write(string.Format("<img src="\"{0}\"">", node.Attributes["url"].Value)); } }
That's 7 lines of PHP vs 11 lines of C#*. The first thing to consider is the missing <? and ?> delimiters in the PHP example. That adds another two lines to the PHP example, so now we're up to 11 vs 9 lines of code.
Then there's the use of the old XML API in the C# version. That means namespace use looks horrible. We can simplify this with XLinq.
@using System.Xml.Linq @{ var xml = XDocument.Load("http://picasaweb.google.com/data/feed/base/user/114741487348646937381/albumid/5494564502704076449?kind=photo"); foreach(var node in xml.Descendants("{http://search.yahoo.com/mrss/}thumbnail"))
{ Response.Write(string.Format("<img src='{0}'>", node.Attribute("url").Value)); } }
So now the code is very simple. We've gone lower than PHP in line count (9 vs 8) and that's including a using directive.
It sounds to me like it's just as much about setting good examples.
What do you think? Is the criticism fair?
* There's some code formatting issue here so the code wraps unnecessarily, affecting line count.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.