<?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/"
	>

<channel>
	<title>Filip Ekberg&#039;s blog</title>
	<atom:link href="http://blog.smartit.se/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartit.se</link>
	<description>.NET Development is the future, are you prepared?</description>
	<lastBuildDate>Thu, 06 May 2010 20:21:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Use Test Driven Development to verify that the code will Always work!</title>
		<link>http://blog.smartit.se/2010/04/23/use-test-driven-development-to-verify-that-the-code-will-always-work/</link>
		<comments>http://blog.smartit.se/2010/04/23/use-test-driven-development-to-verify-that-the-code-will-always-work/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 11:51:54 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net 4.0]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://blog.smartit.se/?p=103</guid>
		<description><![CDATA[After attending Scandinavian Developer Conference in Sweden 2010 and attending the talk from Roy Osherove ( http://osherove.com/ ) Test Driven Development ( TDD ) has been something that I have tried to focus a bit more on.
Roy talks about some really important aspects of programming that should be printed into the programmers brain. I for [...]]]></description>
			<content:encoded><![CDATA[<p>After attending Scandinavian Developer Conference in Sweden 2010 and attending the talk from Roy Osherove ( <a href="http://osherove.com/">http://osherove.com/</a> ) Test Driven Development ( TDD ) has been something that I have tried to focus a bit more on.</p>
<p>Roy talks about some really important aspects of programming that should be printed into the programmers brain. I for instance is one of these people that like to verify everything that I do; Did I <strong>Really </strong>lock the door? So when I&#8217;ve turned the keys in the lock, I verify that the locking mechanizm worked and that the door is no indeed locked.</p>
<blockquote><p>So what does my weird habbit have to do with TDD?</p></blockquote>
<p>Driving the development with tests is not the only part of TDD; as with anything else there are a lot of people that like to think a lot of different things about this method. I like to think of tests as a way to Verify that my code runs as expected.</p>
<p><strong>This is not a case of miss-trust!</strong></p>
<p>Don&#8217;t missunderstand the above as see me as someone that does&#8217;t trust anyone or anything created by others than myself, that&#8217;s not the case. But by verifying that things runs properly, the door is properly locked I know that everything is OK from my part in the scenario.</p>
<p>What if I didn&#8217;t run the tests on the code and handed it over to the next developer that Did not in fact know that the method he works in affects everything else? And what if I didn&#8217;t verify the lock; I was in a big hurry and someone just went into the appartment and stole my TV?</p>
<p>In my opinion, test driven development is way to:</p>
<ul>
<li>Verify that Code runs as it should</li>
<li>Decrease mistakes in the future</li>
<li>Help others gain knowledge of parts in the code faster</li>
</ul>
<p>To take the locking mechanizm-checking even further and really turn it into something that is Driven you can follow these three very simple steps that Roy also talks about in his speeches:</p>
<ul>
<li>Make it fail</li>
<li>Make it work</li>
<li>Make it better</li>
</ul>
<p>How do you make the lock fail to lock? Well you simply <strong>Don&#8217;t lock it!</strong></p>
<p>So let&#8217;s head over to the development aspect of this, you want to make your code fail? No code means it will fail right? When I do this step 1 and 2 always go together, especially when I demo TDD for co-workers or others. I will use the same good example as Roy used in his demo on SDC 2010, let&#8217;s try to put our heads around a simple Calculator project.</p>
<p><strong>Defining the requirements</strong></p>
<p>For this &#8220;project&#8221; we only have fourrequirements:</p>
<ul>
<li>A method called Sum</li>
<li>This method parses a String</li>
<li>This method should return String.Empty when you pass Invalid or Empty data</li>
<li>Adds two integers in the String together &#8220;1 1&#8243; would be 2</li>
</ul>
<p>So if we follow the above we would end up with a test that looks like the following:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#91;</span>TestMethod<span style="color: #008000;">&#93;</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Sum_EmtpyString_ReturnsZero<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var calculator <span style="color: #008000;">=</span> Calculator<span style="color: #008000;">.</span><span style="color: #0000FF;">GetInstance</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; var actual <span style="color: #008000;">=</span> calculator<span style="color: #008000;">.</span><span style="color: #0000FF;">Sum</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; var expected <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>expected, actual<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Since we haven&#8217;t really implemented Calculator, GetInstance or Sum yet, we made it fail, there is no Code. Visual Studio helps us out a bit and makes the process a bit faster, by simply pressing alt + enter when selecting Calculator or Sum we can select to create the Class and create the Method Stub.</p>
<p>So we actually finished both Step 1 and Step 2 at the same time, even though Step 2 isn&#8217;t complete yet, we are nearly there!</p>
<p>Now we need to make it work, what is the simpliest way possible to make it work for the above test-case?</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Sum<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> input<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Emtpy</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>This will actually work and it will indeed check this test as Passed. But it&#8217;s not really what we want. So how do we proceed?</p>
<p>Another Great point Roy pointed out is that, if there isn&#8217;t a test, there&#8217;s no code and if there&#8217;s code there&#8217;s gotta be a test! And if one test passes and you want to Change the code to behave different with other input; You need to prove it with a test!</p>
<p>So we can test if</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Sum<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;1&quot;</span><span style="color: #008000;">&#41;</span></div></td></tr></tbody></table></div>
<p>will return 1, which we from looking at the code will see that it wont!</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Sum_ValueContainsADigit_ReturnTheDigitThatIsPassed<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var calculator <span style="color: #008000;">=</span> Calculator<span style="color: #008000;">.</span><span style="color: #0000FF;">GetInstance</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; var actual <span style="color: #008000;">=</span> calculator<span style="color: #008000;">.</span><span style="color: #0000FF;">Sum</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;1&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; var expected <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;1&quot;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqaul</span><span style="color: #008000;">&#40;</span>expected, actual<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>This test will most defently fail because of our implementation! So we need to go back to Sum and change this method.</p>
<p>Once all tests passes and the test case is approved, we head on to the next step, which is <strong>make it better</strong>! In other wors we need to refactor some code! Try to follow these steps to refactor ( i use ReSharper, which is a Great tool! ).</p>
<ul>
<li>Move the Library to an appropriet Class Library / Project</li>
<li>Optimize the code</li>
<li>Refactor your test to look better</li>
<li>Comment the code</li>
</ul>
<p>So you got a little peek at what TDD is and how it can be used, if everyone would use TDD, it would be so much easier to take on new projects that have already been started. You never know what your changes will impact on.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2010/04/23/use-test-driven-development-to-verify-that-the-code-will-always-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Parallel Extensions in LINQ</title>
		<link>http://blog.smartit.se/2010/03/25/using-parallel-extensions-in-linq/</link>
		<comments>http://blog.smartit.se/2010/03/25/using-parallel-extensions-in-linq/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:16:02 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net 4.0]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[parallel programming]]></category>

		<guid isPermaLink="false">http://blog.smartit.se/?p=102</guid>
		<description><![CDATA[Once again, there was a little mistake in the last post I posted here which clearly didn&#8217;t effect the result that much. But it is still worth mentioning again. The ^ was not meant to be XOR, I was clearly thinking of Math.Pow.
In the last post I didn&#8217;t spend to much time talking about the [...]]]></description>
			<content:encoded><![CDATA[<p>Once again, there was a little mistake in the last post I posted here which clearly didn&#8217;t effect the result that much. But it is still worth mentioning again. The ^ was not meant to be XOR, I was clearly thinking of Math.Pow.</p>
<p>In the last post I didn&#8217;t spend to much time talking about the Parallel Extensions for LINQ which are Really great and helpful; If you just love to replace traditional loops with LINQ-expressions you will probably find this post somewhat amusing.</p>
<p>So let&#8217;s dig down to the coding shall we!</p>
<p>First of all I have set up a smaller list with numbers, in this scenario we will just assume that we have a list of something and depending on the contents of that list, the time it takes to perform an action on that result, will differ. So here&#8217;s my list</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var latency <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span><span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">8</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p><em>Side note: new[]{} is really helpful, especially when you are creating examples like this!</em></p>
<p>And then I have a method that I want to run for each element in my list, which I will call PerformLogic</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> PerformLogic<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> latency<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var ms <span style="color: #008000;">=</span> <span style="color: #FF0000;">500</span> <span style="color: #008000;">*</span> latency<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span>ms<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> ms<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>In &#8220;traditional&#8221; programming, you would maybe do something like this:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> latency<span style="color: #008000;">.</span><span style="color: #0000FF;">Lenght</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span> <span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; PerformAction<span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>But I don&#8217;t find that so amusing anymore, using LINQ is so much neater so instead of that for-loop we can actually do this:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> i <span style="color: #0600FF; font-weight: bold;">in</span> latency <span style="color: #0600FF; font-weight: bold;">select</span> PerformAction<span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>We don&#8217;t really have to write the expession like this though, since LINQ + .NET 4.0 is so smart, we can Refactor this to look somewhat like this:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#40;</span>latency<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>PerformLogic<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>The previous one is a bit more elaborate but this is fine aswell.</p>
<p><strong>Making it parallel</strong></p>
<p>We&#8217;ve reached the place where we no longer can refactor our code to make it faster, we can&#8217;t replace anything in the logic to make everything faster; We need to parallelize it!</p>
<p>Let&#8217;s have a look at what LINQ provides us with, oh, there&#8217;s an method called</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">.</span><span style="color: #0000FF;">AsParallel</span></div></td></tr></tbody></table></div>
<p>.</p>
<p>All I did now was changing the above code to this:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var result <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>latency<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>PerformLogic<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AsParallel</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>And we have a parallelized query. For those with a fast mind can see that it will take about 7,5 seconds to run this since each of the &#8220;latency&#8221;-points will take itself times ½ second.</p>
<p>My final test-code looks like this</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var latency <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span><span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">8</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
<br />
var start <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span><br />
<br />
var result <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>latency<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>PerformLogic<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AsParallel</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
var end <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span><br />
<br />
Parallel<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">ForEach</span><span style="color: #008000;">&#40;</span>result, Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Execution time: {0}&quot;</span>, <span style="color: #008000;">&#40;</span>end <span style="color: #008000;">-</span> start<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>And this is the output<br />
<img src="http://dl.dropbox.com/u/4396175/snapshots/linq_parallel.png" alt="LINQ Parallelism" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2010/03/25/using-parallel-extensions-in-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Parallel Extensions in .NET 4.0 with C#</title>
		<link>http://blog.smartit.se/2010/03/24/using-the-parallel-extensions-in-net-4-0-with-c/</link>
		<comments>http://blog.smartit.se/2010/03/24/using-the-parallel-extensions-in-net-4-0-with-c/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 08:59:40 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net 4.0]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[parallel programming]]></category>

		<guid isPermaLink="false">http://blog.smartit.se/?p=89</guid>
		<description><![CDATA[As .NET 4.0 will be released in a couple of weeks and the RC has been out for a while. It&#8217;s about time that I write something about the new helpful features of .NET 4.0. One of these helpful things are the Parallel Extensions and Parallel helpers that allowes you to do parallel programming.
Parallel computing [...]]]></description>
			<content:encoded><![CDATA[<p>As .NET 4.0 will be released in a couple of weeks and the RC has been out for a while. It&#8217;s about time that I write something about the new helpful features of .NET 4.0. One of these helpful things are the Parallel Extensions and Parallel helpers that allowes you to do parallel programming.</p>
<blockquote><p><strong>Parallel computing</strong> is a form of <a title="Computing" href="http://en.wikipedia.org/wiki/Computing">computation</a> in which many calculations are carried out simultaneously</p></blockquote>
<p>In this example I will be using a WebRequestPool which just helps me out a bit to carry on this example. You might think if it like this: You have different request types which takes different long to execute you might be doing some WebDAV uploading, Image Fetching and other Over-The-Web-Access which takes time. Instead of waiting for each request to stop, you might as well run them simultaneously.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">delegate</span> <span style="color: #6666cc; font-weight: bold;">void</span> WebRequest<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> ms<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> WebRequestPool<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> List Requests <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>So to make it easy I just have a simple Delegate which will allow us to Run/Invoke our WebMethods which all takes some input parameter that will, in some way, make the requests take longer / shorter.</p>
<p>Inside of the WebRequest class all we have is a Requests Pool, a simple list of delegates.</p>
<p>To make the whole a little bit interesting we have three different types of Requests: Standard Request, Long Request and ExtremeRequest</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> StandardRequest<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> ms<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span>ms<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> LongRequest<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> ms<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span>ms<span style="color: #008000;">^</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> ExtremeRequest<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> ms<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span>ms<span style="color: #008000;">^</span><span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>So now we have three different types of methods that all validate with our delegate! Let&#8217;s head on and fire up this pool</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var pool <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> WebRequestPool<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Requests <span style="color: #008000;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StandardRequest,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LongRequest,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExtremeRequest,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StandardRequest,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LongRequest,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExtremeRequest<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>This actually demonstrates something new too, the object initializers. So the list now contains six requests, All we want to do now is Processes these.</p>
<p>First of all we want to do it like we did in the old days, so I&#8217;ve created a method called ProcessPool which looks like this</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> ProcessPool<span style="color: #008000;">&#40;</span>WebRequestPool pool<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; var start <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var item <span style="color: #0600FF; font-weight: bold;">in</span> pool<span style="color: #008000;">.</span><span style="color: #0000FF;">Requests</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; item<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; var end <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; var span <span style="color: #008000;">=</span> end <span style="color: #008000;">-</span> start<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Execution time: {0}&quot;</span>, span<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Of we run this the output is<br />
<img src="http://dl.dropbox.com/u/4396175/snapshots/parallel_run_1.png" alt="Execution time" /></p>
<p>Now, that&#8217;s a bit too slow for me, so <strong>Let&#8217;s Parallelize that!</strong> All i&#8217;ve done now is to creat a new method called ProcessPoolAsParallel which takes the same input and expects to give the same result. There&#8217;s a little bit difference though, the foreach is now replaced with the</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Parallel<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">ForEach</span></div></td></tr></tbody></table></div>
<p>method.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> ProcessPoolAsParallel<span style="color: #008000;">&#40;</span>WebRequestPool pool<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; var start <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Parallel<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">ForEach</span><span style="color: #008000;">&#40;</span>pool<span style="color: #008000;">.</span><span style="color: #0000FF;">Requests</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; item <span style="color: #008000;">=&gt;</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; var end <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; var span <span style="color: #008000;">=</span> end <span style="color: #008000;">-</span> start<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Execution time: {0}&quot;</span>, span<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>So if we run this now the result is:<br />
<img src="http://dl.dropbox.com/u/4396175/snapshots/parallel_run_2.png" alt="Parallel run 2" /></p>
<p>So this increased significally!</p>
<p>This is just a small example of the power in using Parallel programming patterns. Look into the Task class to head on!</p>
<p><strong>Edit</strong></p>
<p>There&#8217;s a slightly miss-used method in the code above, the ^ in C# is XOR and I was thinking of the Math.Pow, however, this doesn&#8217;t really matter in this case since the result is still Parallel = Faster.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2010/03/24/using-the-parallel-extensions-in-net-4-0-with-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Function pointers in C and Python and their possible usage</title>
		<link>http://blog.smartit.se/2009/11/30/function-pointers-in-c-and-python-and-their-possible-usage/</link>
		<comments>http://blog.smartit.se/2009/11/30/function-pointers-in-c-and-python-and-their-possible-usage/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 15:07:20 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[c-programming]]></category>
		<category><![CDATA[function pointers]]></category>

		<guid isPermaLink="false">http://blog.smartit.se/?p=83</guid>
		<description><![CDATA[Function pointers? you might ask yourself, well this little trick gets handy sometimes, I will provide an example of a practical use in a later post on the next euler solution. Might actually do it in C too just to prove that C is still neat.
So to kick this off, what are function pointers? Well [...]]]></description>
			<content:encoded><![CDATA[<p>Function pointers? you might ask yourself, well this little trick gets handy sometimes, I will provide an example of a practical use in a later post on the next euler solution. Might actually do it in C too just to prove that C is still neat.</p>
<p>So to kick this off, what are function pointers? Well for those deep down the rabbit hole ( .NET guys that is ), might not really have a clue on the matter, and others might dissaggree and now exactly what it is. So just to keep the air clear here, function pointers are &#8220;pointers&#8221; that direct you to a function, easy huh?</p>
<p>Well, you probably got as much from just reading the phrase but, it&#8217;s not really rocket science. If you are familiar with references or reference types, such as Strings and Objects, you know that there are different types of memory in which your program operates. When you create an Object you store your data on a shared memory place. There are shared memory and program reserved memory ( the stack! ). So you might want to look at this as a &#8220;reference&#8221; to a function.</p>
<p>So when would this be nessecary? Imagine the scenario where you might want to performe some calculation but you don&#8217;t know what type of API the end user which will end up using your API have. Let&#8217;s say that the method &#8220;square&#8221; ( x^x ) would not be defined. So you might end up having to use function pointers, where you ask the user to suppy the function for calculating square of x.</p>
<p>In Python the Square function for x^x will look like this</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> square<span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; result = i<span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>i-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #66cc66;">*</span>= i<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> result</div></td></tr></tbody></table></div>
<p>In C it will look like this</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> square<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> result <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> i<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #339933;">*=</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now these two look fairly similar don&#8217;t they? Well sure, the only real difference is the dialekt right? It&#8217;s just programming. So let&#8217;s get to the cool parts. In python, we would solve this problem easy, since it&#8217;s not a strongly typed language everything could be a function, right. So let&#8217;s check the decleration for calculate.</p>
<p>But before we check that out, let&#8217;s just make it clear that our Usage will be somewhat like, give me a function that calculates square of a+b, this means, the result should be (a+b)^(a+b).</p>
<p>So this is the function decleration in Python</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> calculate<span style="color: black;">&#40;</span>func, a, b<span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>Not that hard, right? Well, keep in mind that Python is a &#8220;modern&#8221; language, it&#8217;s more of a scripting language.</p>
<p>Check this out and notice the fairly big difference</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> calculate<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> c<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>If you are not familiar with pointers I would suggest you dig down the archive on my blog and check out the chapters about that. So what this really does in C is that you tell the compiler that, okay this function takes a pointer to something that will look like this, and you write the declaration of the function again. So, in this case you really need to know what it looks like. With standard parameter values in Python you could acheive some really cool things without knowing the decleration of the function.</p>
<p>Now we&#8217;ve seen how to Create the methods, taking arguments that are functions, how about using them inside your code?</p>
<p>Check this C example of the whole Calculate function</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> calculate<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> c<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">+</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>And in Python the following will look like this</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> calculate<span style="color: black;">&#40;</span>func, a, b<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> func<span style="color: black;">&#40;</span>a+b<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span></div></td></tr></tbody></table></div>
<p>There is a notable difference here, but I can honestly say that I like the C-style.</p>
<p>Try out the python version!</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> square<span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; result = i<span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>i-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #66cc66;">*</span>= i<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> result<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> calculate<span style="color: black;">&#40;</span>func, a, b<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> func<span style="color: black;">&#40;</span>a+b<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> calculate<span style="color: black;">&#40;</span>square, <span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:<br />
&nbsp; &nbsp; main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2009/11/30/function-pointers-in-c-and-python-and-their-possible-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving the first problem</title>
		<link>http://blog.smartit.se/2009/11/30/solving-the-first-problem/</link>
		<comments>http://blog.smartit.se/2009/11/30/solving-the-first-problem/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 10:06:25 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[euler]]></category>

		<guid isPermaLink="false">http://blog.smartit.se/?p=72</guid>
		<description><![CDATA[So I&#8217;ve decided to start a new project, to solve as many euler problems as possible from http://projecteuler.net/, in Python! The task in hand is not only to solve them but to think outside the box and add new features to the code which might become suitable in the future, who knows.
Let&#8217;s start off by [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve decided to start a new project, to solve as many euler problems as possible from http://projecteuler.net/, in Python! The task in hand is not only to solve them but to think outside the box and add new features to the code which might become suitable in the future, who knows.</p>
<p><strong>Let&#8217;s start off by solving the first problem!</strong></p>
<blockquote><p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.<br />
Find the sum of all the multiples of 3 or 5 below 1000</p></blockquote>
<p>Now you might think it&#8217;s useless if you Only can solve this for 3 and 5, so why don&#8217;t we just make a tuple with the appropriet set of numbers?</p>
<p>My function declaration ended up looking like this</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> sum_naturals<span style="color: black;">&#40;</span><span style="color: #008000;">max</span>, dividers=<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>Where the variable max is, in this case, 1000. to test it out, I want the following to be true</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;"># Prints 23</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> sum_naturals<span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>This problem is not really rocket science so I&#8217;ll just let you guys look at the code and try to figure out what I was thinking, and please leave comments if you like or disslike it.</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> sum_naturals<span style="color: black;">&#40;</span><span style="color: #008000;">max</span>, dividers=<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:<br />
result = <span style="color: #ff4500;">0</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Iterate through the numbers from 0 to max</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">max</span><span style="color: black;">&#41;</span>:<br />
<span style="color: #808080; font-style: italic;"># Iterate the dividers and divide i with each Divider</span><br />
possibleDivision = <span style="color: #ff4500;">0</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> divizor <span style="color: #ff7700;font-weight:bold;">in</span> dividers:<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>i <span style="color: #66cc66;">%</span> divizor<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> possibleDivision == <span style="color: #ff4500;">0</span>:<br />
possibleDivision = <span style="color: #ff4500;">1</span><br />
result += i<br />
<span style="color: #ff7700;font-weight:bold;">return</span> result</div></td></tr></tbody></table></div>
<p>This is actually a perfectly good example on &#8220;How to start python programming&#8221;. If requested or if i just feel like it, I might create a serie where I break these or similar problems into smaller pieces and explain them. Maybe I&#8217;ll throw in a couple of C#, C and PHP examples aswell. <em>You decide</em>.</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2009/11/30/solving-the-first-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing the new Code-tag</title>
		<link>http://blog.smartit.se/2009/11/30/testing-the-new-code-tag/</link>
		<comments>http://blog.smartit.se/2009/11/30/testing-the-new-code-tag/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 08:47:03 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.smartit.se/?p=64</guid>
		<description><![CDATA[Testing testing&#8230;
1234&#160; &#160; &#60;?php
&#160; &#160; &#160; &#160; // some code
&#160; &#160; &#160; &#160; $i = 1;
&#160; &#160; ?&#62;
Seems like it works?
]]></description>
			<content:encoded><![CDATA[<p>Testing testing&#8230;</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// some code</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Seems like it works?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2009/11/30/testing-the-new-code-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Communication issues when adapting outsourcing</title>
		<link>http://blog.smartit.se/2008/12/14/communication-issues-when-adapting-outsourcing/</link>
		<comments>http://blog.smartit.se/2008/12/14/communication-issues-when-adapting-outsourcing/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 17:19:46 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Projects & Project Organization]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hci]]></category>
		<category><![CDATA[human computer interaction]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[outsourcing]]></category>
		<category><![CDATA[project management]]></category>

		<guid isPermaLink="false">http://fekberg.wordpress.com/2008/12/14/communication-issues-when-adapting-outsourcing/</guid>
		<description><![CDATA[ 



 


 




Table of Contents
Communication issues when adapting outsourcing. 1
Background of Outsourcing. 3
A first view.. 3
Main benefits. 4
Adapting Outsourcing to your project 5
Handling work load over seas. 5
Communication problems. 5
Main problems. 5
Cultural problems. 6
Technical problems. 6
Outsourcing and Open source what makes them similar. 9
Open solutions, the advantage. 9
Marketing and new technology, community help. 10
References. 12
Background of Outsourcing
A [...]]]></description>
			<content:encoded><![CDATA[<h3> </h3>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="114"> </td>
</tr>
<tr>
<td> </td>
<td><a href="http://fekberg.files.wordpress.com/2008/12/clip-image002.gif"><img style="display:inline;border-width:0;" title="clip_image002" src="http://fekberg.files.wordpress.com/2008/12/clip-image002-thumb.gif" border="0" alt="clip_image002" width="231" height="240" /></a></td>
</tr>
</tbody>
</table>
<p>Table of Contents</p>
<p><a href="#_Toc216708802">Communication issues when adapting outsourcing. 1</a></p>
<p><a href="#_Toc216708803">Background of Outsourcing. 3</a></p>
<p><a href="#_Toc216708804">A first view.. 3</a></p>
<p><a href="#_Toc216708805">Main benefits. 4</a></p>
<p><a href="#_Toc216708806">Adapting Outsourcing to your project 5</a></p>
<p><a href="#_Toc216708807">Handling work load over seas. 5</a></p>
<p><a href="#_Toc216708808">Communication problems. 5</a></p>
<p><a href="#_Toc216708809">Main problems. 5</a></p>
<p><a href="#_Toc216708810">Cultural problems. 6</a></p>
<p><a href="#_Toc216708811">Technical problems. 6</a></p>
<p><a href="#_Toc216708812">Outsourcing and Open source what makes them similar. 9</a></p>
<p><a href="#_Toc216708813">Open solutions, the advantage. 9</a></p>
<p><a href="#_Toc216708814">Marketing and new technology, community help. 10</a></p>
<p><a href="#_Toc216708815">References. 12</a></p>
<h3><a name="_Toc216708803">Background of Outsourcing</a></h3>
<h4><a name="_Toc216708804">A first view</a></h4>
<p>Let’s assume that you run a company, no matter if the company is big or small. Just imagine having to build a project where you know that your current staff either doesn’t have the right knowledge to solve this problem or the number of staff members is not sufficient. This is where your company will face a problem, either you hire some new personnel or you consider Outsourcing your project. In this text, we will talk only about outsourcing when it comes to information technology projects not any other work fields such as call centers etc.</p>
<p>So when browsing Wikipedia¹ we see that the following description is given <em>“Outsourcing involves the transfer of the management and/or day-to-day execution of an entire business function to an external service provider”. </em>This means that we can transfer our activities on our project to another country and have others take the work load. If we think closely on this, for how long has really outsourcing been available, when did it become easy to <em>Communicate </em>with countries far away? The answer is fairly easy, assume we had no internet and no computers, how would we then communicate with ie India? It would be impossible to this without our technology we have today. So considering a good interaction with computers is both a requirement and in today’s work spaces something that we can assume exists.</p>
<p>Outsourcing your project has in the last couple of years become a bigger and bigger way of solving company problems, these problems being Cultural, communicational and other areas of inconvenience as discussed by Sofie Alriksson².</p>
<p>This gives a good overview of what exactly Outsourcing is and how it’s adapted, now let’s continue discussing benefits and how technical problems might affect our work.</p>
<p><strong></strong></p>
<h4><a name="_Toc216708805">Main benefits</a></h4>
<p>As roughly mentioned above the benefits of outsourcing in general is to take the work load of your staff or to gather new personnel. As mentioned by Sofie Alriksson², adapting Outsourcing is mainly because you want to work on your core activity and let others focus on the outmost parts of the project, having companies’ overseas working on your modules while you are focusing on the main frame.</p>
<p>When having a computer project the price today is often very high, especially the production const, personnel in ex Sweden is very high this will of course give a result that the project will either be rushed or that the company will not afford having the project running for long. By outsourcing your project this scenario might change dramatically meaning that the cost for personnel is much less and this giving more money to more personnel having the project released faster.</p>
<h3><a name="_Toc216708806">Adapting Outsourcing to your project</a></h3>
<h4><a name="_Toc216708807">Handling work load over seas</a></h4>
<p>One of the first things you might consider when starting a project is to have all the documentation ready, this means that having UML-documentation, project plans, time tables and other planning papers ready when outsourcing, because being over-prepared doesn’t exist in the world of outsourcing.</p>
<p>Another thing to consider is; how will the outsourced company handle regular deliveries? What project models do we need to follow? These are some key points to consider, which again takes us to the most important part of all, the computer interaction. We can’t have fairly good English speaking personnel overseas calling us in the middle of the night giving us a project status report. A lot of the countries where outsourcing is cheap, is in another time zone that where the staff is actually expensive.</p>
<p>So how would report on a daily basis work? E-mails might not be as secure as you’d like, because the service itself is not encrypted, meanwhile there are of course solutions for this, but not to take this too much off topic, I’d say that using a closed project platform such as Sharepoint or any other project organization software out there. You can probably find a lot on the open source community which you could customize for your needs.</p>
<p>However, let’s not talk more about the software to be used but rather how we use the selected way of reporting. This is something that we really need to point out to the outsourced company, how we want them to report. As mentioned before, being to clear on what you need, how you need it and when you need it, is never a bad thing.</p>
<h4><a name="_Toc216708808">Communication problems</a></h4>
<h5><a name="_Toc216708809">Main problems</a></h5>
<p>Outsourcing <em>might </em>sound very good and sure can be a good solution for your situation. However, there are always downsides with solution that presents them as being <em>this</em> perfect. These problems are taken up by both Sofie Alriksson² and Jeff Atwood³, besides from the obvious that your project might be shipped to India where you will have no <em>visual </em>perspective over the work, you might find troubles such as the ones Jeff Atwood³ states here <em>“They get cancelled. Or the consultant who bid on the work never delivered, or delivered poor results. Or the client has unreasonable expectations, or doesn’t actually know what he wants.” </em>What actually does happened if you bid too low and the consultant or outsourced company realizes this and in the middle of the process decides to quit? There’s no good solution for that problem, being repetitive is the best learning process, so here goes again, <strong>never ever give to little information</strong>.</p>
<h5><a name="_Toc216708810">Cultural problems</a></h5>
<p>The above problems isn’t the only issues when adapting outsourcing, you might as well find that the cultural difference it way to big and this problem is clearly talked about in Sofie Alrikssons² paper, she also presents a possible solution which in this case was to inform the company where you outsource of your culture and how you like your work to be handled. It’s also very important that the hiring company has knowledge about the other culture, understanding is very important from both parties.</p>
<p>How does the cultural problem affect the computer interaction? For instance imagine outsourcing your project to India where they have totally different believes than we have here up north, this means that they might have different rituals than we do such as preying on a regular basis and on a specific time. If the hiring company does not have knowledge about this, what happens when we try to call them at this time, or when we assume to have something delivered? As you can see, this is not really a computer interaction problem, but rather a religious misunderstanding. But a cultural problem that actually will affect the interaction is the Technical perspective. Sweden per say is one of the countries in the world with the best technology, meaning that we might actually have different assumptions regarding technology and how we use computers, than the company in the outsourcing country. The reason for this might be a lot of different ones but for instance that the country is in general poor and can’t afford to take in new technology and adapt to the new standards. This is a very <strong>important </strong>point when viewing and discussing human computer interaction.</p>
<h5><a name="_Toc216708811">Technical problems</a></h5>
<p>Some of the technical problems are talked about in the previous topic but there are another perspective than the “cultural technology perspective”, the upcoming issue is however a result of that problem. If you imagine the scenario where a company in Sweden needs a new application to be developed for the new mobile technology. If this was a couple of years ago, let’s say 2004 when 3G was fairly new in Sweden and the company 3 was the only ones having this. What if the company 3 would want to develop a new mobile application using the 3G technology, but the application is so advanced and needs a huge amount of staff members to complete. This is simply too expensive for a new company like this to invest in.</p>
<p>However outsourcing this will help and make it more cost effective. But outsourcing this to a country like India which might not yet have this technology, will cause an inconvenience. This problem will therefore make the project cost much more, since the customer needs to set up a test area and development area for this to be developed and from a strictly computer interaction perspective, who says that the people adapting this technology in India, will follow the same principles as we do here?</p>
<p>We need to keep in mind that different people think different and that different cultures are very different meaning; Applications created by an outsourced company might not be as you would’ve made it yourself. Keep in mind that we are talking about software and / or general computer development and research. With this in mind, how differently would you think that an outsourced company documents, programs and do other tasks differently from how you or your staff would?</p>
<p>This question brings up a huge problem when outsourcing, the technology and the way of adapting it, will cause issues between the parties and as Jeff Atwood³ said <em>“For example, people asking for a clone of ebay for under $500”</em></p>
<p>A new company in Sweden that might not have any experience working with software development might think that it’s just typing as Jeff Atwood<sup>4 </sup>talked about. But this is in fact wrong, it’s complicated being a software developer and having to do with a software project might not always be so easy. Thus the applications that developers, managers and other involved staff members use has a quality requirement, they need to be top notch. Using such software and styles might not be widely known, a company might have its own developed software which they do not care to share with other companies. These are also aspects to take in mind when taking on a project which needs outsourcing.</p>
<p>Having discussed the benefits of using outsourcing and the downsides with the applications, culture and other aspects, we need to take a look at a final point on the downside this being, the result of the software product. We can assume that people from ex India are smarter and have another mindset than other countries such as Sweden, they work for less, they know they can easily be replaced, which leads to a harder work style. Now what can possible have to do with Human Computer Interaction and the “samrtness” of a population? Having a usage base that is generally smarter and thinks on a completely different basis will result in your application being made for this crowd. This directly affects the computer interaction, on the visual basis that is, because the hired personnel might interpret how to solve something graphically in a way you would never imagine.</p>
<h3><a name="_Toc216708812">Outsourcing and Open source what makes them similar</a></h3>
<h4><a name="_Toc216708813">Open solutions, the advantage</a></h4>
<p>Open Source is a very broad topic and will not be discussed thoroughly here. But the main purpose of an open application is that the community, being either developers or users can easily get the software and / or its source code; Source code being the logic for how everything behaves.</p>
<p>You could say that all software projects share a specific way of working and this is mainly the structure and documentation of the project. Some projects require this more than others; such as an open source project and an outsourced project. An open source application is often free of use, but there are of course applications that do cost money but are still open source. Either way, the most important part is to help the contributors understanding your business logic and the graphical user interface programming.</p>
<p>This is done by having good documentation and well commented code where you explain all the steps, of course you should never make code unreadable by adding to much comments, then the interaction with the code will just back draft.</p>
<p>When you create an open source project, you force this structured work way from the beginning, there’s no space for spaghetti code or ugly solutions. These parts will be replaced immediately and the programmer will probably not be welcome on this project further on.</p>
<p>This is a big advantage, letting the community contribute to your project and giving you a lot of feedback on it. However, what happens when you want to go global and have a paid for application? The contributors will then require some kind of assets for their work.</p>
<p>The feedback from the community is worth very much on a big project and might help you in long terms; the community is often willing to help out with the most outrageous projects just for fun or for experience. On an outsourced project however, you might not feel that you have the same commitment, however this is because you actually pay for something getting done, and you need to rely on the programmers to do their work. In an open source development you can’t force anyone to do your work.</p>
<h4><a name="_Toc216708814">Marketing and new technology, community help</a></h4>
<p>Let’s play out the scenario where you somehow come up with an idea of a technology or a software that isn’t on the market, but you know that this will help the community a lot in many ways. A project of this sort might be an electric car or a car driven on water, however that has nothing to do with software projects so let’s not talk more about cars.</p>
<p>When you have this kind of idea you either want to make a lot of money or you want to help the public community, but who ever says that money isn’t equal to motivation lies. The main purpose of a project is, in most cases, about making money. So you stand before a dilemma, either you publish your diagrams, project description and other project plans on a public community forum or create a website where you explain your situation. Which then might actually lead to someone else stealing your ideas and benefiting from this which results in them being rich and you being back to square one.</p>
<p>But planning the project well and having good license agreements can help you on the way, you might state that if anyone works on the project they are entitled to their name being written in the EULA or somewhat like that. Keep in mind that an open source project might not be a completely usable alternative for an outsourcing solution but it’s a good point to take when we talk about computer interaction because both type of work requires some common work ways which are good to think about.</p>
<p>Having an open source project which grows big might not only help you development wise but also marketing wise, because having a lot of programmers sharing their thoughts and interface suggestions and so forth will attract a crowd.</p>
<p>And think about it, when having an outsourced project you need to have the following aspects top notch:</p>
<p>· Project plan</p>
<p>· Commenting templates</p>
<p>· Documentation templates</p>
<p>· Wiki</p>
<p>· Forums</p>
<p>· Bug reporting system</p>
<p>· Source control system</p>
<p>These are just the aspects that really need to be perfectly planned no matter if it’s an open source project and outsource project or a local project on your company. For human computer interaction purposes these need to be top of the line.</p>
<p>Can you yet see another similarity between open source and outsourcing? If not, let’s present it; People around the world contributing to software development. See that as a headline of both Open Source and Outsourcing and the two latter names as an <em>“implementation”</em> of this expression. When having an open source project you never know what culture a contributor comes from or which time it is in his country. This forces an adaptation to new technology and a generic culture understanding.</p>
<h3><a name="_Toc216708815">References</a></h3>
<p>1. <strong>Wikipedia.</strong> Outsourcing. <em>Wikipedia. </em>[Online] 12 08, 2008. [Cited: 12 08, 2008.] http://en.wikipedia.org/wiki/Outsourcing.</p>
<p>2. <strong>Alriksson, Sofie.</strong> Communication problems by using outsourcing international . <em>Communication problems by using outsourcing international . </em>Halmstad, Halmstad, Sweden : Halmstad Högskola, 12 08, 2008.</p>
<p>3. <strong>Atwood, Jeff.</strong> Coding Horror. <em>Can You Really Rent a Coder? </em>[Online] 11 23, 2008. [Cited: 12 10, 2008.] http://www.codinghorror.com/blog/archives/001190.html.</p>
<p>4. —. Coding Horror. <em>We Are Typists First, Programmers Second. </em>[Online] 11 17, 2008. [Cited: 12 10, 2008.] http://www.codinghorror.com/blog/archives/001188.html.</p>
<p>5. <strong>David Axlund, VD Mailopages Sweden AB.</strong> <em>VD. </em>Karlskrona, 11 20, 2008.</p>
<p>6. <strong>Ekberg, Filip.</strong> <em>The Art of Teaching. </em>05 : 12, 2008.</p>
<p>7. <strong>Masses, Development for the.</strong> Development for the Masses. <em>Communication problems in outsourcing. </em>[Online] 2008. [Cited: 12 10, 2008.] http://www.dev4masses.com/a_communication_problems/.</p>
<p>By Filip Ekberg and Göran Petersson</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2008/12/14/communication-issues-when-adapting-outsourcing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Art of Teaching</title>
		<link>http://blog.smartit.se/2008/12/05/the-art-of-teaching/</link>
		<comments>http://blog.smartit.se/2008/12/05/the-art-of-teaching/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 12:33:45 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Teaching]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[project organization]]></category>

		<guid isPermaLink="false">http://fekberg.wordpress.com/?p=41</guid>
		<description><![CDATA[The Art of Teaching
Filip Ekberg
filip.ekberg@bth.se
Abstract
A teacher knows that there are no straight answers on how to teach. There are multiple ways giving people new information and helping them adapt this in their current work. One of the preferred learning method by me is the Problem Based Learning, I will take up more about this in [...]]]></description>
			<content:encoded><![CDATA[<p>The Art of Teaching</p>
<p>Filip Ekberg<br />
filip.ekberg@bth.se</p>
<p>Abstract</p>
<p>A teacher knows that there are no straight answers on how to teach. There are multiple ways giving people new information and helping them adapt this in their current work. One of the preferred learning method by me is the Problem Based Learning, I will take up more about this in the upcoming topics. It’s also very important to take the age of the student in mind, how do they actually see on you as a teacher and does your and their age really matter?</p>
<p>1. Introduction</p>
<p>By passing on knowledge to new generations we somewhat evolve into a new and different kind life form. This not being as deep as it sounds, every day we somehow pass knowledge to someone. It might be the neighbor, a child, a sibling, a parent or anyone else for that matter.<br />
The important thing to remember is that all new or old knowledge is dangerously important to pass on to those concerned. There are a million ways of teaching something, not all of them are good and not all of them are bad, being old or being young doesn’t matter, all the age gives us is perspective and understanding of how to pass on knowledge and whom to give it to.<br />
By viewing the aspects of teaching, who needs to know what to be able to survive, complete a task or just continue living their life. Of what importance is all the facts, does one give the window of failure or does one give all the fact so that there is nothing left to learn?</p>
<p>2. Different generations</p>
<p>This might actually be a sensitive spot to touch, but I’ll be short in these words. There is actually a big difference between teaching 2 different generations. Imagine having a student which was born somewhere around 1960 and a student who was born 1980, depending on the age of the student and the age of the teacher, both these persons will take the information in two whole different ways.<br />
If we would’ve taken me as a teacher example, I’m born 1987 which makes me not very old for being a teacher. Some of my students today are actually a lot older than me, which might give in to complications.<br />
The different generations doesn’t only differ in age but in the attitude and the way of learning. A person born in the 1960:ies might have a harder time actually learning new things than someone born in the 1980, this is because, when this text was written it was the year 2008 which makes someone born in the late 1980:ies somewhere around 20 – 25. In this age, you have much easier to learn and take in new information.<br />
Now this does of course not mean that someone born in the 1960:ies is  stupid, rather that there are a big different and when teaching a group with a lot of different generations, this has to be taken into mind when planning a course.<br />
Take another example such as a work place where your co-workers are much older, being young you rarely have anything to say on a work place where the stuff have been done in a certain way for very long.<br />
So when trying to teach an older co-worker, you really need to sell the new information so that the older generation will be more interested.<br />
But going back to the topic of teaching in a class room, it might be a benefit of being older, because older generations have much easier to focus and having a different mindset which will help them succeed.<br />
It’s very important to respect each other, despite the age difference, if a younger person knows something that the older one doesn’t, it’s very important that the senior gives the younger person a chance to actually come forth and tell the information, that might in fact help production or whatever the work space might need.</p>
<p>3. Teaching differentials</p>
<p>There are a lot of different ways of teaching and what should be kept in mind when talking about different methods and where they apply is that everyone is different. I might not find it as amusing as you would, if I were forced to be taught with the old style teaching methods.<br />
Thus, as stated in the upcoming topics, there are benefits of the both methods and there are of course a lot more out there, but the ones that you mostly see in action, would be these two.</p>
<p>3.1. Problem Based Learning</p>
<p>I would certainly say that PBL; Problem Based Learning, is my favorite method of learning. Ever since high school this has been a method that I’ve worked with.<br />
The principles are that a student is given an assignment and there are known factors of failure which will somehow help the student learn what is necessary. After working with the problem for an amount of time, the solution will somewhat appear and the student has learnt something new.<br />
There’s also another aspect of this, or rather, another explanation. Let’s take implementation of the sorting algorithm quicksort as an example. This is a fairly hard algorithm to master and it requires some base knowledge in the field. So when given this assignment, the first obvious part from the teachers perspective is that the student will somehow search for information about the algorithm.<br />
Using internet or a special course literature, both should work very well. This gives the student an opportunity to master this assignment on his or hers own means.<br />
When all the information is collected and the next phase in the learning process begins, which in a programming line of work would be to put up a structure of your software, in this case the software won’t be huge but having a pattern when working is always good, no matter the size.<br />
As a result of this method, the student will have taught him or herself something new and by the individuals own needs.</p>
<p>3.2. Old Style Learning</p>
<p>As a matter of fact, the “Old style” in from my point of view might not be what you would suggest as an older style. And I am not talking about the old school tutoring where the teachers would be rude and make students learn by force and learn by fear.<br />
In my eyes the old style would be where all the answers are somewhat given and there is no room for self teaching or in any way, a path given where the student can choose to learn just what is needed or learn so much more.<br />
This old style can be seen at many high schools throughout, in my experience, Sweden. Now, the old style, what exactly defines this and are there any benefits? Well to start off, the old style learning method is where the students are put down at a desk, everyone directed to a whiteboard, and the teacher is using a pattern of teaching, where the pattern repeats itself. The old style pattern is when the teacher enters the room, greets the students, and starts talking and then when a question is stated an answer will be provided directly.<br />
Now this point of view might be a little bit dull and it certainly has its good parts, they are just somewhat harder to find than the good ones in a problem based situation.<br />
We have to keep in mind that everyone learns differently and that it’s important to give everyone what is needed to succeed. Thus, this method works in some cases but I would say that it wouldn’t work in most cases.<br />
A benefit of the problem based learning system which the old one lacks is that you give a broader room for questions and thoughts and it’s fair to say that it requires a totally different mindset and maturity.</p>
<p>3.3. Which is best?</p>
<p>Giving an answer to that question would be somewhat impossible. Just not because everyone differs from each other so much, but in some situations I would also prefer to be tutored using the old style method.<br />
The assignment stated in the PBL-example a couple of words back is a great example of how you can absorb new technology and new point of views. Programming itself is very broad and there are hardly any similar solutions out there. And the quicksort implementation sure is a defined structured algorithm but it can be implemented in so many different ways, it doesn’t matter if there are fewer rows or more rows, and they are just all different.<br />
Which in the end would make you to consider how others are implementing it, what are the benefits?<br />
Using the old style method, the tutor would just present some ways of implementing it and not giving you as a coder any room for own thoughts. A teaching method is always abstract in my eyes, you can’t tell someone to just go with a method, because “implementing” PBL differs from time to time.</p>
<p>4. Team work is important</p>
<p>You might think “What does Team work has to do with everything?”; Well actually team work has everything to do with learning. By being a tutor on various programming sections I’ve reached to the conclusion that team work is the most important part of learning and teaching. Now, team work isn’t all important only in the case of teacher to student teaching. This is also very important when we talk about teaching in a workspace.<br />
Since I generally work as a programmer, the examples of programming workspaces suits me the best, so here goes. Imagine having a workspace where there are 10 – 20 developers, 5 graphical interface programmers and a couple of designers. These all parts need to co-operate for the development to work. If some of the staff has knowledge that someone else doesn’t, it’s very important that if this knowledge will help the company produce more, then this person needs to convey this to the rest of the staff. This is where the team work is important, if someone on the staff feels insecure with conveying the knowledge; this person is probably not right for the position.<br />
I always say that when I work somewhere, I don’t want to be the brightest and the person with the most experience, this is because I want to learn, learning is very important and knowledge is worth a lot.<br />
And if you’d come to a workspace where people is unwilling to co-operate, sure this workspace lacks team work and this will be disadvantage when you want to learn and grow professionally.</p>
<p>5. Sharing is caring</p>
<p>Not only does sharing rime with caring but it goes very much hand in hand, almost every time that is. In this case, sharing knowledge to your co-workers, students and family is very important. Especially when you work as a teacher, the sharing part is not only important but it’s a factor for you, keeping this job.<br />
I’ve met teachers who felt threatened by me as a somewhat quick learner and bright student, not to sound too self-righteous this was actually a problem for me when I went to high school. I had teachers that, somehow, felt threatened by my knowledge and therefore didn’t want to share new knowledge with me.<br />
This is a dangerous way for thinking and teaching, you always need to take the student, no matter if it’s a co-worker or an actually school student, you always have to see the people you are tutoring new things, to be your student.<br />
And a student is to be handled with care; your personality will in the end reflect in this student and will show everyone, how good of a teacher you are. Of course some people like to learn themselves, but, put your mind around this, initially how do you give someone inspiration? It’s by showing the person what skills you have and maybe how you’d do some things.<br />
Sharing knowledge is in the end a vital factor for evolution, what if Einstein or other important people for our evolution, wouldn’t share their findings? How would this affect our current living environment and our current ways for thinking?</p>
<p>6. Feeding answers is dangerous</p>
<p>However, when sharing information it’s very important that you do this correctly. As mentioned in the previous chapter, all people learn differently. This is probably one of the hardest parts by being a teacher; you need to find a common spot which almost all students like.<br />
Of course this is often impossible, thus there are more than one path to take and there are almost always presented two or more ways for the students.<br />
One important thing to always keep in mind is that you can never ever just give out an answer to a question without somehow providing a solid explanation or a proof why it works.<br />
Why you might ask, this is because when being a student, you are almost certain to always take the easiest path and not thinking clearly about consequences. By being spoon feed you will never really care about how or why the solution is what it is.<br />
And being a programming tutor, this part is very important, what if I were to give all the students the correct answers to all assignments, and tell them “Here are the answers, go find out why”. Maybe a couple of percent would actually find out why the answers are as followed but the majority wouldn’t. So to keep in mind is that when a solution is presented, always give out a good and pedagogic explanation to why.<br />
This topic actually doesn’t just apply to students, it’s also very important not to just give co-workers the answer and let them be happy about it. I know that sometimes I just want a quick answer, but when I actually encounter the problem the second time, and not knowing how to solve it, I regret not doing more research the last time.</p>
<p>7. Giving inspiration not motivation</p>
<p>Not to feed answers and giving inspiration is actually something that we can see go hand in hand. When you actually want to teach someone something you want to give the person inspiration and give them the mindset of wanting to learn.<br />
So why wouldn’t you want to give someone motivation? Motivation isn’t something that can just be handed out, actually motivation is something that I would say comes hand in hand with inspiration, when someone is inspired, the motivation might peek and giving co-workers and students inspiration on a regular basis might in fact help the persons succeed and somehow indirect force them to teach themselves.</p>
<p>8. When open source helps programming tutors</p>
<p>Talking about open source could be a completely separate paper and take up many pages of explaining why this is a good way of learning and working.<br />
First of all, what is open source? Open source is a way for providing your product open and free, not only the software itself but also the source code, which defines the business logic, the graphical programming and other aspects of the program. This is a definition from Google [3] on open source</p>
<p>“A program in which the source code is available to the general public for use and/or modification from its original design free of charge.”</p>
<p>This is actually interesting, companies, people and organizations giving out their source code for free, so how does this actually help a learning process? Well for starters, there are software available for development and making office work more easy and there are so many softwares out there that can and will help you learn new ways.<br />
The topic on open source now is very programming tutoring oriented and might not really be of interest if you work in a construction site. But think of it like this, what if there were some free ways to actually make your construction work easier?<br />
When teaching programming we often come to points where we do reference an open source project, Linux is one of those; Linux is a kernel for the GNU / Linux operative system. This kernel has from the start been open source and the community which uses it has always been very helpful and made this a better product.<br />
Now, working on a project like linux might not be very easy, but it does in fact give you knowledge, this is an very important time to take up that you always have space for new knowledge and you are never too old to be learning new things.<br />
Programming on linux or any other open source projects might require that you actually have some experience from the start but you will also gain so much from being a part of this process.</p>
<p>9. References</p>
<p>[1] David Axlund, VD Mailopages Sweden AB – There might not be any direct references in the text or quotes from David but he has given me a lot of inspiration when it comes to management and giving people knowledge.</p>
<p>[2] Filip Ekberg – I have myself in this text as a reference because a major part of it is from own life experience .</p>
<p>[3] www.google.com http://www.google.se/search?hl=sv&amp;q=define%3A+open+source&amp;meta= 2008-12-05 – Definition of Open Source</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2008/12/05/the-art-of-teaching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Polymorphism – A Practical Example</title>
		<link>http://blog.smartit.se/2008/11/13/polymorphism-a-practical-example/</link>
		<comments>http://blog.smartit.se/2008/11/13/polymorphism-a-practical-example/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 17:01:38 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[programming architecture]]></category>

		<guid isPermaLink="false">http://fekberg.wordpress.com/2008/11/13/polymorphism-a-practical-example/</guid>
		<description><![CDATA[Classes, inheritance and polymorphism can sometimes be somewhat hard to understand. So a practial example suits many well. Therefore this will be a tutorial where i will touch the areas of classes, pointers, inheritance and polymorphism.
So to just clearify some expressions i will add a little dictionary at the top:
Class     A [...]]]></description>
			<content:encoded><![CDATA[<p>Classes, inheritance and polymorphism can sometimes be somewhat hard to understand. So a practial example suits many well. Therefore this will be a tutorial where i will touch the areas of classes, pointers, inheritance and polymorphism.</p>
<p>So to just clearify some expressions i will add a little dictionary at the top:</p>
<p><strong>Class     <br /></strong>A class can somewhat be seen as a blueprint of your object. I.e. having a blueprint for a building, then this would be the class. Then a Constructor would build this to become an actuall touchable object.</p>
<p><strong>Inheritance     <br /></strong>When you inherit something you can think of it more like you extend this thing. I.e. having a Car and then having a Sports Car where there are some new variables to it. The Sports Car is actually a Car but it’s also extended with new properties.</p>
<p><strong>Polymorphism     <br /></strong>This is taken from Wikipedia: <em>“In simple terms, polymorphism is the ability of one type, A, to appear as and be used like another type, B. In strongly typed languages, this usually means that type A somehow derives from type B, or type A implements an interface that represents type B”. </em><a href="http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming">Read more here</a></p>
<p><strong>Pointer     <br /></strong>For a pointer explenation <a href="http://fekberg.wordpress.com/2008/11/11/pointers-double-pointers/">look here</a></p>
<p>I will be using Visual Studio 2008 with the built in C++ compiler for the following examples.</p>
<p>A good practice will be to create a Bank, when you get a new assignment or just want to create something new, start by thinking about the structure, what actuall needs does this have? Well when creating a Bank i think to myself that i’d like to be able to create Bank Accounts, attatch these to People and you can go on and on.</p>
<p>But, for the example i will only go as far as creating a Bank, a Bank Account ( Abstract ) and a Student Bank account which is the only Bank account you can actually get.</p>
<p>So creating a simple diagram over the project, i got something like this:<a href="http://fekberg.files.wordpress.com/2008/11/diagram.jpg"><img title="diagram" style="border-right:0;border-top:0;display:block;float:none;margin-left:auto;border-left:0;margin-right:auto;border-bottom:0;" height="268" alt="diagram" src="http://fekberg.files.wordpress.com/2008/11/diagram-thumb.jpg" width="358" border="0" /></a> So now we have a Bank, Account and Student Account, what kind of variables do we need?</p>
<p><strong>Bank     <br /></strong>Bank Name    <br />Accounts</p>
<p><strong>Account     <br /></strong>Balance    <br />Interest    <br />Max Loan    <br />Account Holder</p>
<p><strong>Student Account     <br /></strong>Amount of Deposits    <br />Last Deposite Month</p>
<p>So the big difference between Account and Student Account is that the Student Account have different rules than Account and therefore calculate a lot of things differently. We won’t go through all the logics. There will of course be a window for you to evolve this application as you feel nessesary.</p>
<p>Now when we have a defined structure we can start by creating a new Project and it’s files. My project will be called Bank and the following files will be placed in it:</p>
<ol>
<li>main.cpp</li>
<li>Bank.h</li>
<li>Bank.cpp</li>
<li>BankAccount.h</li>
<li>BankAccount.cpp</li>
<li>StudentAccount.h</li>
<li>StudentAccount.cpp</li>
</ol>
<p>When all my files are created a start by definint my program entry point, this being my main. <strong><em>Notice that i will be posting code snippets as pictures, because you should Write this yourself and not copy my code!</em></strong></p>
<p><a href="http://fekberg.files.wordpress.com/2008/11/1.jpg"><img title="1" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="132" alt="1" src="http://fekberg.files.wordpress.com/2008/11/1-thumb.jpg" width="188" border="0" /></a> </p>
</p>
<p>We prepare for an input/output stream by including &lt;iostream&gt; and setting using namespace std;</p>
<p>Now the next part is to define the Bank.h We need an appropriet constructor, desctructor and some access methods, remember to never open up member variables publicly!</p>
<p>The #ifndef part is important for the compiler, we dont want to define our header file more than once, because that is not nessesary!</p>
<p><a href="http://fekberg.files.wordpress.com/2008/11/2.jpg"><img title="2" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="376" alt="2" src="http://fekberg.files.wordpress.com/2008/11/2-thumb.jpg" width="439" border="0" /></a> </p>
<p>I assume all the parts are clear except the last one, read more about how that pointer type works in the previous post here on my wordpress.</p>
<p>The implementation itself will be up to you, i will only be showing the structure, header-files and some code from main and where polymorphism is concerned!</p>
<p>The next file to create would be the BankAccount, remember to add #include “BankAccount.h”&#160; to Bank.h when it has been done. Otherwise the BankAccount *accounts array will fail because undefined symbol.</p>
<p>Back to the third file, the BankAccount.h this is how i would structure it:</p>
<p><a href="http://fekberg.files.wordpress.com/2008/11/3.jpg"><img title="3" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="437" alt="3" src="http://fekberg.files.wordpress.com/2008/11/3-thumb.jpg" width="466" border="0" /></a> </p>
<p>The part to look deeply on here is the Deposite method, watch closely, it’s defined as followed: virtual void Deposite(double amount) = 0; So this method is expected to be overrided in a inherited class and it has the return type of void and an in parameter of the type double.</p>
<p>Now the next file to create is the StudentAccount.h where we will be deriving from BankAccount.</p>
<p><a href="http://fekberg.files.wordpress.com/2008/11/4.jpg"><img title="4" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="356" alt="4" src="http://fekberg.files.wordpress.com/2008/11/4-thumb.jpg" width="466" border="0" /></a> </p>
<p>So the following class StudentAccount is extending a class called BankAccount. So this means that StudentAccount is a BankAccount with extended properties and/or overrided functions.</p>
<p>Now, look closely again, here we have the virtual void Deposite part again, but without the =0, so this means we will be creating a definition for this function.</p>
<p>Also the Amount of Deposits and Last Deposit Month is just there to simulate some properties that might be nessesary to do something on a student accont. In my case this is for the Deposite. A Student Can’t deposite money more than three times per month, this is because a student gets 2% interest everytime they deposite money.</p>
<p>This is my Constructor for StudentAccount</p>
<p><a href="http://fekberg.files.wordpress.com/2008/11/5.jpg"><img title="5" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="145" alt="5" src="http://fekberg.files.wordpress.com/2008/11/5-thumb.jpg" width="425" border="0" /></a> </p>
<p>As you can see, we pass the Variables Owner and Deposite back to the constructor of the base type, being BankAccount.</p>
<p>Now this is how my Deposite Method is implemented:</p>
<p><a href="http://fekberg.files.wordpress.com/2008/11/6.jpg"><img title="6" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="410" alt="6" src="http://fekberg.files.wordpress.com/2008/11/6-thumb.jpg" width="400" border="0" /></a>&#160;</p>
<p>Now the last think i want you to look at, is my final Main:</p>
<p><a href="http://fekberg.files.wordpress.com/2008/11/7.jpg"><img title="7" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="430" alt="7" src="http://fekberg.files.wordpress.com/2008/11/7-thumb.jpg" wi</p>
<p>dth="450" border="0" /></a> </p>
</p>
<p>I want you to try and create all the nessesary functions in Bank.cpp, BankAccount.cpp and in StudentAccount.ccp to get the following output from this Main.cpp:</p>
<p><a href="http://fekberg.files.wordpress.com/2008/11/8.jpg"><img title="8" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="333" alt="8" src="http://fekberg.files.wordpress.com/2008/11/8-thumb.jpg" width="437" border="0" /></a> ‘</p>
<p>I would happily answer any questions about this project. <a href="http://frw.se/Bank.rar">A link to the complete source code is here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2008/11/13/polymorphism-a-practical-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pointers &amp; Double Pointers</title>
		<link>http://blog.smartit.se/2008/11/11/pointers-double-pointers/</link>
		<comments>http://blog.smartit.se/2008/11/11/pointers-double-pointers/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 19:50:18 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[heap]]></category>
		<category><![CDATA[pointers]]></category>
		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://fekberg.wordpress.com/?p=4</guid>
		<description><![CDATA[Definitions
First off, we need to clearify what a some of the expressions i will use mean. These are the following expressions:

Stack
Assuming that you know about a computer having RAM ( Random Access Memory ) which allows you to store information and have this accessable faster than you would on a secondary memory like a harddrive [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Definitions</strong><br />
First off, we need to clearify what a some of the expressions i will use mean. These are the following expressions:<br />
<strong><br />
</strong><span style="text-decoration:underline;"><em>Stack</em></span><br />
Assuming that you know about a computer having RAM ( Random Access Memory ) which allows you to store information and have this accessable faster than you would on a secondary memory like a harddrive and/or cd-rom.</p>
<p>When a program is executed there is a part in the memory reserved for this application to use, this &#8220;space&#8221; is called the Stack; The stack is always the same size and it&#8217;s not possible to change it&#8217;s size on any way.</p>
<p><em><span style="text-decoration:underline;">Heap</span><br />
</em>The Heap is also a &#8220;space&#8221; on your memory, actually it&#8217;s all the memory not allocated as a stack. So when your stack is defined, everything else can be expressed as the Heap.</p>
<p><strong>Pointers<br />
</strong>What is a pointer really? A pointer is a globally used expression to reference that your somewhat &#8220;point&#8221; to something. See the following illustration</p>
<p><img class="image" src="http://frw.blogg.se/images/2008/pointer_1_21071735.png" alt="p1" /><br />
On this image we have something that we point to, let&#8217;s call A our Object. So having A as the actualy object, play with the thought that B and C isnt there, and there are no pointers to it.</p>
<p>This would infact mean that we had A allocated on the <em>Stack. </em>When does this become a problem? So play with the thought you have a really big information base such as a User Layer where you store a lot of data on each user. Then havnig a big register on all the people attending a course would take up somewhat a bigger space than we have free.</p>
<p>When is is an issue, we can use a pointer, to reference to this object. You can of course point to an object that you have on the stack, but that&#8217;s not. afaik, what it&#8217;s initially intended for.</p>
<p>So we tell our program that we want to create a Pointer, this pointer will in fact be stored on the stack, but a pointer only takes up 4 bytes so this wont be a problem.</p>
<p>After creating the pointer, we create the object itself and have the pointer B point to this.</p>
<p><strong>Pointer, Objects s &amp; Arrays</strong><br />
Assuming you know about some object orientation and how an object is constructed i will not go in to this very deeply. I.e. we have a class called Person and we want to create somewhat a register over students attending a course, what we initially want to do is create an object array, where we can store all our persons, using c++, as i will do in the following examples you would write something like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Person *attendingStudents = new Person[size];</div></td></tr></tbody></table></div>
<p>Where size is equal to the max amount of students.</p>
<p>Running this code, the constructor of Person will be runned as many times as the size of the array attendingStudents. <span style="text-decoration:underline;">How is this a problem?</span> This becomes a problem when we dont want to run the default constructor and allocate the object size  as many times as the total array size, this has too much overhead.</p>
<p>First of all, how does this look in memory?<span style="text-decoration:underline;"> </span></p>
<p><img class="image" src="http://frw.blogg.se/images/2008/pointer_2_21073486.png" alt="p2" /></p>
<p>On adress 0 to adress 3 wnicn means 4 bytes; every memoy block is 4 bytes; the pointer attendingStudents is allocated and on that area a 4 byte long adress is stored which in our case is 84. The size of the given Person object is not given but just play with the thought that its 4 bytes and the size is 10 this would mean the total size of the Person array would be 10 * 4 = 40 Bytes going from the address 84 to 124.</p>
<p>However, let&#8217;s say that the Person object takes up 4 times as much so it takes up 16 bytes per Person object, this would result in 16 * 10 = 160 bytes, going from address 84 to 244. Now, there is a big overhead if we dont use all the persons and it would be stupid to call the constructors twice.</p>
<p>So, how about, we just point to something that we know is a pointer, and then let this poitner take care of the rest? But we just initialize the first step?</p>
<p><strong>Double pointers<br />
</strong>Thjis is were double pointers comes in handy, look at the following code:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Person **attedningStudents = new Person*[size]:</div></td></tr></tbody></table></div>
<p>This code is not as straight forward to look at, as the pervious one, but it basically means, </p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Person **attendingStudents</div></td></tr></tbody></table></div>
<p>  = Create a reference, to a pointer, what is a pointer? A pointer is something that will in the end point to a data type, so what we do here is saying that Point to a Pointer, this pointer will eventually have the data type Person.</p>
<p>Just to clearify, a pointer to an array, initially points to the first index in that array. So after creating the Pointer to a Pointer we tell it to point to a new list of Pointers, the amount of pointers to create is the same as the digit in size.</p>
<p>This might not make any sense, but take a look at the following</p>
<p><img class="image" src="http://frw.blogg.se/images/2008/pointer_3_21074362.png" alt="p3" /></p>
<p>Initally these pointers don&#8217;t point to anything at all so what we can do is: attendingStudents[i] which will take us to the adress 84 and then create an object on this index by doing this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">attendingStudents[i] = new Person();</div></td></tr></tbody></table></div>
<p>Why is this method better than the one before? Well this assures that we Only have the 11 pointers which takes 4 bytes per pointer. 1 pointer on the stack, referencing 10 pointers on the stack. When does this give us overhead? This gives us a 4 byte overhead when we start creating our Persons. But the execution time saved and just given 4 bytes ovearhead per pointer, this is a preffered method by me.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2008/11/11/pointers-double-pointers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Importance of good Architecture, Structure and Patterns</title>
		<link>http://blog.smartit.se/2008/08/22/importance-of-good-architecture-structure-and-patterns/</link>
		<comments>http://blog.smartit.se/2008/08/22/importance-of-good-architecture-structure-and-patterns/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 21:54:08 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[programming architecture]]></category>

		<guid isPermaLink="false">http://fekberg.wordpress.com/?p=6</guid>
		<description><![CDATA[Often when developing software such as websites, windows ( or any other operative system for that matter ) programs, the begining of the progress is quite simple; you have your ideas and may have some thoughts about how to implement everything. But what often is forgot when developing software is the importance of thinking ahead, [...]]]></description>
			<content:encoded><![CDATA[<p>Often when developing software such as websites, windows ( or any other operative system for that matter ) programs, the begining of the progress is quite simple; you have your ideas and may have some thoughts about how to implement everything. But what often is forgot when developing software is the importance of thinking ahead, thus, planning for a larger software that you have in mind.</p>
<p>For an example, when i started developing SmartIT Invoice i thought of it as a software that would generally help me organize my small amount of invoices. But as the years pass my company grows bigger and bigger and once im up to n-numbers of invoices, a simple List View won&#8217;t be sufficient. Therefore after implementing my Invoice software, i started thinking about how i could change everything and structure the code for helping me in the future. I had in mind that i might not always want to use the Windows Graphical Interface for input and output so as i always do, i seperate the Design code from the Logical Code. This meaning that my application has three layers. Them being:</p>
<ul>
<li>Application Layer, code for display, handling window events</li>
<li>Logic data layer, database connections, objects</li>
<li>Data layer, this being the database with functions, views and procedures</li>
</ul>
<p>By having these three layers i can easily change one of the layers without changing the next. Of course this is not entierly true, i would have to change some parts in the Logic Data Layer if i changed the DBMS.  I would however not have to change that much if i just changed the behaviour of a Stored procedure.</p>
<p>Again takng my Invoice softwre as an example, i recently released a software called Webexpress.nu which allows customers to create their own website and for this i need somewhat of a payment system. Of course using Credit card payments is nice and easy but not entierly nessesary. So by just adapting my Webste to the current Logic Data Layer of my SmartIT Invoice software, i could easily get an intergration that allowed me to create customer invoices that pops up on the user account, when they are online on the page of course and even directly to my software, withouth any adjustments in the Data Layer or in my Windows Software.</p>
<p>This proves the point that well structured code and seperate layers will help you along the way of program development.</p>
<p>As a side note the Data Layer in this case is a Windows DLL with .NET 3.5 code which makes it even easier to implement when the website itself is asp.net with .net 3.5.</p>
<p>There are a lot of good design guidelines out there which will help you structure your software better and help you understand how to always follow a pattern. A pattern doesn&#8217;t, in my point of view, have to be a pattern like Singelton etc, it can by any means be a way for yourself to regocnize your own code, thus following a pattern. Example, i often tend to use m_ before member variables and write all functions and access methods with a capital letter.</p>
<p>Have fun programming!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2008/08/22/importance-of-good-architecture-structure-and-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big O-notation</title>
		<link>http://blog.smartit.se/2008/08/18/big-o-notation/</link>
		<comments>http://blog.smartit.se/2008/08/18/big-o-notation/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 21:55:00 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Algorithms & Data structures]]></category>
		<category><![CDATA[big o-notation]]></category>
		<category><![CDATA[merge sort]]></category>

		<guid isPermaLink="false">http://fekberg.wordpress.com/?p=8</guid>
		<description><![CDATA[So starting school in a couple of weeks and being told that you wont get any &#8220;allowance&#8221; from the state makes you think twice about your current situtation. Not that this has anything ( directly  ) to do with o-notation. However this is how i forced myself into learning it. I have to re-take an [...]]]></description>
			<content:encoded><![CDATA[<p>So starting school in a couple of weeks and being told that you wont get any &#8220;allowance&#8221; from the state makes you think twice about your current situtation. Not that this has anything ( directly  ) to do with o-notation. However this is how i forced myself into learning it. I have to re-take an exam in Algorithms and Datastructures this upcoming week and i want to share my experience in big o-notation.</p>
<p>So basicly we have an array, a list of some sort and somehow we need to go through each element in this list. Having &#8216;n&#8217; elements we need to create some kind of look like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">void walkList(int[] numbers)<br />
{<br />
for ( int i = 0 ; i &amp;lt; numbers.lenght(); i ++ )<br />
{<br />
print numbers[i];<br />
}<br />
}</div></td></tr></tbody></table></div>
<p>Now this will print all the elements contained in the list of numbers. Lets look at this from a time complexity way, 4 constant operations these being:</p>
<ul>
<li>function input</li>
<li>int i assignment</li>
<li>i &lt; numbers check</li>
<li>increment</li>
</ul>
<p>And the loop will run &#8216;n&#8217; times meaning we have n + 4 this will give us O(n + 4), but constant access times are irrelevant talking about runtime so all we do is write O(n). O, ordor as it is pronounced, is a way of stating the time complexity.</p>
<p>Now lets say we need to process ths array in another way, play with the thought that we have this list of numbers and for each number we want to go through the list again. This would give us a nested loop and give the time complexity O(n^2). This meaning that we need to process the list twice for each item, hence n ^ 2.</p>
<p>Looking at a sorting algorithm like Merge Sort that first divides the list into 2 peices untill its at the last item, then merges them. We see the typical behavior of a log() with the base 2. So, the split / sort part is basicly log(n) while the merging part is n and log (n) * n = nlog(n) which is slower than log(n). There are however no &#8220;standard&#8221; sort algorithms that can do better than nlog(n), in a random case that is. Best case for i.e. bubblesort is log(n)  and worst case for bubblesort is log(n^2) which is slower than mergesort.</p>
<p><strong>Mergesort</strong></p>
<p><strong> </strong></p>
<p><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Merge_sort_algorithm_diagram.svg/300px-Merge_sort_algorithm_diagram.svg.png" alt="" /></p>
<p>When is time complexity nessesary? I would say that during all my years of programming, learning speed, size and other performance parts the hard way, i would say that this is a very good complement to fast calculate time complexity of your algorithm. You can be a very good programmer without knowing a lot about this. A lot of this is just something that a programmer knows how to handle without knowing O-notation. But as said, a good complement.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2008/08/18/big-o-notation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Objects, Objects, Objects!</title>
		<link>http://blog.smartit.se/2008/08/08/objects-objects-objects/</link>
		<comments>http://blog.smartit.se/2008/08/08/objects-objects-objects/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 19:55:36 +0000</pubDate>
		<dc:creator>Filip Ekberg</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[programming architecture]]></category>

		<guid isPermaLink="false">http://fekberg.wordpress.com/?p=10</guid>
		<description><![CDATA[By looking on everything in life as Objects is one of the benefits from doing object oriented programming. It doesn&#8217;t really matter if you master the technique or if you are in the beginners stage, just starting with object oriented programming will open up your eyes.
Seeing how objects change your perspective on both programming and [...]]]></description>
			<content:encoded><![CDATA[<p>By looking on everything in life as Objects is one of the benefits from doing object oriented programming. It doesn&#8217;t really matter if you master the technique or if you are in the beginners stage, just starting with object oriented programming will open up your eyes.</p>
<p>Seeing how objects change your perspective on both programming and other stuff in life, i&#8217;ve notied that when i wanted to learn something like animating in Flash, knowing object orientation helps. Not particulary with the animating, but with the thoughts on how i will structure my animations.</p>
<p>I.e. that i have to create a move, where a part in this move occures many times, repeatinly creating this scenes and moving them around is a fairly harsh work. Looking at it from an object oriented perspective you see that you have:<br />
A main film<br />
An object containging the scene</p>
<p>When needed, you just insert a new object of the scene and you never need to repeate the procedure of creating the scene.</p>
<p>Using Objects isn&#8217;t always good though, when you need to store the memory on other medias than the RAM you need it to be serialized, which is not handled to good by some languages such as PHP.</p>
<p>The basics of object orientation is easy to learn over a few minutes, when you try to look at everthing at a new perspective, the learning period will decrease.</p>
<p>Let&#8217;s say that you have a Car, this car has 4 wheels, 5 doors, 6 windows and so on. The doors got handles, the wheels got air in them and so on. Seeing all these parts as Objects is a good way to play with the thoughts of object orientation. See how i apply inheritage on a car:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">abstract class BasePart<br />
{<br />
    int m_ModelNr;<br />
    string m_Name;<br />
    public BasePart(int ModelNumber, string Name)<br />
    { <br />
         m_ModelNr = ModelNumber;<br />
         m_Name = Name;<br />
    }<br />
}</div></td></tr></tbody></table></div>
<p>Everytime you create something, the created part / object or wathever got a Model Number and a Name, just look at carparts or a coka cola bottle.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class Door : BasePart<br />
{<br />
    int m_DoorType;<br />
    int m_Weight;<br />
    int m_Code;<br />
<br />
    public Door(int DoorType, int Weight, int Code, int ModelNumber, int Name) : base(ModelNumber, Name)<br />
    {<br />
     ///.....<br />
    }<br />
}</div></td></tr></tbody></table></div>
<p>The codesnippet above shows the basics in object orientation, this is a Base Class which is Abstract, which means that you cannot create an object of it.<br />
The Door is derived from a BasePart because its a BasePart.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartit.se/2008/08/08/objects-objects-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
