<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Some Creativity</title>
	<atom:link href="http://blog.somecreativity.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.somecreativity.com</link>
	<description>Weblog of Siddharth Uppal</description>
	<pubDate>Mon, 17 Nov 2008 22:39:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>NMock expectations for functions accepting &#8220;ref&#8221; and &#8220;out&#8221; arguments</title>
		<link>http://blog.somecreativity.com/2008/11/17/nmock-expectations-for-functions-accepting-ref-and-out-arguments/</link>
		<comments>http://blog.somecreativity.com/2008/11/17/nmock-expectations-for-functions-accepting-ref-and-out-arguments/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 22:28:48 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[expectations]]></category>

		<category><![CDATA[nmock]]></category>

		<category><![CDATA[out keyword]]></category>

		<category><![CDATA[ref keyword]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=529</guid>
		<description><![CDATA[There appears to be inadequate documentation on setting up expectations in NMock for methods that accept arguments by reference using “out” and “ref” keywords. Here is a quick note to give an example demonstrating how it can be done.
Consider the following interface:


	public interface IFoo
	{
		void Bar(out int a, ref int b);
	}

“Bar” method takes one “out” parameter [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There appears to be inadequate <a href='http://www.nmock.org/advanced.html'>documentation</a> on setting up expectations in <a href='http://nmock.org'>NMock</a> for methods that accept arguments by reference using “out” and “ref” keywords. Here is a quick note to give an example demonstrating how it can be done.</p>
<p>Consider the following interface:</p>
<pre name="code" class="c#">

	public interface IFoo
	{
		void Bar(out int a, ref int b);
	}
</pre>
<p>“Bar” method takes one “out” parameter and another “ref” parameter.</p>
<p>To start mocking &#8220;IFoo&#8221; you would obviously first create a new mock object implementing interface “IFoo”.</p>
<pre name="code" class="c#">

	IFoo aFoo = mocks.NewMock&lt; IFoo &gt;();
</pre>
<p>We store it in a variable named “aFoo”.</p>
<p>Here’s how you would set up an expectation to ask NMock to expect a call to method “Bar” on “aFoo” object with an “out” parameter and a “ref” parameter with 2 as its value.</p>
<pre name="code" class="c#">

	Expect.Once.On(aFoo)
		.Method(&quot;Bar&quot;).With(Is.Out, 2)
		.Will(new SetNamedParameterAction(&quot;a&quot;, 10),
			new SetNamedParameterAction(&quot;b&quot;, 20));
</pre>
<p>The actions specified in the “Will” part cause the “out” and “ref” parameters to be set to values 10 and 20 respectively after “Bar” is called on “aFoo”.</p>
<pre name="code" class="c#">

	int a, b = 2;
	aFoo.Bar(out a, ref b);

	// At this point &quot;a&quot; will be set to 10 and &quot;b&quot; will be set to 20 because
	// of the expectation specified above.
</pre>
<p>Hope this helps.</p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/529/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=529&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/11/17/nmock-expectations-for-functions-accepting-ref-and-out-arguments/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>
	</item>
		<item>
		<title>Automating windows forms UI testing</title>
		<link>http://blog.somecreativity.com/2008/11/06/automating-windows-forms-ui-testing/</link>
		<comments>http://blog.somecreativity.com/2008/11/06/automating-windows-forms-ui-testing/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 23:49:50 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<category><![CDATA[automated UI testing]]></category>

		<category><![CDATA[windows forms]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=518</guid>
		<description><![CDATA[If you have been blessed with a windows-forms application that has business-logic invading the user-interface, I have something that’ll help you. The most practical approach in this situation is to rearchitect the business layer and switch the UI over in a piecemeal fashion. While you&#8217;re doing this, automated testing of the user-interface will make your [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you have been blessed with a windows-forms application that has <a href='http://stackoverflow.com/questions/223982/business-logic-invading-ui-in-a-large-winforms-app'>business-logic invading the user-interface</a>, I have something that’ll help you. The most practical approach in this situation is to rearchitect the business layer and switch the UI over in a piecemeal fashion. While you&#8217;re doing this, automated testing of the user-interface will make your job a lot faster compared to manual testing.</p>
<p>For the purpose of this article let us consider a simple Windows Forms application (download link below). The application allows the user to provide two inputs and then either add them or subtract them. Simple, right?</p>
<p><b>The application</b><br />
<img src="http://siddhu.files.wordpress.com/2008/11/screenshot.png?w=304&#038;h=273" alt="screenshot" title="screenshot" width="304" height="273" class="alignnone size-full wp-image-517" /></p>
<p>Here’s the code for the event-handlers of interest to us:</p>
<pre name="code" class="c#">

		private void MainForm_Load(object sender, EventArgs e)
		{
			this.lblAnswer.Text = &quot;0&quot;;
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			this.lblAnswer.Text = Convert.ToString(this.numericUpDown1.Value + this.numericUpDown2.Value);
		}

		private void btnSubtract_Click(object sender, EventArgs e)
		{
			this.lblAnswer.Text = Convert.ToString(this.numericUpDown1.Value - this.numericUpDown2.Value);
		}
</pre>
<p>The handler for the load event of the form just sets the answer label to display “0”. The handler for the click event of each of the buttons retrieves the selected values from the numeric drop-downs, applies the appropriate operation, and writes the result into the label. </p>
<p><b>The tests</b></p>
<p>In order to write tests for this application, you can start by right-clicking on the class of the form (in this case MainForm), and selecting “Create Unit Tests…”. Hit “OK” on the dialog that pops up to create unit-tests in a separate project. Another dialog will pop up asking for the name of the test project. Just hit “Create”.</p>
<p>This will cause Visual Studio to do some heavy lifting for us and generate accessors to allow us to call methods and properties defined on MainForm, from our tests. We don’t have to write code for accessors using the Reflection API ourselves – so this is extremely cool. Doing it on our own is quite painful (<a href='http://msdn.microsoft.com/en-us/magazine/cc163864.aspx'>proof</a>).</p>
<p>Delete all the tests marked with the TestMethod attribute in the generated class because we’re going to write our own.</p>
<p>The first one is pretty simple. We expect the answer label to display a “0” when the form is initially loaded – so let’s test that. </p>
<pre name="code" class="c#">

		/// &lt;summary&gt;
		///A test for MainForm_Load
		///&lt;/summary&gt;
		[TestMethod()]
		[DeploymentItem(&quot;AppUnderTest1.exe&quot;)]
		public void MainForm_LoadTest()
		{
			MainForm_Accessor target = new MainForm_Accessor();
			target.MainForm_Load(null, null);
			Assert.AreEqual(&quot;0&quot;, target.lblAnswer.Text, &quot;Initial answer is zero&quot;);
		}
</pre>
<p>Notice that we can call MainForm_Load directly (no <a href='http://msdn.microsoft.com/en-us/library/system.reflection.aspx'>ConstructorInfo, MethodInfo – reflection stuff</a> required).</p>
<p>Once that’s done we can just check the text displayed in the answer label and make sure it is “0”.</p>
<p>We can take the same approach to call the click event handlers of the buttons and check the results for addition/subtraction.</p>
<p>Since there are various cases to test, I have a separate function GetTestTable that returns a two dimensional array where each row contains the two test-inputs, result of subtraction, and result of addition – in that order.</p>
<pre name="code" class="c#">

		public int[,] GetTestTable()
		{
			// Format of each row:
			// A, B, (A-B), (A+B)
			int[,] table =
			{
				{0, 0, 0, 0},
				{10, 0, 10, 10},
				{0, 10, -10, 10},
				{-10, 0, -10, -10},
				{0, -10, +10, -10},
				{10, 10, 0, 20},
				{-10, -10, 0, -20},
				{-10, 10, -20, 0},
				{10, -10, 20, 0}
			};
			return table;
		}
</pre>
<p>Following is the function that actually does the testing. We basically process each row returned by GetTestTable one by one. First we set the two inputs on the numeric drop-downs. Next we call the click event-handlers of both buttons verifying what is in the answer label against what we expect. Again notice that we can directly invoke the event handlers and even access properties of the answer label (lblAnswer).</p>
<pre name="code" class="c#">

		/// &lt;summary&gt;
		///A test for btnSubtract_Click
		///&lt;/summary&gt;
		[TestMethod()]
		[DeploymentItem(&quot;AppUnderTest1.exe&quot;)]
		public void AddSubtractTest()
		{
			MainForm_Accessor target = new MainForm_Accessor();

			int[,] table = this.GetTestTable();

			for (int i = 0; i &lt; table.GetUpperBound(0); i++)
			{
				int a = table[i, 0],
					b = table[i, 1],
					subtract = table[i, 2],
					add = table[i, 3];

				target.numericUpDown1.Value = a;
				target.numericUpDown2.Value = b;

				target.btnSubtract_Click(null, null);
				int result = Convert.ToInt32(target.lblAnswer.Text);
				Assert.AreEqual(subtract, result, String.Format(&quot;Subtract {0} and {1}&quot;, a, b));

				target.btnAdd_Click(null, null);
				result = Convert.ToInt32(target.lblAnswer.Text);
				Assert.AreEqual(add, result, String.Format(&quot;Add {0} and {1}&quot;, a, b));
			}
		}
</pre>
<p>To run these tests, select Test-&gt;Run-&gt;All Tests in Solution from the main-menu in Visual Studio. The “Test Results” window in Visual Studio should show that all tests passed.</p>
<p><strong>Summary</strong>
<p>There’re multiple ways to go about automating UI testing. You could use an automated testing tool like Mercury Quick Test. However if you want to take things into your own hands and take advantage of greater control, you could write your tests using NUnit or MS-Test and make PInvoke calls to send messages to various controls in the UI of your application under test. You could use the <a href='http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx'>SendKey API</a> in Windows.Forms too.</p>
<p>However if you want to take advantage of knowledge of the internals of the application under test, we have to use Reflection to set properties of the controls, invoke event handlers, call other methods and then test whether this resulted in the changes that we expected. This makes the job extremely painful. I hope this article shows how much easier it is if we leverage Visual Studio Team System to generate accessors for us.</p>
<p>I don’t see why the technique described above cannot be used to test WPF and Silverlight applications as well.</p>
<p><b>Download</b><br />
<a href='http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=somecreativity&amp;DownloadId=3678'>Click here</a> to download the code accompanying this article.</p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/518/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/518/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/518/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/518/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/518/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=518&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/11/06/automating-windows-forms-ui-testing/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>

		<media:content url="http://siddhu.files.wordpress.com/2008/11/screenshot.png" medium="image">
			<media:title type="html">screenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>Automatic properties with custom logic – part 2</title>
		<link>http://blog.somecreativity.com/2008/10/29/automatic-properties-with-custom-logic-%e2%80%93-part-2/</link>
		<comments>http://blog.somecreativity.com/2008/10/29/automatic-properties-with-custom-logic-%e2%80%93-part-2/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 20:51:52 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<category><![CDATA[automatic properties]]></category>

		<category><![CDATA[C# 3.0]]></category>

		<category><![CDATA[lambda expressions]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=509</guid>
		<description><![CDATA[Let’s say we have a class called ShoppingCartItem. We’re going to concern ourselves with two properties here namely TaxID and Taxable. The business logic dictates that an item is definitely non-taxable if it has a tax-id of zero, otherwise it may or may not be taxable which is decided by some code situated outside the [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Let’s say we have a class called ShoppingCartItem. We’re going to concern ourselves with two properties here namely TaxID and Taxable. The business logic dictates that an item is definitely non-taxable if it has a tax-id of zero, otherwise it may or may not be taxable which is decided by some code situated outside the ShoppingCartItem class. </p>
<p>How would you write your ShoppingCartItem class?</p>
<p>Now – we cannot really take advantage of automatic properties over here.</p>
<pre name="code" class="c#">

	public class ShoppingCartItem
	{
		public int TaxID { get; set; }
		public bool Taxable { get; set; }
	}
</pre>
<p>We really want the ShoppingCartItem to unset the Taxable flag when TaxID is zero. The setter for TaxID property seems to be the most obvious place to do that. But since we’re relying on the C# compiler to generate the getter/setter code we don’t really have control over that.</p>
<p>Of course, we have to fall back to the old way of doing it.</p>
<pre name="code" class="c#">

	public class ShoppingCartItem
	{
		private int mTaxID;

		public int TaxID
		{
			get
			{
				return this.mTaxID;
			}
			set
			{
				this.mTaxID = value;
				if (this.mTaxID == 0)
					this.Taxable = false;
			}
		}
		public bool Taxable { get; set; }
	}
</pre>
<p>That solves the problem we initially set out to solve but isn’t future proof. That’s because there’s nothing stopping a future programmer from adding new code in ShoppingCartItem class that directly saves values to mTaxID field instead of using the property setter. This could lead to Taxable being inconsistent with the value of TaxID. It would be better if we could somehow prevent direct setting of the backing field corresponding to the TaxID property even within the class.</p>
<p>Well, here’s an idea that leverages the lambda expression support in C# 3.0 to give us something that’s concise to write.</p>
<pre name="code" class="c#">

	public class ShoppingCartItem
	{
		public PropertyValue&lt;int&gt; TaxID;
		public PropertyValue&lt;bool&gt; Taxable;

		public ShoppingCartItem()
		{
			this.TaxID = new PropertyValue&lt;int&gt;()
			{
				OnSet = value =&gt;
				{
					if (value == 0)
						this.Taxable.Value = false;
				}

			};
			this.Taxable = new PropertyValue&lt;bool&gt;();
		}
	}
</pre>
<p>PropertyValue is the new class that I wrote. The idea is that you provide the code that should be executed when the TaxID is set, when initializing TaxID.</p>
<p>Here’s the code for the new class.</p>
<pre name="code" class="c#">

	public class PropertyValue &lt; T &gt; : System.ComponentModel.INotifyPropertyChanged
	{
		#region Private fields

		private Action mOnGet;
		private Action mOnSet;
		private T mValue;

		#endregion

		#region Constructors

		public PropertyValue()
		{
			this.mValue = default(T);
		}

		public PropertyValue(T initialValue)
		{
			this.mValue = initialValue;
		}

		public PropertyValue(T initialValue, Action onGet, Action onSet)
		{
			this.mValue = initialValue;
			this.mOnGet = onGet;
			this.mOnSet = onSet;
		}

		#endregion

		#region Properties

		public Action OnGet
		{
			private get
			{
				return this.mOnGet;
			}
			set
			{
				if (this.mOnGet == null)
				{
					this.mOnGet = value;
				}
				else
				{
					throw new InvalidOperationException(&quot;Getter can only be assigned once.&quot;);
				}
			}
		}

		public Action OnSet
		{
			private get
			{
				return this.mOnSet;
			}
			set
			{
				if (this.mOnSet == null)
				{
					this.mOnSet = value;
				}
				else
				{
					throw new InvalidOperationException(&quot;Setter can only be assigned once.&quot;);
				}
			}
		}

		public T Value
		{
			get
			{
				if (this.mOnGet != null)
				{
					this.mOnGet(this.mValue);
				}
				return this.mValue;
			}
			set
			{
				this.mValue = value;
				if (this.mOnSet != null)
				{
					this.mOnSet(this.mValue);
				}
				if (this.PropertyChanged != null)
				{
					this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(&quot;Value&quot;));
				}
			}
		}

		#endregion 

		#region INotifyPropertyChanged Members

		public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

		#endregion

		#region Overridden base class methods

		public override string ToString()
		{
			if (this.mValue != null)
			{
				return this.mValue.ToString();
			}
			else
			{
				return base.ToString();
			}
		}

		#endregion

	}
</pre>
<p>While it does appear to solve the issue, I’m not quite satisfied. So let me end this by pointing out the things I don’t like in the implementation and ask for ideas:</p>
<ul>
<li>
It is wordier compared to the automatic property support in C# and requires you to know about lambda expressions. Here’s how I think it should have been:</p>
<pre name="code" class="c#">

	public class ShoppingCartItem
	{
		public int TaxID
		{
			get;
			set
			{
				if (value == 0)
					this.Taxable = false;
			}
		}
		public bool Taxable { get; set; }
}
</pre>
<p>This doesn’t work in C# 3.0 and generates a compiler error “ShoppingCartItem.TaxID.get&#8217; must declare a body because it is not marked abstract, extern, or partial”.
</li>
<li>
Ideally, I should have been able to write the following which seems more succinct.</p>
<pre name="code" class="c#">

	public class ShoppingCartItem
	{
		public PropertyValue&lt;bool&gt; Taxable = new PropertyValue&lt;/bool&gt;&lt;bool&gt;();
		public PropertyValue&lt;int&gt; TaxID = new PropertyValue&lt;/int&gt;&lt;int&gt;()
		{
			OnSet = value =&gt; {
				if (value == 0)
					Taxable = false;
			}

		};
	}
</pre>
<p>But I cannot, because it generates a <a href='http://msdn.microsoft.com/en-us/library/5724t6za(VS.80).aspx'>compiler error</a> “A field initializer cannot reference the non-static field, method, or property”. This requires me to do the same thing inside the constructor which introduces an extra step.<br />
</int></bool></li>
</ul>
<p>What do you think?</p>
<p></bool></int></bool></int></p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/509/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=509&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/10/29/automatic-properties-with-custom-logic-%e2%80%93-part-2/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>
	</item>
		<item>
		<title>Automatic properties with custom logic</title>
		<link>http://blog.somecreativity.com/2008/10/24/automatic-properties-with-custom-logic/</link>
		<comments>http://blog.somecreativity.com/2008/10/24/automatic-properties-with-custom-logic/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 20:08:56 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<category><![CDATA[.NET]]></category>

		<category><![CDATA[automatic properties]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[VB]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=504</guid>
		<description><![CDATA[There should be a compiler supported way in C# to declare a property with custom getter/setter logic without having to explicitly declare a backing field. In the absence of such a feature, if you want to have custom getter/setter logic you have to ditch automatic properties, declare a backing field explicitly and then there’s nothing stopping a [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">There should be a compiler supported way in C# to declare a property with custom getter/setter logic without having to explicitly declare a backing field. In the absence of such a feature, if you want to have custom getter/setter logic you have to ditch automatic properties, declare a backing field explicitly and then there’s nothing stopping a future programmer from assigning directly to the backing field and the custom getter/setter logic not getting executed probably leading to bugs.</span></p>
<p><b>Update:</b><a href='http://blog.somecreativity.com/2008/10/29/automatic-properties-with-custom-logic-%e2%80%93-part-2/'>Check out part 2</a> where I take an example to bring the problem into perspective and propose a solution&#8230;</p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/504/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=504&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/10/24/automatic-properties-with-custom-logic/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Add Service Reference&#8221; option not appearing in Visual Studio 2008</title>
		<link>http://blog.somecreativity.com/2008/07/22/add-service-reference-option-not-appearing-in-visual-studio-2008/</link>
		<comments>http://blog.somecreativity.com/2008/07/22/add-service-reference-option-not-appearing-in-visual-studio-2008/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 00:11:55 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<category><![CDATA[.net 3.5]]></category>

		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=492</guid>
		<description><![CDATA[Had to do a bit of head-scratching on this one. New projects created in Visual Studio 2008 did show the “Add Service Reference” when right-clicking on a project in Solution Explorer while some existing ones didn’t.
Using “Add Web Reference” instead of “Add Service Reference” has its own set of issues in that WCF services are [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Had to do a bit of head-scratching on this one. New projects created in Visual Studio 2008 did show the “Add Service Reference” when right-clicking on a project in Solution Explorer while some existing ones didn’t.</p>
<p>Using “Add Web Reference” instead of “Add Service Reference” has its own set of issues in that WCF services are meant to be used with DataContractSerializer. &#8220;Add Web Reference&#8221; utilizes XmlSerializer which might lead to some surprises when consuming WCF web-services. The way the two serializers handle WSDL is different. <a href="http://blogs.msdn.com/eugeneos/archive/2007/02/05/solving-the-disappearing-data-issue-when-using-add-web-reference-or-wsdl-exe-with-wcf-services.aspx">This article</a> explains why you might find that property values of your complex types in web-services do not reach all the way to the web-service from the client.</p>
<p>Somebody logged a <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=316573">Microsoft Connect ticket</a> on this but didn’t receive an answer because the issue couldn’t be reproduced.</p>
<p>Anyway, if you’re facing this issue – make sure that the target framework for your project is .NET 3.0 or later (you can do this in the Application tab of your project’s properties). You need to do this extra step if you upgrade your project to Visual Studio 2008 from older versions otherwise &#8220;Add Service Reference&#8221; wouldn&#8217;t appear. You can target .NET 2.0 from Visual Studio 2008 projects and that&#8217;s the default behavior during upgrade.</p>
<p><strong><em>Update:</em></strong> This didn&#8217;t fix the issue for you? Check the comments for more alternatives.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/siddhu.wordpress.com/492/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/siddhu.wordpress.com/492/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/492/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/492/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/492/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=492&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/07/22/add-service-reference-option-not-appearing-in-visual-studio-2008/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>
	</item>
		<item>
		<title>A simple RTF report generator</title>
		<link>http://blog.somecreativity.com/2008/06/10/a-simple-rtf-report-generator/</link>
		<comments>http://blog.somecreativity.com/2008/06/10/a-simple-rtf-report-generator/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 23:56:37 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<category><![CDATA[reflection]]></category>

		<category><![CDATA[report]]></category>

		<category><![CDATA[rtf]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=484</guid>
		<description><![CDATA[
I was describing how a simple yet extensible report-generator could be implemented quickly to somebody. I&#8217;m posting it here as some of you might find it useful (and I can refer to this link in future conversations  ).

The concept:
…is really simple. The idea is to look for a placeholder like @Fruit and replace it [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal">
<p class="MsoNormal">I was describing how a simple yet extensible report-generator could be implemented quickly to somebody. I&#8217;m posting it here as some of you might find it useful (and I can refer to this link in future conversations <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
<p class="MsoNormal">
<p class="MsoNormal"><strong>The concept:</strong></p>
<p class="MsoNormal">…is really simple. The idea is to look for a placeholder like @Fruit and replace it with “Apple”. However to make the whole thing extensible, reflection is used. When calling the report generator, you need to specify a reportInput object (can be of any type), in addition to the file-paths of input and output reports. The report-generator uses reflection to determine the properties available on the reportInput object. <span> </span>For each property, it derives a tag name and substitutes the derived tag name with the actual property value in the input file. The text read from the input file after making replacements is finally written to the output file. For further extensibility, the tag format is not hard-coded and can be specified as an argument.</p>
<p class="MsoNormal"><strong>Before (an RTF file with placeholders):</strong></p>
<p class="MsoNormal"><a href="http://siddhu.files.wordpress.com/2008/06/before1.png"><img class="alignnone size-medium wp-image-487" src="http://siddhu.files.wordpress.com/2008/06/before1.png?w=300&#038;h=137" alt="" width="300" height="137" /></a></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong>After (an RTF file with placeholders replaced with values):</strong></p>
<p><a href="http://siddhu.files.wordpress.com/2008/06/after1.png"><img class="alignnone size-medium wp-image-488" src="http://siddhu.files.wordpress.com/2008/06/after1.png?w=300&#038;h=137" alt="" width="300" height="137" /></a></p>
<p><strong>The code:</strong></p>
<pre name="code" class="c#">

    public static class SimpleReportGenerator
    {
        public static void Generate(string inputFilePath, string outputFilePath, object reportInput, string tagFormat)
        {

            if (string.IsNullOrEmpty(inputFilePath))
                throw new ArgumentException(&quot;inputFilePath&quot;);
            if (string.IsNullOrEmpty(outputFilePath))
                throw new ArgumentException(&quot;outputFilePath&quot;);
            if (reportInput == null)
                throw new ArgumentNullException(&quot;reportInput&quot;);
            if (string.IsNullOrEmpty(tagFormat))
                throw new ArgumentException(&quot;tagFormat&quot;);

            string inputFileText = File.ReadAllText(inputFilePath);
            StringBuilder reportOutput = new StringBuilder(inputFileText);

            Type reportInputType = reportInput.GetType();
            PropertyInfo[] properties = reportInputType.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                string propertyTag = String.Format(tagFormat, property.Name);
                object propertyValueObj = property.GetValue(reportInput, null);
                string propertyValue = (propertyValueObj != null) ? propertyValueObj.ToString() : String.Empty;

                reportOutput.Replace(propertyTag, propertyValue);
            }

            File.WriteAllText(outputFilePath, reportOutput.ToString());

        }
    }
</pre>
<p><strong>An example:</strong></p>
<p>Defining ReportInput</p>
<pre name="code" class="c#">

    public class ReportInput
    {
        public string ReportTitle { get; set; }
        public string ReportHeading { get; set; }
        public string ReportBody { get; set; }
        public string ReportAuthor { get; set; }
        public DateTime ReportDate { get; set; }
    }
</pre>
<p>Creating a ReportInput for testing</p>
<pre name="code" class="c#">

        public ReportInput GetTest()
        {
            ReportInput input = new ReportInput() { ReportAuthor = &quot;John Doe&quot;, ReportBody = &quot;A quick brown fox jumped over a lazy dog&quot;, ReportDate = DateTime.Now, ReportHeading = &quot;The new report&quot;, ReportTitle = &quot;Here we go&quot; };
            return input;
        }
</pre>
<p>Generating a report</p>
<pre name="code" class="c#">

            string input = &quot;testreport.rtf&quot;;
            string output = &quot;testreport_out.rtf&quot;;

            ReportInput reportInput = GetTest();
            // &quot;@{0}&quot; indicates that a property named &quot;Foo&quot; corresponds to &quot;@Foo&quot; tag in the input file.
            SimpleReportGenerator.Generate(input, output, reportInput, &quot;@{0}&quot;);
</pre>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.somecreativity.com%2f2008%2f06%2f10%2fa-simple-rtf-report-generator%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.somecreativity.com%2f2008%2f06%2f10%2fa-simple-rtf-report-generator%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/siddhu.wordpress.com/484/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/siddhu.wordpress.com/484/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/484/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=484&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/06/10/a-simple-rtf-report-generator/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>

		<media:content url="http://siddhu.files.wordpress.com/2008/06/before1.png?w=300" medium="image" />

		<media:content url="http://siddhu.files.wordpress.com/2008/06/after1.png?w=300" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.somecreativity.com%2f2008%2f06%2f10%2fa-simple-rtf-report-generator%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>ArrayList item comparison</title>
		<link>http://blog.somecreativity.com/2008/06/06/arraylist-item-comparison/</link>
		<comments>http://blog.somecreativity.com/2008/06/06/arraylist-item-comparison/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 18:14:53 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=482</guid>
		<description><![CDATA[What&#8217;ll be the output of the following piece of code (asked here)?


		ArrayList a = new ArrayList();
		ArrayList b = new ArrayList();

		a.Add(1);
		b.Add(1);
		a.Add(2);
		b.Add(2.0);

		Console.WriteLine(a[0] == b[0]);
		Console.WriteLine(a[1] == b[1]);

One might expect&#8230;
True
True
But what you&#8217;d actually get is&#8230;
False
False
&#8230;because of boxing.
a.Add(1) boxes the integer 1 into an object and stores it in a, while b.Add(1) boxes the integer 1 into a separate object [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>What&#8217;ll be the output of the following piece of code (<a href="http://www.dev102.com/2008/06/02/a-programming-job-interview-challenge-6-c-games/">asked here</a>)?</p>
<pre name="code" class="c#">

		ArrayList a = new ArrayList();
		ArrayList b = new ArrayList();

		a.Add(1);
		b.Add(1);
		a.Add(2);
		b.Add(2.0);

		Console.WriteLine(a[0] == b[0]);
		Console.WriteLine(a[1] == b[1]);
</pre>
<p>One might expect&#8230;</p>
<p>True<br />
True</p>
<p>But what you&#8217;d actually get is&#8230;</p>
<p>False<br />
False</p>
<p>&#8230;because of boxing.</p>
<p>a.Add(1) boxes the integer 1 into an object and stores it in a, while b.Add(1) boxes the integer 1 into a separate object and stores it in b. Since a[0] and b[0] are going to be different objects, the check is going to fail. Same logic applies when comparing a[1] and b[1].</p>
<p>However, it gets interesting. If you tried to do a similar thing in VB.NET, the output would be different.</p>
<p>So with a code like this&#8230;</p>
<pre name="code" class="c#">

		Dim a as new ArrayList()
		Dim b as new ArrayList()

		a.Add(1)
		b.Add(1)
		a.Add(2)
		b.Add(2.0)

		Console.WriteLine(a(0) = b(0))
		Console.WriteLine(a(1) = b(1))		
</pre>
<p>The output is going to be&#8230;</p>
<p>True<br />
True</p>
<p>Surprised <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Well, VB.NET compiler translates the equality check (&#8221;=&#8221;) to a call to a helper function part of VB.NET runtime which would cast the left and right hand sides appropriately before comparison. In the first case, it would compare the two objects as integers, while in the second case it would compare the two objects as doubles after converting the integer on left hand side to a double.</p>
<p>That&#8217;s why we have generics - no surprises like these&#8230;</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/siddhu.wordpress.com/482/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/siddhu.wordpress.com/482/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/482/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/482/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/482/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=482&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/06/06/arraylist-item-comparison/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>
	</item>
		<item>
		<title>What you should do&#8230;</title>
		<link>http://blog.somecreativity.com/2008/05/01/what-you-should-do/</link>
		<comments>http://blog.somecreativity.com/2008/05/01/what-you-should-do/#comments</comments>
		<pubDate>Fri, 02 May 2008 00:26:59 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=481</guid>
		<description><![CDATA[I am fortunate enough to work with a couple of great individuals. Recently I was able to hypnotize persuade them into discussing things which should and shouldn’t be done in a software project  
I am absolutely sure that the discussion will help me in the future (and them). However I thought the merged list [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal">I am fortunate enough to work with a couple of great individuals. Recently I was able to <strike>hypnotize</strike> persuade them into discussing things which should and shouldn’t be done in a software project <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p class="MsoNormal">I am absolutely sure that the discussion will help me in the future (and them). However I thought the merged list is generic enough to help anyone, and hence this post.</p>
<p class="MsoNormal">
<p class="MsoNormal"><strong>In the beginning…</strong></p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">Before you start on a project, follow up with your managers and ensure that a detailed feasibility analysis has been done. This should include business planning, market analysis, and of course technology investigation to identify major road-blocks that are likely to be encountered in the future. For the technical analysis, you must involve the person who is going to actually write most of the code later on – because he’s the only one who’s most likely to consider all the possible issues.</li>
<li class="MsoNormal">Involve engineers during requirement gathering phase. If possible, ask each of them to take a good look at a system of other competitors and report back with their findings. This will help the Product Manager in that there’s a better guarantee of the surface area of features being covered. The other bigger benefit is that the engineers would have a much clearer idea of the sort of product they’re supposed to build without having to read hundreds of pages in the requirements documents. This will also make them, I believe, more receptive to changes made in the requirements later on as they’ll have a better picture of the landscape. Being receptive to changes is very important.</li>
<li class="MsoNormal">Identify major fears and unknowns that can negatively affect the outcome of a project. Make a proactive effort to address them at the start of the project.</li>
<li class="MsoNormal">Make responsibilities of all individuals involved in the project clear for accountability. Assign roles to them appropriately.</li>
<li class="MsoNormal">There should be a designated Project Manager whose role should be to maintain timelines, and escalate issues up to and from senior management. Asking a person in another role to also perform as a PM might not be effective always.</li>
</ul>
<p class="MsoNormal">
<p class="MsoNormal"><strong>Day to day…</strong></p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">Obtain sign-off for technical decisions and have a general plan for proceeding if a sign-off is not made within a specific amount of time.</li>
<li class="MsoNormal">Daily standup meetings help a lot in keeping every one up to date on status and outstanding issues. There’s a lot to be learned from body language which might otherwise be lost in other forms of communication. However it is important to keep the meetings short – 10 to 15 minutes. There’s lots of literature about how the meetings should and shouldn’t be done. I’ll just say that you need to try out different things and pick the one which works best with the personalities of the individuals in the team.</li>
</ul>
<p class="MsoNormal" style="margin-left:0.5in;">
<p class="MsoNormal"><strong>In the meetings…</strong></p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">Long weekly meetings drain the energy out of people and consequently the project. While I have my doubts on whether people pay attention after 45 minutes on average, I have even stronger doubts on the effectiveness of the meetings that go on for more than 2 hours. There might be exceptions of course, and I’d be interested in knowing what they did differently.</li>
<li class="MsoNormal">After the weekly meeting, ensure that the meeting minutes are sent out describing each item discussed in the agenda along with the decisions made, open issues, and action items (assigning a person responsible).</li>
<li class="MsoNormal">Be on time in meetings. Try to attend the meetings physically instead of over phone.</li>
<li class="MsoNormal">Try to avoid taking calls on your cell phones during meetings – especially when you are actively involved in a discussion.</li>
<li class="MsoNormal">Making decisions based on consensus is not always effective. Making decisions without considering inputs from others is equally bad.</li>
</ul>
<p class="MsoNormal">
<p class="MsoNormal"><strong>When conducting code / design / UI reviews…</strong></p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">If the process is to do design / code reviews in the meetings, to make the review more effective, try to restrict the number of attendees to the minimum absolutely necessary. Assigning reviewers to subsystems, if possible, might help in this regard.</li>
<li class="MsoNormal">When performing a code review ensure that you enforce the positive aspects of the code, while identifying the aspects that need improvement. Too many details are bad; only give as many specifics as you think are needed to send the developer whose code is being reviewed forward in the right direction. When performing a review, pay attention and make an honest effort to understand the problem being posed to you.</li>
</ul>
<p class="MsoNormal">
<p class="MsoNormal"><strong>When your code / design / UI is being reviewed by someone…</strong></p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">When asking someone for a code / design review, make a dedicated effort to get their feedback. This might require you to spend an hour preparing a sample application to demonstrate the problem, but the time spent in it would be worth the effort. Be open to feedback. Negative feedback is still better than no feedback at all.</li>
</ul>
<p class="MsoNormal">
<p class="MsoNormal"><strong>In general…</strong></p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">Do not shoot down ideas point blank. This erodes the enthusiasm of the contributors which is very difficult to get back. Make sure you identify the positive aspects of every idea.</li>
<li class="MsoNormal">Do not be afraid to hire temporary contractors and subject matter experts if required. That’s why a feasibility analysis is important.</li>
<li class="MsoNormal">When involving new people in a project, ensure that they have received adequate training on other internal products and frameworks as required.</li>
<li class="MsoNormal">If you’re required to use a common piece of code, ensure that it has an adequate test-bed. Secondly, push for dedicating engineering resources for their maintenance, depending of course on the size of the common code. If there aren’t any developers accountable for the upkeep of the common piece of code, you’re likely to lose the confidence of the developers who’re supposed to use it.</li>
</ul>
<p class="MsoNormal">
<p class="MsoNormal"><strong>But most importantly…</strong></p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">Work to a level where you can be proud of your contributions tomorrow. In the end, that’s all that matters.</li>
</ul>
<p class="MsoNormal">
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/siddhu.wordpress.com/481/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/siddhu.wordpress.com/481/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/481/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=481&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/05/01/what-you-should-do/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>
	</item>
		<item>
		<title>Two (useless but potentially) interesting tid-bits</title>
		<link>http://blog.somecreativity.com/2008/04/29/two-useless-but-potentially-interesting-tid-bits/</link>
		<comments>http://blog.somecreativity.com/2008/04/29/two-useless-but-potentially-interesting-tid-bits/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 06:17:15 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<category><![CDATA[compiler]]></category>

		<category><![CDATA[try]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=480</guid>
		<description><![CDATA[Try-Catch-Finally
A try-catch-finally is converted into IL by the C# compiler as a try-catch inside the try block of another try-finally. This allows for finally block to execute even when exceptions are raised in the catch block. Use ildasm and check it out yourself!
throw football;
Though you cannot throw an arbitrary managed object as “throw myObj” (you&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Try-Catch-Finally</strong></p>
<p>A try-catch-finally is converted into IL by the C# compiler as a try-catch inside the try block of another try-finally. This allows for finally block to execute even when exceptions are raised in the catch block. Use <a href='http://msdn.microsoft.com/en-us/library/f7dy01k1(VS.80).aspx'>ildasm</a> and check it out yourself!</p>
<p><strong>throw football;</strong></p>
<p>Though you cannot throw an arbitrary managed object as “throw myObj” (you&#8217;ll get a compilation error), you can modify the generated IL to do so. However your catch block will actually receive a <a href='http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.runtimewrappedexception.aspx'>RuntimeWrappedException</a> in these scenarios. Why is this allowed? Well, unlike C#, it is legal to throw arbitrary objects in managed C++ and in those cases a RuntimeWrappedException is thrown too.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/siddhu.wordpress.com/480/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/siddhu.wordpress.com/480/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/480/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=480&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/04/29/two-useless-but-potentially-interesting-tid-bits/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>
	</item>
		<item>
		<title>C# compiler optimizations and empty “try” block</title>
		<link>http://blog.somecreativity.com/2008/04/28/c-compiler-and-empty-%e2%80%9ctry%e2%80%9d-block/</link>
		<comments>http://blog.somecreativity.com/2008/04/28/c-compiler-and-empty-%e2%80%9ctry%e2%80%9d-block/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 00:47:09 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Tech/Hacks]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[compiler optimization]]></category>

		<category><![CDATA[empty try]]></category>

		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=479</guid>
		<description><![CDATA[There is some misinformation you’re likely to stumble upon via Google when searching for “C# compiler /optimize+”. Interestingly, the following snippet can be seen on various forums.
The following is a response from a developer on the C# compiler team: We get rid of unused locals (i.e., locals that are never read, even if assigned). We [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There is some misinformation you’re likely to stumble upon via Google when searching for “C# compiler /optimize+”. Interestingly, the following snippet can be seen on various forums.</p>
<blockquote><p>The following is a response from a developer on the C# compiler team: We get rid of unused locals (i.e., locals that are never read, even if assigned). We get rid of unreachable code. We get rid of try-catch with an empty try. <strong>We get rid of try-finally with an empty try.</strong> We get rid of try-finally with an empty finally. We optimize branches over branches: gotoif A, lab1 goto lab2: lab1: turns into: gotoif !A, lab2 lab1: We optimize branches to ret, branches to next instruction, and branches to branches.</p></blockquote>
<p>The part in <strong>bold</strong> is incorrect.</p>
<p>Before I dive into a simple app that I wrote to prove that the information is incorrect, there’s a simple logical reasoning to refute the claim. Basically, a function that has had a try/finally block completely removed because of an empty try or finally will behave completely differently than one who hasn’t. Optimizing something doesn’t mean you stop doing important things to save some time <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>“We get rid of try-finally with an empty try”. Do they really?</strong></p>
<p>For those who still aren’t convinced with the explanation above, I wrote a simple C# class and saved it in a file Test.cs. I compiled the code once from the command line without optimizations (“csc test.cs”) and once with optimizations (“csc /optimize+ test.cs”).</p>
<p>Here’s what Foo looked like in C#:</p>
<pre name="code" class="c#">

        private void Foo()
        {
            int x;
            try
            {
            }
            finally
            {
                DoSomething();
                DoSomethingElse();
            }
        }
</pre>
<p>Nothing much there… Just an unused variable “x”, an empty try, and some code in the finally block.</p>
<p>Here’s the IL without optimizations:</p>
<pre name="code" class="c#">

.method private hidebysig static void  Foo() cil managed
{
  // Code size       22 (0x16)
  .maxstack  0
  .locals init (int32 V_0)    // Here&#039;s our unused variable.
  IL_0000:  nop
  .try
  {
    IL_0001:  nop
    IL_0002:  nop
    IL_0003:  leave.s    IL_0014
  }  // end .try
  finally
  {
    IL_0005:  nop
    IL_0006:  call       void Test::DoSomething()
    IL_000b:  nop
    IL_000c:  call       void Test::DoSomethingElse()
    IL_0011:  nop
    IL_0012:  nop
    IL_0013:  endfinally
  }  // end handler
  IL_0014:  nop
  IL_0015:  ret
} // end of method Test::Foo
</pre>
<p>Here’s the IL with optimizations:</p>
<pre name="code" class="c#">

.method private hidebysig static void  Foo() cil managed
{
  // Code size       14 (0xe)
  .maxstack  0
  .try
  {
    IL_0000:  leave.s    IL_000d
  }  // end .try
  finally
  {
    IL_0002:  call       void Test::DoSomething()
    IL_0007:  call       void Test::DoSomethingElse()
    IL_000c:  endfinally
  }  // end handler
  IL_000d:  ret
} // end of method Test::Foo
</pre>
<p>As you can see:</p>
<ul>
<li>The compiler got rid of the unused variable when optimizations were enabled
<ul>Notice that the following declaration doesn’t appear in the second IL listing while it does in the first one:</p>
<p>.locals init (int32 V_0)</ul>
</li>
<li>Try / Finally is still there</li>
</ul>
<p>If you’re still questioning why you would have a try/finally with an empty “try” in the first place, you might find an <a href="http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/">earlier article of mine</a> interesting.</p>
<p>Hope this helps someone in an interview or something <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/siddhu.wordpress.com/479/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/siddhu.wordpress.com/479/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/siddhu.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/siddhu.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/siddhu.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/siddhu.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/siddhu.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/siddhu.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/siddhu.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/siddhu.wordpress.com/479/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/siddhu.wordpress.com/479/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/siddhu.wordpress.com/479/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.somecreativity.com&blog=7388&post=479&subd=siddhu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.somecreativity.com/2008/04/28/c-compiler-and-empty-%e2%80%9ctry%e2%80%9d-block/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/siddhu-128.jpg" medium="image">
			<media:title type="html">Sid</media:title>
		</media:content>
	</item>
	</channel>
</rss>