<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rock, Paper, Software &#187; Nemerle</title>
	<atom:link href="http://software.tulentsev.com/category/nemerle/feed/" rel="self" type="application/rss+xml" />
	<link>http://software.tulentsev.com</link>
	<description>Random thoughts about programming</description>
	<lastBuildDate>Fri, 03 Feb 2012 13:47:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Formatting with named parameters</title>
		<link>http://software.tulentsev.com/2009/01/formatting-with-named-parameters/</link>
		<comments>http://software.tulentsev.com/2009/01/formatting-with-named-parameters/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 13:45:17 +0000</pubDate>
		<dc:creator>Sergei Tulentsev</dc:creator>
				<category><![CDATA[Nemerle]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[named formatting]]></category>

		<guid isPermaLink="false">http://software.tulentsev.com/?p=76</guid>
		<description><![CDATA[Problems with formatting The &#8220;official&#8221; way to format strings in .NET BCL is to use String.Format method (and wrappers for it, like Console.Write). This is not very reliable method. You can forget to include parameter into the format string or confuse one parameter with another. And your IDE does not offer any help here. We [...]]]></description>
			<content:encoded><![CDATA[<h3>Problems with formatting</h3>
<p>The &#8220;official&#8221; way to format strings in .NET BCL is to use <a href="http://msdn.microsoft.com/en-us/library/system.string.format.aspx" target="_blank">String.Format</a> method (and wrappers for it, like <a href="http://msdn.microsoft.com/en-us/library/system.string.format.aspx" target="_blank">Console.Write</a>).</p>
<p><a href="http://software.tulentsev.com/wp-content/uploads/2009/01/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://software.tulentsev.com/wp-content/uploads/2009/01/image-thumb.png" border="0" alt="image" width="584" height="129" /></a></p>
<p>This is not very reliable method. You can forget to include parameter into the format string or confuse one parameter with another. And your IDE does not offer any help here.<span id="more-76"></span></p>
<h3>We want better way!</h3>
<p>People feel that this is not right and try to invent some more convenient methods. One of which is formatting with named parameters (using names instead of ordinals). Yesterday I read <a href="http://haacked.com/archive/2009/01/04/fun-with-named-formats-string-parsing-and-edge-cases.aspx" target="_blank">this blog post</a>. There are several implementations of formatting with named parameters and author makes more reliable and efficient implementation just for fun. But you know what? It still doesn&#8217;t seem right.</p>
<p><a href="http://software.tulentsev.com/wp-content/uploads/2009/01/image1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://software.tulentsev.com/wp-content/uploads/2009/01/image-thumb1.png" border="0" alt="image" width="593" height="97" /></a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/bb397696.aspx" target="_blank">Anonymous type</a> here is supposed to protect us from renaming issue, but it clutters the code. And again, we do not get any help from IDE (warnings about non-existing elements, highlighting, etc).</p>
<h3>But how can it be done even better?</h3>
<p>Let&#8217;s look at <a href="http://en.wikipedia.org/wiki/Nemerle" target="_blank">Nemerle</a>. It borrows &#8220;spliced string&#8221; syntax from languages like PHP (&#8220;hello, $username&#8221;). But it has several advantages over PHP and Perl. All expressions are resolved and typed at compile-time. And if you use <a href="http://nemerle.org/Download" target="_blank">VS package</a>, then you&#8217;ll get development-time checks (on-the-fly) and highlighting.</p>
<p>One picture is worth a thousand words. So look at these code samples</p>
<p><a href="http://software.tulentsev.com/wp-content/uploads/2009/01/image2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://software.tulentsev.com/wp-content/uploads/2009/01/image-thumb2.png" border="0" alt="image" width="556" height="51" /></a></p>
<p><a href="http://software.tulentsev.com/wp-content/uploads/2009/01/image3.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://software.tulentsev.com/wp-content/uploads/2009/01/image-thumb3.png" border="0" alt="image" width="547" height="107" /></a></p>
<p>Feel the difference! What can possibly go wrong here (except for <a href="http://msdn.microsoft.com/en-us/library/system.nullreferenceexception.aspx" target="_blank">NullReferenceException</a>, but <a href="http://msdn.microsoft.com/en-us/library/system.string.format.aspx" target="_blank">string.Format</a> is also vulnerable to it). Also, this code is very efficient. Essentially it is transformed to a series of <a href="http://msdn.microsoft.com/en-us/library/system.string.concat.aspx" target="_blank">string.Concat</a> or <a href="http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.append.aspx" target="_blank">StringBuilder.Append</a> calls.</p>
<p>P.S.: One more thousand-words-picture.</p>
<p><a href="http://software.tulentsev.com/wp-content/uploads/2009/01/image4.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://software.tulentsev.com/wp-content/uploads/2009/01/image-thumb4.png" border="0" alt="image" width="507" height="95" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://software.tulentsev.com/2009/01/formatting-with-named-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Special comments</title>
		<link>http://software.tulentsev.com/2007/04/special-comments/</link>
		<comments>http://software.tulentsev.com/2007/04/special-comments/#comments</comments>
		<pubDate>Sat, 07 Apr 2007 19:44:39 +0000</pubDate>
		<dc:creator>Sergei Tulentsev</dc:creator>
				<category><![CDATA[Nemerle]]></category>
		<category><![CDATA[MS Visual Studio]]></category>

		<guid isPermaLink="false">http://software.tulentsev.com/2008/11/special-comments/</guid>
		<description><![CDATA[Yesterday night I had a dream about how it would be cool to highlight special kinds of comments, like TODOs and BUGs. But when I came to office, it turned out that JetBrains stole this idea a few days before. :-) Their solution is extensible and customizable, but all those customizations don&#8217;t work at the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday night I had a dream about how it would be cool to highlight special kinds of comments, like TODOs and BUGs.<br />
But when I came to office, it turned out that JetBrains stole this idea a few days before. :-)<br />
Their solution is extensible and customizable, but all those customizations don&#8217;t work at the moment.<br />
Mine, at the moment, has three hardcoded colors and regexes, and it IS working properly. :-)<br />
Check it out:<br />
<a href="http://tulentsev.com/blog/images/special_comments.png" target="_blank"><img src="http://tulentsev.com/blog/images/special_comments.png" alt="Screenshot of special comments highlighting" width="100%" /></a></p>
<p>This is done as a part of <a href="http://rsdn.ru/article/nemerle/Nemerle.VsIntegration-en.xml">Nemerle-&gt;VS2005 integration project</a>. <a href="http://rsdn.ru/article/nemerle/Nemerle.VsIntegration-ru.xml">Here</a> is the link for russian readers.</p>
]]></content:encoded>
			<wfw:commentRss>http://software.tulentsev.com/2007/04/special-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

