<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Buu Nguyen's Blog</title>
	
	<link>http://www.buunguyen.net/blog</link>
	<description>Thoughts on software development and project management</description>
	<pubDate>Mon, 08 Dec 2008 03:23:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/BuuNguyensBlog" type="application/rss+xml" /><feedburner:emailServiceId>700377</feedburner:emailServiceId><feedburner:feedburnerHostname>http://www.feedburner.com</feedburner:feedburnerHostname><item>
		<title>GUI Mockups Made Easy</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/478053135/gui-mockups-made-easy.html</link>
		<comments>http://www.buunguyen.net/blog/gui-mockups-made-easy.html#comments</comments>
		<pubDate>Mon, 08 Dec 2008 03:01:23 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[gui]]></category>

		<category><![CDATA[mockups]]></category>

		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=330</guid>
		<description><![CDATA[I have been using Visio a lot to design GUI mockups.  Visio is a pretty powerful and flexible software except for a few drawbacks and most notably the mockups produced by Visio have the Windows XP looks-and-feel.  This is fine if these are mockups for a Windows desktop application but pretty awkward for [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using Visio a lot to design GUI mockups.  Visio is a pretty powerful and flexible software except for a few drawbacks and most notably the mockups produced by Visio have the Windows XP looks-and-feel.  This is fine if these are mockups for a Windows desktop application but pretty awkward for other types of applications.  Lately, I came across a nice alternative called <a href="http://www.balsamiq.com">Balsamiq Mockups</a>.  Mockups produced by this tool are platform-neutral and thus can be used to sketch GUIs for virtually any kind of applications.  Besides, the control-set provided out of the box include many controls that Visio doesn&#8217;t have like tag cloud, map, browser window etc.  There are a couple of nice features like JIRA and Confluence integration, but the thing I find most notable about Balsamiq is its agility: one can be a lot more productive building most of their GUI mockups with Balsamiq than with Visio.</p>
<p>For example, if I want to sketch a grid populated with some existing data all I need to do is dragging the grid component out of the toolbar and fill in some CSV-formatted text.  (Anyone experiencing drawing data-grids with Visio will know the process is not that straight-forward.)  Or if I want to create a tag cloud, I just simply enter some words and Balsamiq will weight the words randomly and display them in a nice tag cloud picture.  For more complex components like tree or menu, a wiki-like syntax is available to fill in the data and decorate the output (e.g. menu item separator, checked menu item etc.)  This simple process of entering some plain text repeats for all kind of GUI components which need input data.    </p>
<p>Although I am happy with what Balsamiq has to offer, I wish the software has features to allow users to draw arbitrary shapes and add custom images into the mockups.  For now, users are limited to whatever GUI components and icon images provided out of the box.  Regardless, I think these requirements not necessary for a majority of GUI mockups and for most of the rest I think I can resort to my modest photo-editing skills :-).</p>
<p>Below is a sample mockup created with Balsamiq.  See more <a href="http://www.balsamiq.com/products/mockups/examples">here</a>.</p>
<p><img width="600" height="600" src="http://www.balsamiq.com/images/mytube.gif" alt="mockup" /></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=vky2O"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=vky2O" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=6xYQo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=6xYQo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=TZjJo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=TZjJo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/gui-mockups-made-easy.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/gui-mockups-made-easy.html</feedburner:origLink></item>
		<item>
		<title>Overview of C# 4.0</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/451527261/new-features-of-csharp-4.html</link>
		<comments>http://www.buunguyen.net/blog/new-features-of-csharp-4.html#comments</comments>
		<pubDate>Thu, 13 Nov 2008 07:02:28 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Programming Languages]]></category>

		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[Technologies]]></category>

		<category><![CDATA[.net 4.0]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[c# 3.0]]></category>

		<category><![CDATA[c# 4.0]]></category>

		<category><![CDATA[dynamic language runtime]]></category>

		<category><![CDATA[dynamic languages]]></category>

		<category><![CDATA[generics]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=274</guid>
		<description><![CDATA[Note: This article is also posted at The Code Project. Refer to this link.  There are quite interesting discussions going on there.
The .NET framework 4.0 CTP has just been released and I think it&#8217;s a good time to explore the new features of C# 4.0.  In this post, I will introduce about the [...]]]></description>
			<content:encoded><![CDATA[<p><em>Note: This article is also posted at The Code Project. Refer to this <a href="http://www.codeproject.com/KB/cs/csharp_4_overview.aspx">link</a>.  There are quite interesting discussions going on there.</em></p>
<p>The .NET framework 4.0 CTP has just been released and I think it&#8217;s a good time to explore the new features of C# 4.0.  In this post, I will introduce about the following features: dynamic lookup, generics covariance and contravariance support, optional and named parameters.<br />
<span id="more-274"></span><br />
<strong>1. Dynamic Lookup</strong><br />
If <code>var</code> in C# 3.0 brings about type inference for local variables with the purpose of saving a couple of key strokes, dynamic lookup adds much more to the dynamicity of the C# language.  When you declare a variable with <code>dynamic</code>, all of its method invocations or member accesses will be resolved at runtime.  For example, let’s look at the following code</p>
<pre name="code" class="csharp">
public static void Main() {
    dynamic obj = “I’m statically System.String”;
    obj.NotExistingMethod(“param”);
}
</pre>
<p>In the code, we create a string object and instead of assigning it to a variable of type <code>string</code>, we assign it to a variable declared as <code>dynamic</code>.  This basically instructs the compiler to not to attempt to resolve any method call or member access of the declared variable.  Instead, all these resolutions will happen at runtime.  That being done, the next line in which we invoke a non-existing method with an arbitrary parameter will compile just fine into CIL.  At runtime, when the method call is resolved and the runtime finds that there’s no such method in the runtime type (which is a <code>System.String</code>), an exception is thrown.   That being said, if we use a valid method then there would be no exception and the code will run fine till completion.  For example:</p>
<pre name="code" class="csharp">
    dynamic obj = “I’m statically System.String”;
    Console.WriteLine(obj.ToLower());
</pre>
<p>Not only that we can declare a variable as dynamic, we can also declare methods&#8217; arguments to be so.  For example:</p>
<pre name="code" class="csharp">
    private static void PrintID(dynamic obj) {
        Console.WriteLine(obj.ID);
    }

    public static void Main() {
        var person = new {ID = 111, Name = "Buu"};
        PrintID(person);

        var account = new {ID = 101, Bank = "Some Bank"};
        PrintID(account);
    }
</pre>
<p>We basically create two anonymous types, for the sake of convenience, both having a property called <code>ID</code> and then instantiate objects out of these types.  We then pass each of these two objects to the method <code>PrintID</code> which accepts a dynamic object and print out the ID property.  The code will print out “111” and “101” respectively.  And yes, we’ve just seen duck typing in action.  In C#.</p>
<p>That example also shows an interesting usage of <code>dynamic</code> in regarding to anonymous types.  Now, we can pass objects of anonymous types out of their declaration scope (e.g. the method) and still be able to invoke their methods or access to their members without resorting to verbose reflection code.  (And in fact, whenever you see any piece of reflection code in your application and regardless of the code&#8217;s purpose, there might be an opportunity to replace it with dynamic lookup to make the code more readable.)</p>
<p>We are not just limited to make statically typed .NET objects become dynamic, we can use this dynamic lookup feature to conveniently interact with “actual” dynamic objects available through the Dynamic Language Runtime (DLR) included in .NET framework 4.0.  In fact, one can implement such dynamic objects in C# by implementing the <code>System.Scripting.Actions.IDynamicObject</code> interface, which is also part of the DLR.  Regardless of the actual receiver of dynamic dispatch, the usage of dynamic lookup is exactly the same from the caller&#8217;s perspective.  </p>
<p>Some of you might wonder what code the compiler generates and whether there is any change to the CLR to support dynamic lookup or not.  To answer that question, let’s look at the CIL generated from the very first code fragment of this post.  (Click on the image to see the full size.)</p>
<p><a href="http://www.buunguyen.net/blog/wp-content/uploads/2008/11/dynamic.jpg"><img src="http://www.buunguyen.net/blog/wp-content/uploads/2008/11/dynamic.jpg" alt="" title="CIL of dynamic keyword" width="620" height="260"/></a></p>
<p>The generated CIL is pretty verbose but a skim through it reveals two important things.  Firstly, our “dynamic variable” turns out to be a plain old CLR <code>System.Object</code> instance.  And secondly, there’s no new CIL directive or opcode to support dynamic lookup.  Instead, dynamic resolution and invocation is completely handled by framework code.  In fact, the above CIL is equivalent to the following C# code, but now without the <code>dynamic</code> keyword.</p>
<pre name="code" class="csharp">
    object obj = &quot;I'm statically System.String&quot;;
    var payload = new CSharpCallPayload(
        RuntimeBinder.GetInstance(),
        false, false, &quot;NotExistingMethod&quot;,
        typeof(object), null);
    var callSite = CallSite&lt;Action&lt;CallSite, object, string&gt;&gt;.Create(payLoad);
    Action&lt;CallSite, object, string&gt; action = callSite.Target;
    action.Invoke(callSite, obj, &quot;param&quot;);
</pre>
<p>(In fact, I simplified the code a bit so that it can fit in one method, the actual CIL generated does have a check at <code>IL_000c</code> which basically looks at the <code>callSite</code> static field of a nested class, which is generated automatically by the compiler, to see if it&#8217;s null or not before going ahead and initializing it.  In order words, the <code>callSite</code> is cached for subsequent invocations of the same method.)</p>
<p>So there&#8217;s really no magic behind the dynamic keyword.  What the compiler basically does is generating some payload containing the information about the invocation so that it can be made at runtime.  If there&#8217;s any magic at all, it would be in the static method <code>CallSite.Create()</code> which uses reflection to invoke the <code>NotExistingMethod</code> on the given object if it’s not an instance of <code>IDynamicObject</code>.  </p>
<p>Now, we know that a “dynamic object” is actually a plain old object; it should explain why method can accept dynamic parameters.  It should also be of no surprise to know that dynamic lookup can also be applied to return value of an instance/static method or an instance/static field.  After all, unlike the var keyword which requires the compiler to infer the exact type at compile time, the compiler in dynamic lookup scenarios can simply pick <code>System.Object</code> as the type.<br />
<br/><br />
<strong>2. Generics Covariance and Contravariance</strong><br />
In previous versions of C#, generic types are invariant.  That is, for any two types <code>GenericType&lt;T&gt;</code> and <code>GenericType&lt;K&gt;</code>, in which <code>T</code> is a subclass of <code>K</code> or <code>K</code> is a subclass of <code>T</code>, <code>GenericType&lt;T&gt;</code> and <code>GenericType&lt;K&gt;</code> have no inheritance relationship whatsoever to each other.  On the other hand, if <code>T</code> is a subclass of <code>K</code> and if C# supports covariance, <code>GenericType&lt;T&gt;</code> is also a subclass of <code>GenericType&lt;K&gt;</code> or if C#  supports contravariance, <code>GenericType&lt;T&gt;</code> is a superclass of <code>GenericType&lt;K&gt;</code>.</p>
<p>To understand why pre-4.0 C# disallows covariance and contravariance, let’s look at some code</p>
<pre name="code" class="csharp">
    var strList = new List&lt;string&gt;();
    List&lt;object&gt; objList = strList; // compile-error, with cast or not
</pre>
<p>If the code in line 2, it can be error-prone.  Consider what we can write after line 2 assuming it is allowed:</p>
<pre name="code" class="csharp">
    // BOOM: we're adding an arbitrary AnyObject to what, at runtime, is a list of strings
    objList.add(new AnyObject());
</pre>
<p>On the other hand, if C# supported contravariance, we could have written the following problematic code:</p>
<pre name="code" class="csharp">
    var objList = new List&lt;object&gt;;
    objList.add(3);
    objList.add(new AnyObject());
    List&lt;string&gt; strList = objList; 

    // BOOM: we're getting an arbitrary object thinking it’s a string
    string element = strList.get(0);
</pre>
<p>Due to this invariant restriction, although for the good purpose, we can&#8217;t easily reuse variables and methods to respectively get assigned to or accepts various generic types.  It’s somewhat unfortunately because the key thing to realize that covariance is fine as long as <code>GenericType&lt;T&gt;</code> does not have any method or member accepting arguments of type <code>T</code> (e.g. if we can&#8217;t add a bunch of objects into the <code>objList</code>, which is indeed an instance of <code>List&lt;string&gt;</code>, we&#8217;ll be safe).  Besides, contravariance is just as safe if <code>T</code> does not appear in any return value from a member or method (e.g., if we can&#8217;t get out any string from <code>strList</code>, which is indeed an instance of <code>List&lt;object&gt;</code>, we&#8217;ll be safe).  </p>
<p>Fortunately, C# 4.0 provides us an option: if a <strong>generics interface</strong> or <strong>generics delegate</strong> which has a <strong>reference type</strong> <code>T</code> as its type parameter and does not have any method or member that take in a parameter of type <code>T</code>, we can declare it to be covariant on T.  On the other hand, if that interface or delegate does not have any method or member that returning T, we can declare it be contravariant on T.  (Notice the emphases, only interfaces and delegates have covariance and contravariance support and the type parameter must be a reference type.  On the other hand, C# arrays have been supporting covariance from the very beginning.)  </p>
<p>Let’s look at an example.  We have a <code>Generator</code> delegate which basically returns random instances of object of certain type (e.g. <code>string</code>).  Its declaration is as follows:</p>
<pre name="code" class="csharp">
    delegate T Generator&lt;out T&gt;();
</pre>
<p>Because this delegate does not take in any <code>T</code> as its argument, we can safely make it covariant on <code>T</code>.  And indeed, that compiler will allow us to do so by adding the modifier <code>out</code> before the type parameter.  However, if this delegate is declared as, say <code>delegate T Generator&lt;out T&gt;(T seed)</code> then the compiler will complain since it&#8217;s no longer safe for covariance.   Now, let’s look at the usage:</p>
<pre name="code" class="csharp">
    Generator&lt;string&gt; strGen = new Generator&lt;string&gt;(StringGenerator);

    // Below line is compiled now because Generator&lt;string&gt; is
    // subclass of Generator&lt;object&gt; under covariant rule
    Generator&lt;object&gt; objGen = strGen; 

    // Downcast is also allowed for the same reason
    strGen = (Generator&lt;String&gt;)objGen; 

    ...

    private string StringGenerator()
    {
        return &quot;I'm a random string&quot;;
    }
</pre>
<p>With contravariance, you need to use the <code>in</code> keyword.  Let&#8217;s look at an example making use of both contravariance and covariance:</p>
<pre name="code" class="csharp">
    delegate K Converter&lt;in T, out K&gt;(T param);
</pre>
<p>This converter takes an object of type <code>T</code> and converts it to an object of type <code>K</code> (e.g. convert <code>String</code> to <code>Object</code>).  Since it does not take in any <code>K</code>, it can safely be declared to be covariant on <code>K</code>.  Similarly, since it exposes no <code>T</code>, it can safely declare to be contravariant on <code>T</code>.  Its usage is as follows:</p>
<pre name="code" class="csharp">
    var converter = new Converter&lt;object, string&gt;( ConvertImpl);
    Converter&lt;string, object&gt; string2ObjectConverter = converter;
    object result = string2ObjectConverter(&quot;A&quot;); 

    ...

    private string ConvertImpl(object o) {
        return o.ToString();
    }
</pre>
<p>Note that although the above examples show how to declare covariance and contravariance for delegate types, it&#8217;s not different to do so with interfaces.  </p>
<p>Before we finish with covariance and contravariance, let’s look at what code the compiler generates.  After all, we know that the compiler must encode something to the CIL to denote covariant and/or contravariant generics types so that they can be consumed properly by client code.  And this is what the definitions of our Generator and Converter delegates viewed from ildasm.</p>
<p><img src="http://www.buunguyen.net/blog/wp-content/uploads/2008/11/generics.jpg" alt="" title="Generics covariance and contravariance"/></p>
<p>Do you notice anything?  Those little minus and addition signs are used to denote contravariance and covariance respectively.  And interesting enough, it turns out that the CLR has been supporting such CIL since the introduction of generics in .NET 2.0.  Therefore, it’s possible to write CIL using covariance and contravariance under .NET 2.0+.  Only by now that it’s possible to do so using C#.</p>
<p>A final thought about this feature, while this is a good enhancement to the language, I like the generics covariance/contravariance implementation, enabled via wildcards, in Java better for its flexibility.  Anyway, let’s just be happy with it for now, we can’t have everything.<br />
<br/><br />
<strong>3. Optional and Named Parameters</strong><br />
The last two features of C# 4.0 that we&#8217;ll discuss about are optional parameters and named parameters.  These features have been with VB.NET since forever and I’m glad they are finally implemented in C#.</p>
<p>With optional parameters, we can provide default values for methods’ and constructors’ parameters.  That way,  we don’t have to write a bunch of overloaded methods and constructors.  For example, we can define a constructor like this:</p>
<pre name="code" class="csharp">
    public Cart(int id, String name = “default cart”, double amount = 0d) {…}
</pre>
<p>Now, you can invoke this constructor with any of these calls:</p>
<pre name="code" class="csharp">
   new Cart(1);
   new Cart(1, “my cart”);
   new Cart(1, “my cart”, 105.5);
</pre>
<p>How exactly does C# implement this feature?  If we look at the CIL generated for this code, we’ll see there’s no magic at all.  Basically the default values will be injected to the call site so that the method invocation happens normally.  Here’s the CIL generated by the compiler: </p>
<p><img src="http://www.buunguyen.net/blog/wp-content/uploads/2008/11/named_param_use.jpg" alt="" title="Optional parameter usage" /></p>
<p>Some might think that the compiler gets the default values in the source code to inject into the caller’s code.  However, that will not work if a method with optional parameters is published as a library.  In that case, there’s no way the compiler can get the default values to inject to the code of the library’s client.  Therefore, what the compiler actually does is to encode the default parameters right into the method itself.  This is what the CIL for <code>Cart</code>’s constructor:</p>
<p><img src="http://www.buunguyen.net/blog/wp-content/uploads/2008/11/named_param_declaration.jpg" alt="" title="Optional parameter definition"/></p>
<p>Notice the <code>.param</code> directive which basically tells the compiler about the default values for the optional parameters.  These parameters are also annotated by the <code>[opt]</code> attribute.</p>
<p>While being a great feature, there’s a caveat when using optional parameters: since the compiler inlines the default values at the caller site, change to default values at the library site won’t be reflected unless the caller is recompiled.  In order words, you should consider default values of parameters as part of the published API of a method and you’d better make them right the first time.</p>
<p>Now, let’s say we want to call the <code>Cart</code>’s constructor with the <code>ID</code> and <code>amount</code> specified but not the <code>name</code>, how would we do that?</p>
<p>To avoid ambiguity (for example when two optional parameters are both strings), C# won’t allow us to simply skip a parameter like this:</p>
<pre name="code" class="csharp">
    new Cart(1, 15.5d); // compile-error
</pre>
<p>An approach C# could take is to allow this syntax:</p>
<pre name="code" class="csharp">
    new Cart(1, , 15.5d);
</pre>
<p>However, this looks terrible enough with just one missing parameter, much less more of them. (How do you like to read this code <code>MethodWithManyFields(,,,15,,”param”,,)</code>?)</p>
<p>For this particular situation, named parameters are excellent solution:</p>
<pre name="code" class="csharp">
   new Cart(1, amount: 15.5d);
</pre>
<p>This is not the only use of named parameters though.  A very important purpose of named parameters is to enhance the readability of code.  Let’s say you have a class having a bunch of fields that are to be initialized in a constructor.  Without name parameters, a constructor of such class will look very ugly and hard to understand without resorting to the documentation, source code, or Intellisense.  </p>
<p>One approach is to create a builder to create instance of such class.  For example:</p>
<pre name="code" class="csharp">
   new BigClass.Builder().attr1(“value”).attr2(“value”)...attrN(“value”);
</pre>
<p>This will make the code more explicit about what values are to be assigned to what fields.  However, the drawback is that we need to implement a builder class, which is quite a tedious task if we have to repeat that for many classes in our application.</p>
<p>With C# 3.0, it’s not that bad because we can use object initializer to do something like this:</p>
<pre name="code" class="csharp">
    new BigClass {Attr1 = “value”, Attr2 = “value”, …, AttrN = “value”}
</pre>
<p>This looks good, but we have to define all the necessary properties for it to work, which is also a tedious thing to do if we don’t really need properties for the class or if the class itself is immutable.</p>
<p>With named parameters, we have a very nice solution without having to write any builder or property if we don’t want to.  (Note the semicolon after the field name.)</p>
<pre name="code" class="csharp">
    new BigClass{attr1: “value”, attr2: “value”, …, attrN: “value”);

    // The below does the same thing
    new BigClass{attrN: “value”, attr1: “value”, …, attr2: “value”);
</pre>
<p>Regarding the implementation of this at the CIL level, the compiler is smart enough to infer the correct argument order and simply perform a plain old method invocation.  </p>
<p>That’s it.  The key features of C# 4.0.  I am personally glad that C# has come to support these.  Some people said that C# has become so complex and started losing its original beauty.  While I can understand that view, I think the situation is not that bad.  While it&#8217;s obvious that C# has more and more constructs to supports functional and dynamic programming, the statically typed nature and the old constructs of the language are still there and no developer is forced to use the new features if they don&#8217;t need to.  On the other hand, these features bring more options for those who need them and I&#8217;d rather have more options than to be handcuffed.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=3IyON"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=3IyON" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=8ZeIn"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=8ZeIn" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=beXBn"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=beXBn" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/new-features-of-csharp-4.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/new-features-of-csharp-4.html</feedburner:origLink></item>
		<item>
		<title>The 5 Types of Poor Architects</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/316133768/the-5-types-of-poor-architects.html</link>
		<comments>http://www.buunguyen.net/blog/the-5-types-of-poor-architects.html#comments</comments>
		<pubDate>Fri, 20 Jun 2008 10:55:32 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[Development Processes]]></category>

		<category><![CDATA[Management]]></category>

		<category><![CDATA[OOAD]]></category>

		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[Technologies]]></category>

		<category><![CDATA[architecture]]></category>

		<category><![CDATA[muses]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=208</guid>
		<description><![CDATA[I have worked with so many architects in my career, including those who have the &#8220;Architect&#8221; word in their business card and those who play architect role in their projects.  And while I had good fortune to meet very talented people, I am frequently disappointed by poor architects who put their ego, arrogance, fanaticism [...]]]></description>
			<content:encoded><![CDATA[<p>I have worked with so many architects in my career, including those who have the &#8220;Architect&#8221; word in their business card and those who play architect role in their projects.  And while I had good fortune to meet very talented people, I am frequently disappointed by poor architects who put their ego, arrogance, fanaticism (and sometimes, ignorance) before anything else.  Recalling the memories I have about the poor architects, I come up with the following grouping. <span id="more-208"></span></p>
<ul>
<li>
<strong>The nothing-but-nails architects. </strong> These architects have hammer and thus they see everything as nails.  That said, these people are very eagle to apply overkill technologies to solve even the simplest problems.  If the software has web front-end, then a MVC web framework must be used.  If it has to integrate with some back-end system, then an Enterprise Service Bus implementation must be deployed.  Business logic?  We need Enterprise Java Bean, baby.  If there are 100 concurrent users, then the system should be hosted in a farm environment with 2 web servers, 2 application servers and 1 database server.  And architecture design won&#8217;t stop until these architects have put all 23 GoF patterns and one dozen of enterprise architectural patterns which they just learn from a book into their Visio diagrams.
</li>
<p></p>
<li>
<strong>The no-news-is-good-news architects.</strong>  These architects are afraid of new things, those they often insist to be &#8220;unproven&#8221; and &#8220;risky&#8221;.  Some of these architects are of same group as the nothing-but-nail guys, i.e. they are so proud of their bag of tricks that they feel no other technologies are relevant and all problems are the same.  The others are way behind the technological trends that they feel threatened by new technologies and tools.  The arguments these architects often use to turn down new ideas include &#8220;it will never work&#8221;, &#8220;this is not practical&#8221;, &#8220;we already has proven methods, why bother such risky solution?&#8221;, or even the discussion-stopping message &#8220;I have solved this problem before, I know what works and what do not.&#8221;  I remember an occasion in which I observed a senior architect criticized heavily the design of another architect who &#8220;dared&#8221; to suggest the use of Amazon&#8217;s SimpleDB as the storage engine for their new web application.  Arguments used by the former include &#8220;database over HTTP is simply unacceptable&#8221;, &#8220;we don&#8217;t need those thousands of servers in Amazon&#8217;s farm&#8221;, and &#8220;you are bringing extra risk for us by introducing another node of security&#8221;.  The poor latter architect, he did not know he was suggesting something which was radically new to the mind of the former.
</li>
<p></p>
<li>
<strong>The do-as-I-said architects.</strong>  Unlike the no-news-is-good-news group which bashes against new ideas, this group turns down whatever ideas not coming from them.  This type may not necessarily feel threatened by new things, they just feel like their ability is being challenged by ideas they did not think of from the first place.  If they think using Open ESB should be used, then any suggestion about BizTalk, or a home-grown integration solution that does just the job well will be turned down.  Even if they do think the latter two are better ideas.  Similarly, they will turn down any &#8220;RESTful&#8221; ideas because it&#8217;s WS-* that they propose in the first place even if they understand that the REST alternative may save them bunch of implementation efforts.  Just do as they said and all is good.
</li>
<p></p>
<li>
<strong>The silver-bullet-obsession architects. </strong> This group stands on opposite end from the no-news-is-good-news group: they are crazy about new things.  They are so interested in fads and buzzwords that they include these in any presentation they make and any design solution they propose.  To these architects, it&#8217;s just cool to talk about and use new things while completely dismissing the relevancy of such things to the problem at hand.  EJB?  So old-fashioned, let&#8217;s use RoR.  Ajax?  Forget about it, RIA is the future.  RIA by Flex?  Silverlight with managed code is the key.  ORM is the past, it should be LINQ-2-SQL all the way down, baby.  And they keep spending their career looking for more silver bullets.
	</li>
<p></p>
<li>
<strong>The UML-only architects.</strong>  If you have read my essay, <a href="http://www.buunguyen.net/blog/the-code-is-the-design.html">The Code is the Design</a>, you should be able to guess how bad I feel about architects who think coding is only for the wimps.  Indeed, there are architects who think that if they have to write the code then there&#8217;s little distinction between them and the plain old poor developers.  They think that the role is to direct, i.e. draw some diagrams and handle them out to the coders who will &#8220;realize&#8221; the design.  They argue that coding is just a simple step if the design is done right.  Some may go as far as stating that they don&#8217;t even need to know how to code in a language or understand the ins-and-outs of a technology before architecting a solution using those language and technology.  For example I met an architect who admitted that he had not coded any single line of Java code but thought that he would do fine when architecting enterprise JEE applications. &#8220;As long as I have good Java coders to implement my design,&#8221; he concluded.  A joke?  Not at all.  True story!
</li>
</ul>
<p>There, we have seen the 5 groups of architects who have somewhat been successfully in ruining the software architect role in the eyes of other people.  It&#8217;s high time they threw away their arrogance to not look down on others&#8217; opinions, got pass their boosterism to use the most appropriate tools for the problem at hand, and acknowledged their ignorance by continuously learning and keeping up with technological trends.  And last but not least, it&#8217;s high time they started writing code again…  And if the software industry has any luck, 5 or 10 years from now some developers may come across this post and think I was joking.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=5bGJO"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=5bGJO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=WiU8o"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=WiU8o" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=VZYno"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=VZYno" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/the-5-types-of-poor-architects.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/the-5-types-of-poor-architects.html</feedburner:origLink></item>
		<item>
		<title>The Story of a Hope-Driven Developer</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/293435844/the-story-of-a-hope-driven-developer.html</link>
		<comments>http://www.buunguyen.net/blog/the-story-of-a-hope-driven-developer.html#comments</comments>
		<pubDate>Mon, 19 May 2008 11:56:05 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[developers]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/the-story-of-a-hope-driven-developer.html</guid>
		<description><![CDATA[A fictitious story about a fictitious &#8220;hope-driven&#8221; developer&#8230;  In a sense, it&#8217;s fictitious because there&#8217;s probably no one single coder exposes all these behaviors of being hope-driven.  On the other hand, it&#8217;s not hard to find one who frequently displays one or more of these behaviors.  Anyway, let&#8217;s now travel into the [...]]]></description>
			<content:encoded><![CDATA[<p>A fictitious story about a fictitious &#8220;hope-driven&#8221; developer&#8230;  In a sense, it&#8217;s fictitious because there&#8217;s probably no one single coder exposes all these behaviors of being hope-driven.  On the other hand, it&#8217;s not hard to find one who frequently displays one or more of these behaviors.  Anyway, let&#8217;s now travel into the mind of our fictitious hope-driven fellow&#8230;<br />
</p>
<hr />
<br />
<i>I am a hope-driven developer.  I am superior and productive. I love coding and I&#8217;m different from others. </p>
<p>Unlike others, I don&#8217;t write unit test for my code.  I hope my code will work right because I&#8217;m so good at coding.  Even in the rare cases when it doesn&#8217;t, the QA team should be able to catch the defects easily and I will immediately know what happen to make necessary fixes.  I hope I will never have to touch most of the already written code again and if I don&#8217;t have to revisit it, what would unit tests help anyway? </i><br />
<span id="more-207"></span><br />
<i>Unlike others, I don&#8217;t check in compilable code into the source control system very often.  Instead, I code it straight for several days (or weeks) until finishing my module before checking everything in.  I hope my code will not break any code of others and I hope others&#8217; code won&#8217;t cause funny behavior in mine.  Besides, my colleagues should follow the architecture design so carefully that there are no integration defects between their components and mine.  </p>
<p>Unlike others, I don&#8217;t follow coding conventions.  I believe people are different and should be respected for that.  I am not productive following a coding style I&#8217;m not familiar with and it&#8217;s productivity that I am getting paid for.  I hope my peers will understand my code easily because as I mentioned, I&#8217;m so good in coding.  But I hope I never have to read that code of my peers because they seem to employ very cryptic styles.  (Being as tolerant as I am towards people&#8217; uniqueness, I just can&#8217;t understand why somebody does not want to include an &#8220;i_&#8221; prefix for their variables to denote integer type.)</p>
<p>Unlike others, I don&#8217;t write comments.  I hope that my code is so self-explanatory that everybody can easily understand.  How is it possible that one cannot guess from my highly self-explanatory code as to which the pre-conditions of a procedure are, the exceptions thrown by it, and the logic behind it?  After all, it&#8217;s written in a really high-level programming language.  But why should anybody read my code if it is really so perfect?  (Encapsulation and loose-coupling, everyone?)</p>
<p>Unlike others, I don&#8217;t learn and use design patterns.  I hope that my design skill is so good that I don&#8217;t need to learn from any others.  Even if it is not the case (hardly be), I hope that design patterns overkill for all my design problems.  Besides, my problems, which are very challenging and unique, would have no such thing as a proven solution to them.  I also hope that the languages I use are so superior that design patterns are just so irrelevant.  </p>
<p>Unlike others, I can only start writing code when having every detail of the requirement spelled out and a detailed design document in place.  By having comprehensive requirement specifications, I don’t have to change my code frequently mid-course because of requirement misunderstanding or guessing.  I also hope that it would make my customers feel less freely to change their mind because all things having already been written down.  And by having a good and detailed design document in place, my colleagues&#8217; code and mine will work together smoothly and automatically because the code are mostly a one-to-one mapping from a good and detailed design.</p>
<p>Unlike others, I look down on the so-called 15-minutes daily meetings, during which people in turn report what they had done, would do, and any problems faced.  Everyone should be professional enough to know what they are supposed to do for the day and problems should visible to the right people at the right time without requiring a daily teaming-up.  Besides, the works of my colleagues and I are usually so independent that there is no need to communicate so frequently.  (Just follow the design document and code your way through, guys!)</p>
<p>Unlike others, I don&#8217;t learn new things.  I hope that the knowledge that I have gained thus far is sufficient for me to address any coding problem.  And as I am so familiar with the current tools, I am supposed to be highly productive with them than I can ever be with any other tools.  (After all, it&#8217;s a famous person, who I can&#8217;t remember the name and is said to write that there would be no silver bullet upon the next decade in the software engineering field.  I can&#8217;t agree more!)</p>
<p>That&#8217;s how I get by.  Coding productively and passionately.  I typically chunk out a hundred or so lines of code per week and if you take into my multi-year software development career, that is a lot of code.  I can&#8217;t help but feeling so proud of what I have done&#8230;  </p>
<p>I love coding and I&#8217;m different from others.  I am superior and productive.  I am a hope-driven developer&#8230; </i></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=PXRlO"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=PXRlO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=2xYDo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=2xYDo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=ScPro"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=ScPro" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/the-story-of-a-hope-driven-developer.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/the-story-of-a-hope-driven-developer.html</feedburner:origLink></item>
		<item>
		<title>Object-oriented database programming with db4o - Part 2</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/258247883/object-oriented-database-programming-with-db4o-part-2.html</link>
		<comments>http://www.buunguyen.net/blog/object-oriented-database-programming-with-db4o-part-2.html#comments</comments>
		<pubDate>Wed, 26 Mar 2008 11:14:37 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[Technologies]]></category>

		<category><![CDATA[db4o]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/object-oriented-database-programming-with-db4o-part-2.html</guid>
		<description><![CDATA[Finally, I could manage some time writing up the follow-up post about other interesting features of db4o, specifically about client-server feature and transaction &#038; concurrency support.  You can read the article here: http://www.codeproject.com/KB/cs/oop_db4o_part_2.aspx.  
This write-up also gives me a chance to learn about some cool new features of db4o 7.2 (currently development version) [...]]]></description>
			<content:encoded><![CDATA[<p>Finally, I could manage some time writing up the follow-up post about other interesting features of db4o, specifically about client-server feature and transaction &#038; concurrency support.  You can read the article here: <a href="http://www.codeproject.com/KB/cs/oop_db4o_part_2.aspx">http://www.codeproject.com/KB/cs/oop_db4o_part_2.aspx</a>.  </p>
<p>This write-up also gives me a chance to learn about some cool new features of db4o 7.2 (currently development version) such as LINQ integration, transparent activation and transparent persistence.  These are really big changes from the previous version I tried (6.3).  Hope that I can find some time writing about all these features.  But don&#8217;t wait for me though, just go ahead and try them yourself&#8230;</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=EK76O"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=EK76O" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=iVD3o"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=iVD3o" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=o38Bo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=o38Bo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/object-oriented-database-programming-with-db4o-part-2.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/object-oriented-database-programming-with-db4o-part-2.html</feedburner:origLink></item>
		<item>
		<title>Attributes of good leaders</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/231057878/attributes-of-good-leaders.html</link>
		<comments>http://www.buunguyen.net/blog/attributes-of-good-leaders.html#comments</comments>
		<pubDate>Thu, 07 Feb 2008 15:51:13 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[Management]]></category>

		<category><![CDATA[Self Improvement]]></category>

		<category><![CDATA[leadership]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/attributes-of-good-leaders.html</guid>
		<description><![CDATA[What are the attributes that every leader, be she a mid-level manager or a CEO, need to have to be highly effective?  Technical competency and domain knowledge?  Obviously, although these are different for different industries or functional areas.  Below is the list of industry- and functional-independent attributes which I think a good [...]]]></description>
			<content:encoded><![CDATA[<p>What are the attributes that every leader, be she a mid-level manager or a CEO, need to have to be highly effective?  Technical competency and domain knowledge?  Obviously, although these are different for different industries or functional areas.  Below is the list of industry- and functional-independent attributes which I think a good leader must possess.  I will not go into deep details for each of the attribute because that would make this post very long.  Therefore, I will leave the elaboration of each of the attributes to subsequent posts.<span id="more-204"></span></p>
<ul>
<li><strong>High emotional intelligence (EQ)</strong>.  EQ is the ability to understand, manage, and influence self&#8217;s and others&#8217; feeling and therefore essential for effective leadership, which is mostly about working with people and making the best out of them.  A person with low EQ does not know how to listen, how to respond, and how to behave properly to different people in different situations.  And such person can&#8217;t be a good leader.</li>
<p></p>
<li><strong>Ability to articulate a vision and inspire people in that vision</strong>. Not only needs an organization a vision, even a project also needs one.  A vision fosters a desired culture, establishes a compelling mission and envisions a future, enables turn-around (if one is needed), and creates a synergy among members so that they can enthusiastically and steadily move towards the shared goal and never lose focus.  Without a vision, autonomy and things like that are just the management dream.</li>
<p></p>
<li><strong>Ability to see everyone&#8217;s strengths and put them in the right jobs</strong>.  The focus on strengths, instead of weaknesses enables outstanding achievement and high staff satisfaction.  Don&#8217;t give an engineer bad rating for his poor technical writing skills, give him a good rating for his outstanding problem-solving skills and hire another person to do the writing instead.</li>
<p></p>
<li><strong>Ability to grow and develop people</strong>.  This includes things like giving proper feedbacks, setting examples, investing in suitable training, delegating well, setting smart goals, and buying them coffee (I&#8217;m not joking).  If the leader gets hit by a bus, somebody in the team must be capable of taking his role.  Or better yet, the team does not need a leader at all (except for someone to buy them coffee).</li>
<p></p>
<li><strong>Passion</strong>.  You can&#8217;t do great things and inspire others to do great things if you don&#8217;t love what you do.  And passion must be revealed not just through the speeches but through actions.  Say you love new technologies?  Show your people that you do keep up and play with new technologies, or better yet, innovate new technologies.</li>
<p></p>
<li><strong>Integrity, integrity, integrity</strong>.  The leader must be a person his people trust.  A high integrity leader treats his people with respect and is fair to all of them.  (And being respectful does not mean leaders don&#8217;t sack the wrong people, those who lack of both skills and attitude to get things done and share no same value with the organization.)  If there&#8217;s no integrity in the leader, all the other things are irrelevant at best.  People don&#8217;t follow bosses who have no integrity.  And there&#8217;s no leader without followers.  Period.</li>
</ul>
<p>Note that all these attributes do not stand in separation but are highly interrelated.  You can&#8217;t grow people if you can&#8217;t see through their strengths and focus only on weaknesses.  Likewise, you can&#8217;t articulate a vision and inspire your people if you don&#8217;t possess good EQ to understand and manage the differences of your people.  </p>
<p>On the other hand, all of these attributes are learnable one can definitely learn to improve one&#8217;s capability to be an effective leader.  There is no such thing as a born leader.  Hardworking and continuous improvement are those that make people leaders.  </p>
<p>If you work for a boss who displays all the above attributes, consider yourself very lucky.  If you are the boss yourself and possess all these attributes, then congratulations!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=NurkO"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=NurkO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=2Qsro"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=2Qsro" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=CYR6o"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=CYR6o" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/attributes-of-good-leaders.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/attributes-of-good-leaders.html</feedburner:origLink></item>
		<item>
		<title>On interviewing - beyond technical competence</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/189371328/on-interviewing-beyond-technical-competence.html</link>
		<comments>http://www.buunguyen.net/blog/on-interviewing-beyond-technical-competence.html#comments</comments>
		<pubDate>Fri, 23 Nov 2007 15:21:41 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[Management]]></category>

		<category><![CDATA[Self Improvement]]></category>

		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[interviewing]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/on-interviewing-beyond-technical-competence.html</guid>
		<description><![CDATA[In the last few posts on interviewing, I discussed mostly about the technical aspects of the interviewing process and some readers had raised the concern that whether technical competence alone is sufficient for doing programming job well.  Well, it’s definitely not.  In this post, I will discuss on the three most important factors, [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.buunguyen.net/blog/the-wrong-attitude-of-learning-on-the-job.html">last</a> <a href="http://www.buunguyen.net/blog/some-basic-but-effective-net-interview-questions.html">few</a> <a href="http://www.buunguyen.net/blog/mcsdnet-certification.html">posts</a> on interviewing, I discussed mostly about the technical aspects of the interviewing process and some readers had raised the concern that whether technical competence alone is sufficient for doing programming job well.  Well, it’s definitely not.  In this post, I will discuss on the three most important factors, besides technical skills, that people must care about when evaluating candidates for a programming job.<br />
<span id="more-191"></span></p>
<p><strong>Passion</strong><br />
You want people programmers who are really passionate about their craft and take pride on what they do.  Passionate people are self-motivated; you don&#8217;t have to spend your time on preaching them on why they should add value to the team in one way or another.  They are also autonomous; as long as you have given clear and challenging objectives, they will know how to get things done.  Passionate programmers will spend their weekend surfing over technological blogs and feeds to keep them up to date and their evenings reading books or coding something, unrelated to the project, to sharpen their knowledge and skills.  Passionate programmers are also curious, they just don&#8217;t accept the fact that there is something about this software business that they can&#8217;t understand and will go any necessary length to understand stuffs under the hood.  They will “javap” Java class files to see what the bytecode instructions look like; they will decompile DLLs to see how the MS developers actually write code; they will use Fiddler to see what are actually sent back and forth between their web client and the WCF web service…</p>
<p>Look for passion in CVs.  Do the candidates code in their free time even as simple building some “toy” projects?  Are they contributors of any open-source projects?  Look for passion during the interview.  Asking them how they learn new things - whether they are up to date about latest technologies and trends, whether they learn things on their own initiative instead of <a href="http://www.buunguyen.net/blog/the-wrong-attitude-of-learning-on-the-job.html">&#8220;learning on the job&#8221;</a>.  Notice if they sound really enthusiastic when talking about technologies or display a curiosity in stuffs that they don&#8217;t know.  At times, you will interview very good liars, but then, passion is among the most difficult things to be faked and I can&#8217;t think of any single mistake I&#8217;ve made on this so far.</p>
<p><strong>Trustworthiness</strong><br />
There is nothing worse than a highly competent programmer who is dishonest.  Dishonest people have excuses for almost everything.  They cover their mistakes with lies and blames.  They will trick anyone on everything just to get to where they want to be.  They will take all praises if things go well and dismiss all the responsibilities when things go wrong.  They spend office time fulfilling their personal timetable and always act as though they were the most hardworking staff.  And the more competent they are, which usually mean the more authority they would assume in the project, the more damaging it will be when their mistakes are uncovered.  The bottom line, dishonest people, no matter how competent, ruin the people, the project, and the organization.</p>
<p>On the contrary, trustworthy people will tell you and everyone else in the team about their mistakes and have a plan to avoid it from happening again.  They even take note of every criticism from others in order to reflect and improve themselves.  They are transparent in everything they do even if that means there are more chances of them being caught of making mistakes (“So what?  Everybody makes mistake, the point is to learn from it and be a better person”, these people think.)  And last but not least, trustworthy people also get thing done.  They are given a task and if they say they will finish it they will finish it.</p>
<p>It&#8217;s quite difficult to tell if people are trustworthy or not unless you have worked with them for a while.  But there are a few things that can help.  Check if they really know the things they list in the CV.  Check for their integrity by asking questions about their past behaviors in certain circumstances - try to ask a lot of questions and identify inconsistency in things they say.  And as this is no exact science, use your instinct as well.  If they display any single sign of being untrustworthiness, then unless they are so competent that you really want to give them a try, you should quickly proceed with a no-hire decision.</p>
<p><strong>Teamwork</strong><br />
Programmers have to work well in team.  You don&#8217;t need a hero who does not listen or accept almost anything said and done by others.  You don&#8217;t need a hero who refuses to participate in code review just because they think their code is perfect or because they don&#8217;t want to accept any comments from &#8220;those inferior programmers&#8221;.  You don&#8217;t need a hero who disregards almost every team rules and processes.  These people, often cynical, never see the good things in others but can spend the whole day criticizing the bad things.  In most team meetings, these people either speak a lot, leaving no space for other (&#8221;I&#8217;m the only one in this whole team that can make sense.  The others had better listen to what I say&#8221;) or they don&#8217;t speak a thing (&#8221;Are these people know what they&#8217;re talking about?  I’m bored to dead here.&#8221;)  </p>
<p>On the other hand, people who have high teamwork spirit will care about everyone else in the team.  And even if their colleagues are really incompetent, these people, instead of saying &#8220;I hate working with these jerks&#8221;, they will say &#8220;I think I can assist my colleagues in this particular area&#8221;.  They think independently and at the same time value diverse opinions; they can work effectively on their own and at the same time care about the things others do and are always willing to give a helping hand.  They not only comply with team&#8217;s discipline but also do their best to bolster it as they know discipline creates great team, or simply because they can&#8217;t just accept the idea that others have to suffer because of their sloppiness or the idea that they are too lazy to adhere to something the whole team has agreed on.  They share their knowledge to their colleagues whenever they have a chance.  And if you have a team wiki&#8217;s, their names will be in the top of the contributor list.  </p>
<p>Just like trustworthiness, it&#8217;s very hard to tell if people have teamwork spirit or not unless you have a sufficient amount of time working with them.  Again, instinct counts.  Does this person seem to talk only about his/her achievements without any regards to the people s/he worked with?  Does this person mostly use &#8220;I&#8221; instead of &#8220;We&#8221; when describing all the significant technical decisions made in his past 50-people project?  What does s/he think about other job roles like tester, business analysts?  Does s/he think that discipline is very necessary?</p>
<p><strong>Conclusion</strong><br />
That’s it.  Passion, trustworthiness, and teamwork spirit (plus sufficient technical ability) are all that you need.  You may think these things are too obvious to be discussed at length in any blog post, but then, as simple as they are many interviewers I know often forget about them and pay too much of their time questioning the technical competence alone.  The more time you spend up-front to evaluate these factors during the hiring, the better off your organization/project will be.  And if some time in the middle project that you discover that the person you hired is dishonest, lacks of passion, or tends to go for one-man heroic effort, the best thing you can do for your team, and probably for that person as well, is to let him/her go very quickly.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=RgOtO"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=RgOtO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=FPMfo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=FPMfo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=pH3Eo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=pH3Eo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/on-interviewing-beyond-technical-competence.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/on-interviewing-beyond-technical-competence.html</feedburner:origLink></item>
		<item>
		<title>Unit testing the data access layer</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/163231312/unit-testing-the-data-access-layer.html</link>
		<comments>http://www.buunguyen.net/blog/unit-testing-the-data-access-layer.html#comments</comments>
		<pubDate>Sun, 30 Sep 2007 10:32:10 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[OOAD]]></category>

		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[Technologies]]></category>

		<category><![CDATA[dao]]></category>

		<category><![CDATA[design patterns]]></category>

		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/unit-testing-the-data-access-layer.html</guid>
		<description><![CDATA[Unit testing can be difficult sometimes.  In some cases, you need to refactor your code-under-test to make it more testable; in other cases, you need to apply some special techniques into your test code so that it can do what you want; and in the worst cases, you can&#8217;t think of any such techniques [...]]]></description>
			<content:encoded><![CDATA[<p>Unit testing can be difficult sometimes.  In some cases, you need to refactor your code-under-test to make it more testable; in other cases, you need to apply some special techniques into your test code so that it can do what you want; and in the worst cases, you can&#8217;t think of any such techniques nor are able to refactor the production code and thus, don&#8217;t write any test at all.  It&#8217;s in my experience working with many teams applying unit testing that they often have troubles writing tests for the data access layer (DAL), UI layer, service interface layer, and multi-threading code, mostly because they are not aware of the techniques for doing that.  That is not surprisingly difficult to understand though, business logic is much more intuitive and straight-forward to be tested and every single article or book out there will have examples writing test for the business logic firstly.</p>
<p>In this blog entry, I will explore some techniques of testing the data access layer.  While it won&#8217;t be very comprehensive (I think an entire book can be written just to explore in details all facets of database unit testing), I hope there is enough of topics covered for you to explore more.<span id="more-199"></span></p>
<p><br/><br />
<strong>But first, what is DAL?</strong><br />
Everyone has his or her own idea of what DAL is, but for this entry, I will stick with the following definition: DAL is a software module which encapsulates data access logic and publishes interfaces for other software module to interact with the underlying data source(s) at a high-level of abstraction (programming language objects and attributes) instead of data source&#8217;s concepts like row, columns, tables etc.  </p>
<p>There are many ways of implementing DAL, including Active Record pattern, Data Mapper (or DAO) pattern etc. (see more in [1]), and while the techniques described in this entry will apply to all DAL implementations, the examples assume an implementation of the Data Mapper pattern because this is arguably the most frequently used data access pattern in the Java and .NET spaces.</p>
<p><br/><br />
<strong>What to test</strong><br />
Before writing any tests for the DAL, we should consider the following things:</p>
<ul>
<li>Do we want to hit the database at all or should we mock out the database communication API?  </li>
<li>If we have to hit the database, do we want to hit the real production version of the database or do we want to hit an in-memory lightweight database?</li>
</ul>
<p>Some people advocate against writing unit tests which hit the database [2] because: </p>
<ul>
<li>A test is not really unit test if it depends on the data logic of the application, the behaviors of the database system and the underlying communication API (JDBC or ADO.NET).  (That&#8217;s too much for a <em>unit </em>test.)</li>
<li>Hitting the database slows down the test running life cycle and thus is not recommended.</li>
</ul>
<p>According to this camp, in order to test the DAL, we should mock out the interaction with the real database system and only aim to test how the data access class responds to the caller and interacts with the database communication API like ADO.NET or JDBC regardless of how the database system really behaves.  Before discussing on whether this is a good idea or not, let&#8217;s look at the some code.  (Note: To run this code, you need to have the EasyMock library [3].)  We basically have a DAO class, JdbcPersonDaoImpl, publishing an interface to persist objects of type Person and using JDBC to communicate with the database system.  Our test class, JdbcPersonDaoImplTest, will verify whether the DAO class interact properly with JDBC.</p>
<p><br/></p>
<pre name="code" class="java">public class JdbcPersonDaoImpl implements PersonDao {

	private DataSource dataSource;

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public int insert(Person person) {
		try {
			Connection conn = dataSource.getConnection();
			String sql = "INSERT INTO people VALUES (?, ?)";

			// Creates a statement and asks it to return generated Ids
			PreparedStatement stmt = conn.prepareStatement(sql,
				Statement.RETURN_GENERATED_KEYS);
			stmt.setString(1, person.getName());
			stmt.setInt(2, person.getAge());

			// Executes the statement and retrieve the generated Id
			stmt.executeUpdate();
			ResultSet rs = stmt.getGeneratedKeys();
			int personId = rs.getBigDecimal(1).intValue();

			rs.close();
			stmt.close();
			conn.close();
			return personId;
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
}</pre>
<p><br/></p>
<pre name="code" class="java">public class JdbcPersonDaoImplTest {

	@Test public void testInsertOnePerson() throws Exception {
		final int expectedId = 100;
		final Person person = new Person("John Doe", 30);
		final String sql = "INSERT INTO people (name, age) VALUES (?, ?)";

		// Creates a bunch of mock objects
		DataSource dataSource = createMock(DataSource.class);
		Connection connection = createMock(Connection.class);
		PreparedStatement stmt = createMock(PreparedStatement.class);
		ResultSet rs = createMock(ResultSet.class);

		// Sets expectations
		expect(dataSource.getConnection()).andReturn(connection);
		expect(connection.prepareStatement(sql,
			Statement.RETURN_GENERATED_KEYS)).andReturn(stmt);
		stmt.setString(1, person.getName());
		stmt.setInt(2, person.getAge());

		// Sets expectations
		stmt.executeUpdate());
		expect(stmt.getGeneratedKeys()).andReturn(rs);
		expect(rs.getBigDecimal(1)).andReturn(expectedId);
		rs.close();
		stmt.close();
		connection.close();

		// Turns to "action" mode
		replay(dataSource, connection, stmt, rs);

		// Creates the test fixture and feeds it the mock data source
		PersonDao dao = new JdbcPersonDaoImpl();
		dao.setDataSource(dataSource);

		// Executes and verifies results
		int personId = dao.insert(person);
		assertEquals(expectedId, personId);
		verify(dataSource, connection, stmt, rs);
	}
}</pre>
<p>How&#8217;s that?  The test code is way too complex compared with the production code and yet, the only thing it does is assuring that the production code interacts with the JDBC API properly.  (And if you try to write test for a search operation which returns large result set, it is much worse.)  I don&#8217;t think it is fun nor worth the effort.  The complexity of the data layer has little to do with the interaction with the database communication API, but rather with the database schema and the SQL statements or stored procedures executed as part of an interaction (and if you use an <a href="http://www.buunguyen.net/blog/the-legend-of-data-persistence-part-1.html">ORM framework</a> like Hibernate, the complexity of the mapping rules adds up to that matter).  </p>
<p>In fact, I&#8217;d rather let my tests hit the real database for the SQL or stored procedures to be executed, or I would not write any test at all.  (Of course, you can combine both testing the interactions and testing the real database modification, but as I said, the interaction part is too simple to be wrong while costing so much code.)  Those in the real-unit-test-does-not-touch-database camp may refer to this as &#8216;integration&#8217; test, not unit test, but as long as my test cases are reliable, independent, repeatable, automated, and <i>fast</i> (enough), I don&#8217;t care much about the terminology.  </p>
<p><br/><br />
<strong>The in-memory database</strong><br />
To have your tests run fast, you might not want to test against your production database systems (like Oracle or MS SQL Server).  Instead, you may consider an in-memory lightweight database like HSQLDB [4] or Derby [5] (see [6] for a list of in-memory databases).  The nice thing about these two databases is that they have both JDBC and Hibernate support, thus it may not take a lot of effort to run your production code against these databases.  (That&#8217;s not 100% certain though and it depends on what your production database is.  You&#8217;d better check out the documentation of these databases.)  There are a few other things you should consider when choosing this approach:</p>
<ul>
<li>You must make sure your schema is compatible between the test and production database.  You will not want to maintain two separate sets of SQL script files.  (DRY, everyone.)</li>
<li>You should have your tests populate the test database&#8217; schema on the fly to assure the automation and repeatability characteristics of good tests.</li>
</ul>
<p>The good news is that a tool like Hibernate can populate the database schema automatically and on the fly based on the mapping files.  The bad news is that sometimes you have to modify the default Hibernate configuration settings to make sure that the generated schema is compatible with your production database&#8217; schema, otherwise, you may run into problems upon deployment.</p>
<p>If you use Hibernate, then testing against the in-memory database can be as simple as creating a Hibernate configuration file and a simple DAO test class which basically invokes the DAO&#8217;s interface and verifies the results (much less simpler compared to our mock-based version) like below:</p>
<pre name="code" class="xml">hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url jdbc:hsqldb:testdb/hsqldb
hibernate.connection.username=sa
hibernate.connection.password=forgetit
hibernate.hbm2ddl.auto=create-drop</pre>
<p><br/></p>
<pre name="code" class="java">@Test public void testFindAllPeople()
		throws Exception {
	// Prepares the test data
	List&lt;Person&gt; peopleList = new ArrayList&lt;Person&gt;();
	peopleList.add(new Person(&quot;John Doe&quot;, 30));
	peopleList.add(new Person(&quot;Jane Doe&quot;, 28));

	// Populates the database and flushes
	Session session = HibernateUtil.getSessionFactory().getCurrentSession();
	for (Person p : peopleList) {
		session.save(p);
	}
	session.flush();

	// Verifies the result
	PersonDao dao = new JdbcPersonDaoImpl();
	dao.setDatasource(dataSource);
	assertEquals(peopleList, dao.findAll());
}</pre>
<p><br/><br />
<strong>The real database</strong><br />
If speed is not a big deal to you and you do not want to mess with another database and get into the compatibility headache, you can always go directly to your production database system.  In that case, keep in mind a few things:</p>
<ul>
<li>Each developer should have her own database server on her development machine to avoid messing up with other developers&#8217; tests.</li>
<li>If software license is a problem, create a separate database instance for each developer.</li>
<li>Separate the DAL test into its own suite so that you can test it as you like and don&#8217;t touch it if you are not changing any data-related stuff (DAL code, SQL, stored procedures, database schema etc.)  You don&#8217;t want the possibly time-consuming unit testing process of the DAL to occur while the only thing you change is a piece of application logic.</li>
</ul>
<p>Another thing you should consider whenever your tests hit the database, be it in-memory or production database, is that your tests must start the running with a known database state.  In other words, either clean up everything before or after a test run and make sure the same data is populated in advance if necessary.  And for data population purpose, consider a tool like DbUnit [7].</p>
<p><br/><br />
<strong>So, you ask &#8220;which techniques should I use?&#8221;</strong><br />
I think that it is not worth testing the interaction with the database communication API using mock objects if the interaction is simple (most of the time, it is simple).  On the other hand, I would rather pick the test for the real production database system rather than an in-memory database to maximize the reliability of the tests while staying away from the compatibility issues.  Besides, there are a few practices, as described above, to alleviate the performance and repeatability problems of hitting the real database.  But of course, that&#8217;s my choice given the kinds of applications I&#8217;m doing.  You need to pick the techniques that work best in your environment.  And I hope I have given enough introduction for you to explore more and make you call.</p>
<p><br/><br />
<strong>References</strong><br />
[1]: Patterns of Enterprise Application Architecture, Martin Fowler, Addison-Wesley, 2002<br />
[2]: <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=126923">http://www.artima.com/weblogs/viewpost.jsp?thread=126923</a><br />
[3]: <a href="http://www.easymock.org">http://www.easymock.org</a><br />
[4]: <a href="http://hsqldb.org">http://hsqldb.org</a><br />
[5]: <a href="http://db.apache.org/derby">http://db.apache.org/derby</a><br />
[6]: <a href="http://en.wikipedia.org/wiki/In-memory_database">http://en.wikipedia.org/wiki/In-memory_database</a><br />
[7]: <a href="http://dbunit.sourceforge.net">http://dbunit.sourceforge.net</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=IUXKO"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=IUXKO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=zF5oo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=zF5oo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=S5TUo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=S5TUo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/unit-testing-the-data-access-layer.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/unit-testing-the-data-access-layer.html</feedburner:origLink></item>
		<item>
		<title>I am a dVP</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/158607749/i-am-a-dvp.html</link>
		<comments>http://www.buunguyen.net/blog/i-am-a-dvp.html#comments</comments>
		<pubDate>Wed, 19 Sep 2007 16:20:23 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[Technologies]]></category>

		<category><![CDATA[awards]]></category>

		<category><![CDATA[db4o]]></category>

		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/i-am-a-dvp.html</guid>
		<description><![CDATA[I have just been recognized as a db4o Most Valued Professional (dVP) for the year 2008 and won a trip to Berlin next year to attend the ICOODB 2008 conference.  It has always been a pleasure working with a great product like db4o and I surely enjoy this award.  
BTW, to those who [...]]]></description>
			<content:encoded><![CDATA[<p>I have just been recognized as a <a href="http://db4o.com/community/professionals/dVP/">db4<a href="http://www.buunguyen.net/blog/object-oriented-database-programming-with-db4o-part-1.html">o Most Valued Professional</a> (dVP) for the <a href="http://db4o.com/community/professionals/dVP/directory2008.aspx">year 2008</a> and won a trip to Berlin next year to attend the <a href="http://odbmsjournal.org/icoodb/index.html">ICOODB 2008 conference</a>.  It has always been a pleasure working with a great product like <a href="http://www.codeproject.com/useritems/OOP_with_db4o.asp">db4o</a> and I surely enjoy this award.  </p>
<p>BTW, to those who are expecting to see part 2 of my <a href="http://www.buunguyen.net/blog/object-oriented-database-programming-with-db4o-part-1.html">db4o article</a>, I am a bit overwhelmed with other stuffs lately and could not have time to start working on it; but I&#8217;ll surely do that as soon as I can.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=335ZO"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=335ZO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=mrITo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=mrITo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=Ehkno"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=Ehkno" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/i-am-a-dvp.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/i-am-a-dvp.html</feedburner:origLink></item>
		<item>
		<title>Microsoft Tech·Ed SEA 2007</title>
		<link>http://feeds.feedburner.com/~r/BuuNguyensBlog/~3/152537628/microsoft-tech%c2%b7ed-sea-2007.html</link>
		<comments>http://www.buunguyen.net/blog/microsoft-tech%c2%b7ed-sea-2007.html#comments</comments>
		<pubDate>Wed, 05 Sep 2007 14:58:47 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[events]]></category>

		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[teched]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/microsoft-tech%c2%b7ed-sea-2007.html</guid>
		<description><![CDATA[I will be attending the Microsoft Tech·Ed SEA 2007 event at Malaysia from Sept 10-13.  According to the website&#8217;s statistic, not a lot of my blog&#8217;s readers come from the South East Asia area; but if any of you will attend this event, send me message to my email address (see About Me), we [...]]]></description>
			<content:encoded><![CDATA[<p>I will be attending the <a href="http://www.microsoft.com/malaysia/techedsea2007/">Microsoft Tech·Ed SEA 2007 event</a> at Malaysia from Sept 10-13.  According to the website&#8217;s statistic, not a lot of my blog&#8217;s readers come from the South East Asia area; but if any of you will attend this event, send me message to my email address (see <a href="http://www.buunguyen.net/blog/about/">About Me</a>), we might meet over there.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=TO4qO"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=TO4qO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=RqsDo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=RqsDo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BuuNguyensBlog?a=KyXSo"><img src="http://feeds.feedburner.com/~f/BuuNguyensBlog?i=KyXSo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/microsoft-tech%c2%b7ed-sea-2007.html/feed</wfw:commentRss>
		<feedburner:origLink>http://www.buunguyen.net/blog/microsoft-tech%c2%b7ed-sea-2007.html</feedburner:origLink></item>
	</channel>
</rss>
