<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Programatique's Blog</title>
	<atom:link href="http://programatique.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://programatique.wordpress.com</link>
	<description>&#60;html&#62; and everything in between.</description>
	<lastBuildDate>Thu, 21 Jan 2010 14:15:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='programatique.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Programatique's Blog</title>
		<link>http://programatique.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://programatique.wordpress.com/osd.xml" title="Programatique&#039;s Blog" />
	<atom:link rel='hub' href='http://programatique.wordpress.com/?pushpress=hub'/>
		<item>
		<title>ASP.NET Postback Control Lost When Button is Disabled via JavaScript</title>
		<link>http://programatique.wordpress.com/2010/01/21/asp-net-postback-control-lost/</link>
		<comments>http://programatique.wordpress.com/2010/01/21/asp-net-postback-control-lost/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 14:10:51 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[postback]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=116</guid>
		<description><![CDATA[You know those bugs that frustrate you to no end, resulting in some screaming, hair-pulling, etc? I had one of those a few days ago. For some reason data on the form I was working on stopped saving. I had no idea why. The code was all there. The server-side code hadn&#8217;t changed. I checked [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=116&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You know those bugs that frustrate you to no end, resulting in some screaming, hair-pulling, etc? I had one of those a few days ago. For some reason data on the form I was working on stopped saving. I had no idea why. The code was all there. The server-side code hadn&#8217;t changed. I checked and re-checked everything (so I thought). I even deleted the aspx and aspx.vb files and recreated them. Finally I realized that for some reason my client-side disabling of a button after-click was doing some weird things on poastback.</p>
<p>Here&#8217;s what I figured out. On my site, I want to disable a button once it is clicked to prevent multiple posts. So I disable the button on the click utilizing jQuery. However when I do this, the postback occurs but the control that triggered the postback is lost on the server. The server-side code handling that button click does not fire at all. When I check Page.IsPostBackEventControlRegistered, it returns false.</p>
<p>When I attempt to just hide the control on click, the postback details are not lost. However, I would prefer not to do this since it results in layout jitter. Adding in a faux-button span or something like that is possible, but a bit hokey. Disabling the button on click is the most straightforward method to prevent multiple postbacks from the client. I haven&#8217;t checked if this issue is caused by jQuery though I doubt it, and think that simply disabling the button in JavaScript is the issue.</p>
<p>Anyone have a similar issue with button disabling?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=116&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2010/01/21/asp-net-postback-control-lost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>Code Metrics for Visual Studio</title>
		<link>http://programatique.wordpress.com/2009/09/08/code-metrics-for-visual-studio/</link>
		<comments>http://programatique.wordpress.com/2009/09/08/code-metrics-for-visual-studio/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 19:25:31 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code metrics]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[visual basic]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=108</guid>
		<description><![CDATA[Have you ever run Code Metrics in Visual Studio (2008)? When I first ran it, I got a plethora of numbers back for Cyclomatic Complexity, Class Couping, etc. I had no idea what most of these measures meant, so I&#8217;ve been going about finding out what each defines. The results have helped me find areas [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=108&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have you ever run Code Metrics in Visual Studio (2008)? When I first ran it, I got a plethora of numbers back for Cyclomatic Complexity, Class Couping, etc. I had no idea what most of these measures meant, so I&#8217;ve been going about finding out what each defines. The results have helped me find areas of code that need extra attention.</p>
<p><strong>Maintainability Index</strong></p>
<p>Is a summary measure of the other items in VS&#8217;s Code Metrics. The higher the number the better. I&#8217;ve read that you want to put some work into any code getting a score of 65 and lower to 80 and lower. Interestingly enough the worst &#8220;maintainability&#8221; components in my solutions are the auto-generated code for Windows Forms.</p>
<p><strong>Cyclomatic Complexity</strong></p>
<p>This measures how many &#8220;paths&#8221; your code contains. If you have a simple program with no conditions and no looping, you would have a CC of 1. The algorithm for determining complexity involves creating a node-based diagram and counting pathways and nodes. It can be also be determined by simply counting up each &#8220;if&#8221;, &#8220;else&#8221;, &#8220;for&#8221;, &#8220;while&#8221;, and &#8220;case&#8221; in a routine and adding 1. Generally for each member of a class you do not want complexity to exceed 10 or possibly 15. If you get extremely high complexity numbers you can see why you might want to check out that particular method, as it is probably not as easy to understand and maintain as other code.</p>
<p>Lowering the complexity of code involves refactoring. You may be doing several tasks in a single routine that you want to abstract out to another process. This would create another method in your code, but will allow for increased readibility and maintainability.</p>
<p><strong>Depth of Inheritance</strong></p>
<p>In .NET this is basically how many degrees the class lies away from it&#8217;s most basic ancestor class. For most classes this will be relative to System.Object. Interfaces can receive a DOI of 0.</p>
<p><strong>Class Coupling</strong></p>
<p>This is the number of classes the particular class in question is dependant on. The less dependency the less liable the code is to breaking.</p>
<p><strong>Conclusion<br />
</strong></p>
<p>There is also &#8220;lines of code&#8221; which is fairly self explanatory. In conclusion there is a healthy amount of criticism against code metrics &#8211; since it is an objective measure of code. However, if used with context in mind, I think these metrics can definitely help you find highly complex and unmaintainable chunks of code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=108&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/09/08/code-metrics-for-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>simple querystring code for javascript</title>
		<link>http://programatique.wordpress.com/2009/07/23/javascript-querystring/</link>
		<comments>http://programatique.wordpress.com/2009/07/23/javascript-querystring/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 14:17:38 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[querystring]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=98</guid>
		<description><![CDATA[I created a simple procedure awhile ago to easily access querystring parameters, similar to how they can be accessed in ASP.NET. //QUERYSTRING document.queryStringValues = new Array() document.queryString = function(key){ var itemValue if(document.queryStringValues.length == 0){ var i, itemKey, itemPair //load querystring var strSearch = location.search.substring(1, location.search.length) var qsItems = strSearch.split('&#38;') //set length document.queryStringValues.length = qsItems.length for(i [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=98&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I created a simple procedure awhile ago to easily access querystring parameters, similar to how they can be accessed in ASP.NET.</p>
<pre>//QUERYSTRING
document.queryStringValues = new Array()
document.queryString = function(key){
	var itemValue

	if(document.queryStringValues.length == 0){
                var i, itemKey, itemPair

		//load querystring
		var strSearch = location.search.substring(1, location.search.length)
		var qsItems = strSearch.split('&amp;')

		//set length
		document.queryStringValues.length = qsItems.length

		for(i = 0; i &lt; qsItems.length; i++){
			itemPair = qsItems[i].split('=')
			itemKey = itemPair[0]
			if(itemPair.length == 2){
				itemValue = itemPair[1]
				document.queryStringValues[itemKey] = itemValue
			}
			else{
				document.queryStringValues[itemKey] = null
			}
		}
	}

	itemValue = document.queryStringValues[key]

	return itemValue
}</pre>
<p>The code creates a queryStringValues array under &#8220;document&#8221; to hold the values of the querystring &#8211; which is accessed by the key value. The actual functionality comes through calling &#8220;document.queryString(&#8216;somekey&#8217;)&#8221;. This procedure checks to see if queryStringValues has been loaded. If not the array is loaded up. Then the code checks queryStringValues to find the value based on the key given. If the value is not found a null value is returned.</p>
<p>I allow the queryStringValues to be loaded only the first time the document.queryString so that if it&#8217;s unneeded no extra processing/memory is used up. I could add onto this code by adding a variable called &#8220;hasLoaded&#8221; to the queryStringValues array, so that if the URL querystring has no values, the array will not keep trying to load everytime the procedure is called.</p>
<p>In the end, you have an easy way to retrieve queryString members by calling something like this:</p>
<pre>var userName = document.queryString('username')</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=98&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/07/23/javascript-querystring/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;core&#8221; javascript file (part 1) &#8211; string trimming</title>
		<link>http://programatique.wordpress.com/2009/07/16/core-javascript-file-part-1-string-trimming/</link>
		<comments>http://programatique.wordpress.com/2009/07/16/core-javascript-file-part-1-string-trimming/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 18:28:36 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=91</guid>
		<description><![CDATA[I was tweeting a bit about a few simple string trimming functions. I thought it might be interesting to flesh that out a bit and also start a short blog series on what I have in my &#8220;core&#8221; javascript file. Basically this core file, or library &#8211; if you want to stretch it &#8211; contains [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=91&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was tweeting a bit about a few simple string trimming functions. I thought it might be interesting to flesh that out a bit and also start a short blog series on what I have in my &#8220;core&#8221; javascript file. Basically this core file, or library &#8211; if you want to stretch it &#8211; contains simple utility functions that make the rest of my javascript programming simple. A lot of these functions will probably be handled if you use a mature 3rd party library like YUI or jQuery. Even so, it&#8217;s good to understand how some of these functions work. Also some of the code in &#8220;core&#8221; library contains functionality that is not in the feature set of these external libraries. I&#8217;ll start off with the trim() function, and go through other aspect of my &#8220;core&#8221; file in subsuquent posts.</p>
<p>The &#8220;core&#8221; file starts with a pseudo-namespace creation &#8211; the namespace being &#8220;core&#8221;:</p>
<pre>core = new Object()</pre>
<p>The trim function allows you to strip leading or following whitespace from a string. It&#8217;s often found in most programming languages. I find myself using it almost always when manipulating strings in compiled code.</p>
<pre>core.trim = function(text){
	return text.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}
String.prototype.trim = function(){
	return core.trim(this)
}</pre>
<p>The first block defines a standalone trim function. Using regular expressions it replaces out whitespace characters. We can expand upon the native String object to add-on a trim function. This ability to add-on methods to native objects really shows some of flexibility and power of javascript. This allows us to modify the String object so that any string that is created heretofore has the trim() method available to it.</p>
<p>You can now take an input from a textbox and trim any outside whitespace like so:</p>
<pre>var firstName = document.getElementById('txtFirstName').value
document.write(firstName.trim())</pre>
<p>This simplifies trimming across the board for all strings.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=91&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/07/16/core-javascript-file-part-1-string-trimming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>coding as an art form</title>
		<link>http://programatique.wordpress.com/2009/07/15/coding-as-an-art-form/</link>
		<comments>http://programatique.wordpress.com/2009/07/15/coding-as-an-art-form/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 14:55:24 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[art]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[creativity]]></category>
		<category><![CDATA[musings]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=84</guid>
		<description><![CDATA[Two of my most time-consuming passions are coding and songwriting. (Yes I was once the frontman of a small alt rock detail &#8211; I assure you that you&#8217;ve never heard of us). Maybe because of that i find a lot of parellels between the two &#8211; especially between crafting lyrics and building code. As much [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=84&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Two of my most time-consuming passions are coding and songwriting. (Yes I was once the frontman of a small alt rock detail &#8211; I assure you that you&#8217;ve never heard of us). Maybe because of that i find a lot of parellels between the two &#8211; especially between crafting lyrics and building code.</p>
<p>As much as we call it computer science &#8211; and there is much science to it &#8211; programming shares much with poetry &#8211; and I mean that literally, not in a fancy poetic way. Both have a (generally) limited set of words to use. You put all those words (or keywords) together to produce a larger meaning. The devil is in the details. As a perfectionistic lyricist it&#8217;s easy to generally convey an idea, but I would often tweak each word of a line until I felt they expressed exactly what I desired. The same occurs with code &#8211; where the same function can be coded thousands of different ways &#8211; yet we each strive for our own &#8220;perfect&#8221; permutation of code.</p>
<p>In my short coding experience &#8211; this has led me to the conclusion that coding is in many ways an art form. And I thoroughly enjoy that. It&#8217;s not just functionality. It&#8217;s creativity. Increasing vocubulary (keywords) and really understanding the grammar (syntax) of the coding language will not just allow for more efficient code, but more beautiful code. In many ways efficiency and beauty work together in code. When you come across a succinct powerful set of code &#8211; it&#8217;s pleasing to the eye; not to mention how an application that &#8220;just works&#8221; is pleasing to users.</p>
<p>You may this is a load of bull, that&#8217;s ok. It is a bit cheesy. Still I think everyone takes value in creating something pleasing. Create something beautiful with your code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=84&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/07/15/coding-as-an-art-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>Dear Mr. or Ms. Programmer</title>
		<link>http://programatique.wordpress.com/2009/06/22/dear-mr-programmer/</link>
		<comments>http://programatique.wordpress.com/2009/06/22/dear-mr-programmer/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 20:56:25 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[visual basic]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=71</guid>
		<description><![CDATA[My previous job entailed me rewriting tens of thousands of lines of code. There were probably a handful of comments. And that was just one of the massive issues with the code. For example Intellisense wouldn&#8217;t even work because of the overflow of unneeded references in the project. One of the guys that wrote the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=71&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My previous job entailed me rewriting tens of thousands of lines of code. There were probably a <em>handful</em> of comments. And that was just one of the massive issues with the code. For example Intellisense wouldn&#8217;t even work because of the overflow of unneeded references in the project. One of the guys that wrote the code sat across from me. I used to utter expletives under my breath all day long while giving him the stink eye. (I&#8217;m passive aggresive if you can&#8217;t tell) That said, I&#8217;ve become acutely sensitive to what makes for bad code &#8211; and possibly what might make for some good code. I humbly submit a few points highlighted below &#8211; every point kind of relates to another though.</p>
<p>You&#8217;re still here? I guess I should get started then..</p>
<p><strong>1 Be a Thoughtful Programmer</strong><br />
Yes. Thoughtful. As in, bring your wife roses on your anniversary. Hold the elevator for others. Don&#8217;t hog the ball when playing hoops. That kind of thoughtful. When you code, you can&#8217;t code for yourself. Even if you&#8217;re tasked an assignment that only you will work on. One day, even if it&#8217;s years from now, someone else will most likely have to look at your code. This isn&#8217;t just some flowery hippie talk. If you take other people&#8217;s views into mind, you will become a better programmer.</p>
<p>In English class we called this &#8220;Audience-Centered Writing&#8221;. Writing while taking the readers point of view. You take into consideration how your program is structured. Does it make sense to someone else looking at it? You examine how you name your variables. What name would most easily make sense to the most people? You take into consideration if your code produces massive amounts of warnings in the compiler. Maybe I don&#8217;t want other programmers bogged down with my warnings? And so on. If you follow this simple rule, your code will most likely be cleaner, more organized, and hopefully more efficient. &#8220;Audience-Centered Writing&#8221;. It actually makes sense when writing code too.</p>
<p>For the sake of all that&#8217;s good in the world, COMMENT. Frankly, if you don&#8217;t comment your code, you&#8217;re being a jerk. I don&#8217;t mean over-comment, I mean if you have 2 comments for 10,000 lines of code, I will not like you (and neither will your coworkers).</p>
<p><strong>2 Be Humble</strong><br />
There are a thousand ways to code the simplest action. When you code something, know that it can be better. If you&#8217;re that cocky, just pretend. Pretend that maybe you aren&#8217;t the world&#8217;s greatest programmer. How can this code be more efficient? How can it be more readable? This leads to coding and re-coding. Each revision should make your code better. On the other end, be a perfectionist within reason. Be an artist. Know that you want the code to be <em>really </em>good. But not perfect. Because there is so much flexibility in coding even the smallest tasks &#8211; it is more like an art, not a mathematical formula. Make it beautiful and move on.</p>
<p>Related to this is following best practices. Believe it or not, you probably don&#8217;t know more about the .NET framework than the people that created it. I know some of you really hate that idea. But it&#8217;s a whole freakin&#8217; <em>team </em>of highly-paid highly-experienced doctorates. Trust me, I had a class with a professor who was actually helping to form .NET back in the day. He was a smart guy. And he worked with a bunch of smart guys. Follow their advice. If you&#8217;re a .NET programmer, it might be a good idea to follow the Best Practice guides that Microsoft publishes. If nothing else, at least your code will be more readible since more people follow Microsoft&#8217;s Best Practices than Joe Schmoe Programmers best practices.</p>
<p>If you&#8217;re doing JavaScript work, there are tons of articles on best practices online. There are differing points on specifics (including some bad advice), but try to find where there is consensus and (hopefully) that should be a good starting point.</p>
<p><strong>3 Know your Stuff</strong><br />
The subtitle for this should be &#8220;good programming practice over hyped-up new stuff&#8221;. Before you read up on YUI, read up on CSS. Before you read up on Entity Framework learn how to use inheritance. Sounds simple but in my experience the exact opposite occurs. What makes for a good coder is not knowing the latest in WPF, WCF, and whatever other fancy new acronym you can think of. Good programming is all about fundamentals. Is your code organized? Is your logic sound? Do you have a firm grasp of the language essentials? It amazes me how many .NET Developers talk about Workflow, but don&#8217;t know the first thing about the CollectionBase class or coding interfaces. Similarly how a web developer can tout jQuery, yet still use tables for web page layout. Know your stuff. If you really want to be a good programmer, learn <em>and utilize</em> the fundamentals of what you are coding.</p>
<p>The other stuff &#8211; new technologies &#8211; should come easy after that. In fact you will have a deeper and much more mature understanding of newer technologies/API&#8217;s/etc if you understand the basics of your coding environment. Now I&#8217;m not saying I know all my stuff.. but I&#8217;m (hopefully) on the path to getting all that core knowledge down as well as gradually picking up on 3rd party libraries, fancy features, and the likes.</p>
<p><strong>Conclusion</strong><br />
To sum it all up: know your fundamentals, include others&#8217; point of view, and don&#8217;t be a jerk.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=71&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/06/22/dear-mr-programmer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Cross-thread operation not valid&#8221; &#8211; Multi-Threading in Windows Forms For VB Beginners (Part 1 of 2)</title>
		<link>http://programatique.wordpress.com/2009/06/10/multi-threading-in-vb-net-1/</link>
		<comments>http://programatique.wordpress.com/2009/06/10/multi-threading-in-vb-net-1/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 12:57:34 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apartment model]]></category>
		<category><![CDATA[backgroundworker]]></category>
		<category><![CDATA[multi-threading]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[visual basic]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=59</guid>
		<description><![CDATA[So you want to have a long-running process not freeze up your UI while it runs? This is a common desire of programmers and one which can be resolved with multi-threading. One of the most misunderstood/unknown features of the .NET framework is how multi-threading in a Windows Form project works. I&#8217;ve seen various pieces of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=59&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So you want to have a long-running process not freeze up your UI while it runs? This is a common desire of programmers and one which can be resolved with multi-threading. One of the most misunderstood/unknown features of the .NET framework is how multi-threading in a Windows Form project works.</p>
<p>I&#8217;ve seen various pieces of code that attempts multi-threading; but fails because basic concepts are not understood. Or heard complaints that multi-threaded code &#8220;only runs when not in debug mode&#8221;; or that it &#8220;fails randomly for no reason&#8221;. This is because the debugger will usually not allow cross-thread interaction of form controls. And because when you force that to happen you will get intermittent errors. These explanations are explained further in the following paragraphs. Working with threads is an advanced and complex task &#8211; when not accounting for what is called &#8220;thread safety&#8221; a lot of things can go wrong.</p>
<p><strong>The Apartment Model<br />
</strong>The basic idea new multi-thread programmers should familiarize themselves with is the Apartment Model. This is how the .NET framework deals with objects and threads. The analogy is fairly simple. A thread represents an apartment (yes, the kind people live in). Any object created in that thread, lives inside that thread. Each object is unaware of what is happening in other threads.</p>
<p>Hence a particular thread, let&#8217;s call it ThisThread has created a ProgressBar object. You manually create another thread in code (let&#8217;s say it called OtherThread). OtherThread is tasked with running a long process and you want OtherThread to update the ProgressBar once a step in this process is complete. Bad idea. You cant just have some random stranger walking into someone else&#8217;s house and telling them what to do. Same goes here. Darn apartments.</p>
<p><strong>The Dreaded Debugger Message<br />
</strong>If you try it, you will most likely end up with this message in the debugger:</p>
<pre>Cross-thread operation not valid:
Control 'ProgressBar1' accessed from a thread
other than the thread it was created on.</pre>
<p>Uh oh. So how do we ever get that ProgressBar to update? We have to pass the information back to the normal application flow so that the thread that created the ProgressBar can update it. So the task at hand is actually inter-thread communication. Luckily the folks at Microsoft has created a component to ease this entire issue. Enter the BackgroundWorker. This component is available from .NET Framework version 2.0. I will be speaking from experience using it in .NET Framework 3.5 (Visual Studio 2008)</p>
<p><strong>Introducing the BackgroundWorker<br />
</strong>The BackgroundWorker is a Windows Form component, meaning it should show up in the toolbox. You can simply drag and drop it into your form to have the functionality of the BackgroundWorker for that form.</p>
<p>The BackgroundWorker has 3 events that can be handled just like you do for other Windows Forms objects. These events are &#8220;DoWork&#8221;, &#8220;ProgressChanged&#8221; and &#8220;RunWorkerCompleted&#8221;. DoWork defines exactly what code should execute in the background. ProgressChanged defines how to report progress that is passed to the BackgroundWorker (if WorkerReportsProgress = True). RunWorkerCompleted allows for the coder to clean up after the process is complete and also to check the outcome of the process (if it was successful, an error occurred, or was cancelled)</p>
<p>There are two key properties that you want to consider when you add a BackgroundWorker. First is &#8220;WorkerReportsProgress&#8221;; second is &#8220;WorkerSupportsCancellation&#8221;. If you want to update that ProgressBar after each step, you want to set this to true. Otherwise if you have a process, but don&#8217;t need step-by-step updates on progress, set this to false. If the Worker should be able to cancel midway through processing you should set &#8220;WorkerSupportsCancellation&#8221; to true.</p>
<p>I hope to go further into how to exactly utilize the BackgroundWorker and certain considerations you may want to weigh for whatever process is run by the BackgroundWorker in my next post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=59&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/06/10/multi-threading-in-vb-net-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>VB beginnier’s guide to n-tiered programming (part 4) – bringing layers/projects all together</title>
		<link>http://programatique.wordpress.com/2009/06/09/n-tiered-project-linkag/</link>
		<comments>http://programatique.wordpress.com/2009/06/09/n-tiered-project-linkag/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 20:21:18 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3-tier]]></category>
		<category><![CDATA[n-tiered]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[visual basic]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=57</guid>
		<description><![CDATA[So we have all these layers within our application. How do fit all of them together together in a Visual Studio Solution? This might be a simple question, but one that may be tough to find a direct or simple answer to. I&#8217;m going to try to do that now as well as clarify some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=57&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So we have all these layers within our application. How do fit all of them together together in a Visual Studio Solution? This might be a simple question, but one that may be tough to find a direct or simple answer to. I&#8217;m going to try to do that now as well as clarify some simple details that might be overlooked for new VB coders creating an n-tier solution.</p>
<p>So let&#8217;s say you have a 3-tiered application for a Cashier app with the following projects (each project representing a layer):</p>
<ul>
<li>CashierDataService (Data Access Layer code)</li>
<li>CashierLogic (Logic/Business Object code)</li>
<li>CashierForms (Presentation code)</li>
</ul>
<p>The Data Access Layer project and the Logic layer project should each be a &#8220;Code Library&#8221; as its project type. The CashierForms should be a Windows Forms project. Now how do we get all the code connected together</p>
<p>You would build the CashierDataService. Once you have a DLL built from it, go into the CashierLogic project and add a reference to to the CashierDataService. You can do this by opening the Add Reference dialog box. From there go to the &#8220;Projects&#8221; tab, which should list all the projects in your solution.</p>
<p>Next you would do the same with CashierForms and CashierLogic. That is you would add a reference to CashierLogic inside the CashierForms projects.</p>
<p><strong>General Guidelines<br />
</strong>Note that I am <em>not </em>adding a reference to CashierDataService inside of CashierForms. The presentation layer should not directly interact with the Data Access Layer. The Logic (AKA Business or Business Object) layer serves as the middleman between these two layers (among other things). Thus, the actual structure of references enforces the seperation of responsibilities within n-tiered application design.</p>
<p>So in the end, the layers &#8220;build up&#8221; from each other. The DataAccessLayer serving as the foundation. The Business Logic layer on top of that. And finally the Presentation Layer as the pretty shell that surrounds all that code.</p>
<p><strong>Some Final Thoughts<br />
</strong>Now usually you will have more than 3 projects representing 3 layers. But the basic enforcement should be kept the same. The Presentation Layer only has references to Logic Layer. The Logic Layer has only references to the Data Access layer. Often I will have a common or shared project (named something like CashierCommon) that contains common code among all layers. I have to be vigilant to keep bloat down in this layer, since it should only be used as a last resort for (usually) common enumerators or simple logical functions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=57&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/06/09/n-tiered-project-linkag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>VB beginnier&#8217;s guide to n-tiered programming (part 3) &#8211; business logic layer</title>
		<link>http://programatique.wordpress.com/2009/05/27/vb-beginniers-guide-to-n-tiered-programming-part-3-business-logic-layer/</link>
		<comments>http://programatique.wordpress.com/2009/05/27/vb-beginniers-guide-to-n-tiered-programming-part-3-business-logic-layer/#comments</comments>
		<pubDate>Wed, 27 May 2009 16:14:24 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3-tier]]></category>
		<category><![CDATA[collectionbase]]></category>
		<category><![CDATA[interfaces]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=49</guid>
		<description><![CDATA[This is where I spend the bulk of my programming. The goal is to take business objectives and translate them into code. No direct calls to stored procedures, or any sort of SQL should be contained in this layer. Also, no Windows Forms (or Web Forms) objects should be contained within this project. This includes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=49&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is where I spend the bulk of my programming. The goal is to take business objectives and translate them into code. No direct calls to stored procedures, or any sort of SQL should be contained in this layer. Also, no Windows Forms (or Web Forms) objects should be contained within this project. This includes passing Forms objects as parameters -which is a huge no-no. Not much else to say specifically about the layer, since it will differ for each solution&#8217;s requirements. For those still unfamiliar with much of the VB.NET language. I&#8217;ll finish off with a few common pieces of code I utilize for most projects.</p>
<p>I tend to use a lot of the basic interfaces here from IDisposable, IComparer, etc. If you are unfamiliar with interfaces, they are &#8220;implemented&#8221; by classes. Interfaces set required methods/properties for the implementing class to contain.</p>
<p>Also, for objects that contain collections of custom objects &#8211; I tend to use the CollectionBase class. A custom class can inherit from CollectionBase. From there you will probably need to create a few basic procedures such as &#8220;Add&#8221; and &#8220;Item&#8221;, along with any other functionality you need. Here&#8217;s the basic method signature for add:</p>
<pre>Add(Item as MyClass)</pre>
<p>I also overload the Add method to include one that utlizes the constructur (New()) of the item. If I had an Item that takes an ID and a Name, I would usually include an Add method like so:</p>
<pre>Add(ID as Integer, Name as String)</pre>
<p>From there I create a new instance of MyClass, and then add it to the CollectionBase&#8217;s &#8220;List&#8221; variable. You would also need a way to return items via an Index number like so:</p>
<pre>Default Readonly Property Item(Index as Integer)</pre>
<p>You can add, retrieve items with the underlying &#8220;List&#8221; variable &#8211; and if needed it&#8217;s underlying ArrayList, which is called &#8220;InnerList&#8221; by the CollectionBase.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=49&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/05/27/vb-beginniers-guide-to-n-tiered-programming-part-3-business-logic-layer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
		<item>
		<title>VB beginner&#8217;s n-tiered coding (part 2) &#8211; data access tier</title>
		<link>http://programatique.wordpress.com/2009/05/12/beginners-guide-n-tiered-2/</link>
		<comments>http://programatique.wordpress.com/2009/05/12/beginners-guide-n-tiered-2/#comments</comments>
		<pubDate>Tue, 12 May 2009 19:45:34 +0000</pubDate>
		<dc:creator>programatique</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3-tier]]></category>
		<category><![CDATA[DAL]]></category>
		<category><![CDATA[data access layer]]></category>
		<category><![CDATA[n-tiered]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[visual basic]]></category>

		<guid isPermaLink="false">http://programatique.wordpress.com/?p=39</guid>
		<description><![CDATA[The Data Access Layer consists of all calls made between the database and the application. As mentioned previously, no other layer should contain any sort of calls to the database. So what does a Data Access Layer look like? First you&#8217;ll need a base class from which most of your Data Access classes are derived. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=39&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The Data Access Layer consists of all calls made between the database and the application. As mentioned previously, no other layer should contain any sort of calls to the database. So what does a Data Access Layer look like? First you&#8217;ll need a base class from which most of your Data Access classes are derived. Then you&#8217;ll need a derived class for each specific implementation of database you will be using. Usually this means 1 derived class. Much of my initial research into DAL&#8217;s was based on <a href="http://www.simple-talk.com/dotnet/.net-framework/.net-application-architecture-the-data-access-layer/">this</a>.</p>
<p>This post assumes you know how to connect to, read, and update a database in .NET; and that you are somewhat familiar with basic object-oriented concepts such as inheritance and interfaces.To keep things simple, and for the purpose of introducing the concept of a Data Access layer this code omits certain things. For example &#8211; it does not deal with database transactions and it only specifies Dataset-based querying (ignores DataReaders). This represents how I like to create DAL&#8217;s, and is by no means the only way to do things. I hope to present some basic concepts and ideas along with some concrete code to those unfamiliar with DAL&#8217;s.</p>
<p>I initially create a skeleton class which all other classes are derived from. It utilizes a lot of interfaces. Instead of calling a SqlCommand or an OracleConnection &#8211; utilize IDbCommand and IDbConnection. This avoids calling specific implementations of DataAdapters and Connections for your child classes. We want to keep the base class as generic as possible, so utilize the various data-related interfaces to keep it as database-agnostic as possible. The base class provides 3 key methods (which will be overloaded) -</p>
<p style="padding-left:30px;">Execute &#8211; returns a dataset<br />
ExecuteNonQuery &#8211; returns an integer indicating RowsAffected<br />
ExecuteScalar &#8211; runs a scalar SQL statement and returns an object</p>
<p>Each should be marked &#8220;Protected&#8221;, so they can only be accessed by child classes and cannot be accessed by other VS Projects &#8211; we wouldn&#8217;t want non-DAL classes directly executing SQL. This would violate our separation of responsibilities for each application layer. Each of the above methods have 4 overloaded versions. One which passes only the SQL statement. One which passes SQL statement, and a ParamArray of IDbParameters. And versions of the preceding with a Connection object. Like so:</p>
<p style="padding-left:30px;">Execute(SQL as String) As Dataset<br />
Execute(SQL as String, ParamArray params as IDbParameter()) As Dataset<br />
Execute(SQL as String, Conn as IDbConnection)&#8230;<br />
Execute(SQL as String, Conn as IDbConnection, ParamArray params as IDbParameter())&#8230;</p>
<p>This pattern is followed for &#8220;ExecuteScalar(&#8230;) As Object&#8221; and &#8220;ExecuteNonQuery(&#8230;) As Integer&#8221;. This allows for some flexibility in calling these functions. Those signatures with IDbConnection passed in allow the coder to re-use a connection if desired. Which brings us to &#8220;helper&#8221; functions within the class.</p>
<p style="padding-left:30px;">Public GetConnection &#8211; which returns an IDbConnection<br />
Protected GetCommand(Command as string, Connection as IDbConnection) &#8211; returns an IDbCommand<br />
Protected GetDataAdapter(cmd As IDbConnection) &#8211; returns an IDbDataAdapter<br />
Protected GetParam(Name as string, Value as string) &#8211; which returns an IDbParameter</p>
<p>I only use method signatures matching the &#8220;most-used&#8221; initialization method signatures (New(&#8230;)) for each of these helper functions; feel free to create functions for whatever different initialization method signatures you want. GetConnection is marked private, so the logic layer can reuse an open connection if needed. When creating your main functions (Execute, ExecuteScalar, and ExecuteNonQuery), be sure to use only interfaces, and to retrieve database objects via the above helper classes.</p>
<pre>Protected Function Execute(SQL as String, Conn as IDbConnection) As DataSet
  Dim ds As DataSet
  Dim da as IDbDataAdapter</pre>
<pre>  Using cmd As IDbCommand = GetCommand(SQL, Conn)
    da = GetAdapter(cmd)
    da.Fill(ds)
  End Using</pre>
<pre>  Return ds
End Function</pre>
<p>Now you can create child classes which inherit from this base class and utilize a specific DBMS. You will only need to specifically detail the GetConnection, GetCommand, GetParam, and GetDataAdapter functions. Everything should &#8220;fall into place&#8221; from there, since we kept our other method calls vague (via Interfaces).</p>
<p>Finally, there are tools, such as <a href="http://en.wikipedia.org/wiki/Nhibernate" target="_blank">nHibernate </a>that take much of the menial work out of creating DAL&#8217;s. I have yet to delve into this as of yet, but hope to in the future.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programatique.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programatique.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programatique.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programatique.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programatique.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programatique.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programatique.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programatique.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programatique.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programatique.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programatique.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programatique.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programatique.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programatique.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programatique.wordpress.com&amp;blog=7478846&amp;post=39&amp;subd=programatique&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programatique.wordpress.com/2009/05/12/beginners-guide-n-tiered-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad40668b60ccf37eb8cc6d3928e22fae?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">programatique</media:title>
		</media:content>
	</item>
	</channel>
</rss>
