Sunday, May 11, 2014

Decompose and Win!

Section 1.2 of the CSharp Language Specification document for C# 5.0 (which is associated with .NET 4.5) covers the basics of Programs, Namespaces, Types, Members, and Assemblies and how we can use them to decompose our problems into consumable cognitive chunks.  By decomposing a large problem into a series of smaller ones using the tooling available in C#, we are able to write more readable code.  In our initial Hello World program, we included functionality from the System namespace (though I didn't call out explicitly that this is what we were doing) to get the Console.WriteLine() function.  With this example we are building a library and then using that library to perform some actions.  The library is in its own namespace, which we include while compiling the source code which links it into the executable.  For this one we aren't going to explore compilers or languages, instead we will explore tools.  I compiled both source files within the same project in Visual Studio to produce a single executable.  I have reverse engineered the code using both JustDecompile from Telerik:

and ILDasm from Microsoft:

They both show similar tree structures which display the encapsulation of the functionality.  Notice how the Stack object originates from a different namespace than the Test object.  This structure allows us to build up functionality libraries, test them in isolation, and include them within larger works.

No comments:

Post a Comment