<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx</link><description>I haven't forgotten that I promised to describe one more place where we insert an explicit conversion automatically. But before that, a quick digression. 
 Reader Phil Haack has written some good tips for writing clear code and quotes an old post of</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#10273643</link><pubDate>Mon, 27 Feb 2012 22:45:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10273643</guid><dc:creator>Nick</dc:creator><description>&lt;p&gt;#if DEBUG&lt;/p&gt;
&lt;p&gt;bool b =&lt;/p&gt;
&lt;p&gt;#endif&lt;/p&gt;
&lt;p&gt;DoSomething(); // Apparently, this works in C# 4.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10273643" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#10137443</link><pubDate>Sun, 06 Mar 2011 21:46:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10137443</guid><dc:creator>GregM</dc:creator><description>&lt;p&gt;Adam, that depends on your environment. &amp;nbsp;In my environment, for example, warnings do prevent compilation, as we use the warnings as errors option.&lt;/p&gt;
&lt;p&gt;However, I do have the VC++ warning &amp;quot;variable initialized but never used&amp;quot; turned on for the reasons you describe.&lt;/p&gt;
&lt;p&gt;So in my VC++ environment, this is an error&lt;/p&gt;
&lt;p&gt;bool b = DoSomething();&lt;/p&gt;
&lt;p&gt;but this is not&lt;/p&gt;
&lt;p&gt;bool b;&lt;/p&gt;
&lt;p&gt;b = DoSomething();&lt;/p&gt;
&lt;p&gt;So VC++ does allow write-only variables, but warns about initialize-only variables.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10137443" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#10136616</link><pubDate>Thu, 03 Mar 2011 21:00:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10136616</guid><dc:creator>Adam M.</dc:creator><description>&lt;p&gt;I&amp;#39;m not particularly convinced. A warning doesn&amp;#39;t prevent compilation, so if a dummy variable is added to aid debugging, it seems perfectly reasonable to issue a warning about it to remind the programmer to remove the unnecessary variable. And if they really want to leave debug code in the source forever, they can add an exclusion for the warning easily enough. I&amp;#39;d much rather have the compiler tell me that I forgot to do something with the variable I assigned than keep quiet, assuming that 1) I&amp;#39;m just adding it for debugging purposes, and 2) I intend to not remove it.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10136616" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#2261898</link><pubDate>Tue, 24 Apr 2007 19:45:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2261898</guid><dc:creator>Eric Lippert</dc:creator><description>&lt;p&gt;Since that &amp;quot;poor soul&amp;quot; is often oneself, it's not entirely altruistic!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2261898" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#2261835</link><pubDate>Tue, 24 Apr 2007 19:39:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2261835</guid><dc:creator>John</dc:creator><description>&lt;p&gt;You are getting old and wise when you start to think about the poor sole working on the code later. &amp;nbsp;Thanks.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2261835" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#2249837</link><pubDate>Mon, 23 Apr 2007 23:25:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2249837</guid><dc:creator>Alun Jones</dc:creator><description>&lt;p&gt;You probably can put breakpoints on the closing brace in Visual Studio. &amp;nbsp;However, I spend my day in at least 4 programming environments each with different debuggers and I won't even relate how many different C IDE's I've put up with over the years... Some habits are more portable than others.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2249837" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#2249782</link><pubDate>Mon, 23 Apr 2007 23:18:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2249782</guid><dc:creator>Alun Jones</dc:creator><description>&lt;p&gt;Never, never, never (what never? hardly ever) put functional code inside of #ifdef DEBUG sections!&lt;/p&gt;
&lt;p&gt;It's a really bad habit to get into, and it leads to things like:&lt;/p&gt;
&lt;p&gt;#if DEBUG&lt;/p&gt;
&lt;p&gt;bool x = Divide(1,1);&lt;/p&gt;
&lt;p&gt;#else&lt;/p&gt;
&lt;p&gt;Divide(1,0);&lt;/p&gt;
&lt;p&gt;#endif&lt;/p&gt;
&lt;p&gt;&amp;quot;It always works in the debug version, but crashes every time in the release build!&amp;quot;&lt;/p&gt;
&lt;p&gt;As for the previous notes about adding &amp;quot;return&amp;quot; or &amp;quot;continue&amp;quot; into a function or loop to allow a breakpoint at the end of the function or as the loop is about to loop, I seem to remember that you can actually put a breakpoint on the line with the closing brace.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2249782" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#2249443</link><pubDate>Mon, 23 Apr 2007 22:52:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2249443</guid><dc:creator>Stefan Wenig</dc:creator><description>&lt;p&gt;I know a few people who would definately answer that with: you should do test-driven development, not debugging. And I tend to agree with them more and more...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2249443" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#2248986</link><pubDate>Mon, 23 Apr 2007 21:57:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2248986</guid><dc:creator>Chris Moorhouse</dc:creator><description>&lt;p&gt;So, then, would supporting the Command - Query Separation Principle by not writing or calling functions with the TrySomething pattern be desirable, in your opinion?&lt;/p&gt;
&lt;p&gt;If the example returned something more significant than a success flag in addition to the out parameter, would your reasoning regarding write-only variables to support debugging still stand?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2248986" width="1" height="1"&gt;</description></item><item><title>re: Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/04/23/write-only-variables-considered-harmful-or-beneficial.aspx#2247881</link><pubDate>Mon, 23 Apr 2007 19:47:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2247881</guid><dc:creator>Shog9</dc:creator><description>&lt;p&gt;&amp;gt; This is because there is no good way in the Visual Studio debugger to say &amp;quot;show me the return value of the last function call&amp;quot;.&lt;/p&gt;
&lt;p&gt;And of course, the VC++ debugger *did* show me just that - which made that nested function call example a very easy thing to watch. 'Till reading this post, i'd assumed that the C# debugger also supported it, and that i'd just screwed up my installation horribly in some improbable way... thanks for simultaneously breaking my heart and restoring my confidence in my own sanity.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2247881" width="1" height="1"&gt;</description></item></channel></rss>