<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.1" -->
<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/"
	>

<channel>
	<title>CodeUtopia</title>
	<link>http://codeutopia.net/blog</link>
	<description>Web development and other things</description>
	<pubDate>Sat, 05 Jul 2008 20:27:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<item>
		<title>Making working with DB records easier with a controller helper</title>
		<link>http://codeutopia.net/blog/2008/07/05/making-working-with-db-records-easier-with-a-controller-helper/</link>
		<comments>http://codeutopia.net/blog/2008/07/05/making-working-with-db-records-easier-with-a-controller-helper/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 20:27:59 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/07/05/making-working-with-db-records-easier-with-a-controller-helper/</guid>
		<description><![CDATA[The other day I noticed a pattern that repeats quite much in my code:

Take a parameter from the request, such as id
Query the DB for a record that matches the param
Redirect or throw a 404 exception if record was not found

Why do all this, when it could be simply a helper call?

A DB helper
Since I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I noticed a pattern that repeats quite much in my code:</p>
<ul>
<li>Take a parameter from the request, such as id</li>
<li>Query the DB for a record that matches the param</li>
<li>Redirect or throw a 404 exception if record was not found</li>
</ul>
<p>Why do all this, when it could be simply a helper call?</p>
<p><span id="more-115"></span></p>
<h3>A DB helper</h3>
<p>Since I&#8217;m using Doctrine, I&#8217;m simply calling my helper CU_Controller_Action_Helper_Doctrine. If you&#8217;re using Zend_Db or something else, you could call it Your_Controller_Action_Helper_Db or whatever.</p>
<p>The idea is to make the multi-line operation of taking a parameter, querying the db and checking the result into a single line operation.</p>
<p>For example&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #0000ff;">$id</span> = <span style="color: #0000ff;">$this</span>-&gt;_getParam<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'id'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$record</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">Doctrine</span>-&gt;<span style="color: #006600;">getRecordOrException</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Article'</span>, <span style="color: #0000ff;">$id</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Essentially, the above code would get an Article object with the ID from the parameter, or throw an exception if it wasn&#8217;t found, allowing you to, for example, display an error 404 page automatically.</p>
<h3>Implementation</h3>
<p>You can find source <a href="http://codeutopia.net/code/library/CU/Controller/Action/Helper/Doctrine.php">code for my implementation of a Doctrine helper at the svn</a>.</p>
<p>Note that it throws an exception of type CU_Exception_NotFound, which you may want to change to your own class.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/07/05/making-working-with-db-records-easier-with-a-controller-helper/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ideas for testing Zend Framework apps</title>
		<link>http://codeutopia.net/blog/2008/07/03/ideas-for-testing-zend-framework-apps/</link>
		<comments>http://codeutopia.net/blog/2008/07/03/ideas-for-testing-zend-framework-apps/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 16:52:24 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/07/03/ideas-for-testing-zend-framework-apps/</guid>
		<description><![CDATA[Here are some ideas I was thinking of for making testing Zend Framework (and Doctrine) based apps nice and easy.

PHP testing
Naturally, you&#8217;d first off use PHPUnit and Matthew&#8217;s work on Zend Framework request testing to write unit tests for your models, controllers and library code.
Testing library code should be relatively simple, since most of it [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some ideas I was thinking of for making testing Zend Framework (and Doctrine) based apps nice and easy.</p>
<p><span id="more-114"></span></p>
<h3>PHP testing</h3>
<p>Naturally, you&#8217;d first off use <a href="www.phpunit.de/ ">PHPUnit</a> and <a href="http://weierophinney.net/matthew/archives/182-Testing-Zend-Framework-MVC-Applications.html">Matthew&#8217;s work on Zend Framework request testing</a> to write unit tests for your models, controllers and library code.</p>
<p>Testing library code should be relatively simple, since most of it probably works more like &#8220;traditional&#8221; code: It does not output html, does not access the DB and things like that.</p>
<p>Testing models and controllers is a more complex thing. Models quite likely will access the DB, so how to make testing them simpler?</p>
<p>First, you could use the in-memory SQLite adapter with PDO (new PDO(&#8217;sqlite::memory:&#8217;)) to create a database that won&#8217;t mess with anything external. Then, if you&#8217;re using a library like Doctrine, you can let it generate the database for you based on the models. You would also want to write some fixtures with some dummy data that you can use in your tests.</p>
<p>Since Doctrine&#8217;s models should work most of the time, you may not want to spend time writing tests for them, but if you provide any custom methods in your models, you might want to make sure they do what they are supposed to.</p>
<p>Controller testing can be the most difficult part, and this is where you may need to perform some refactoring if your design is not suitable for testing. For example, you may have a lot of logic in your controllers, which might be better off in your models or library code. Testing the whole idea of getting out the correct output or redirects may be difficult, but the Zend Framework test case stuff Matthew Weier O&#8217;Phinney has been working on should help a lot there.</p>
<h3>Other testing</h3>
<p>In addition to testing the stuff that happens on the server, you may want to test what&#8217;s actually going on on the client side of things.</p>
<p>For this, there&#8217;s <a href="http://jsunit.net/">JsUnit</a>, which is essentially similar as PHPUnit is for PHP but just for JavaScript. Also, there&#8217;s things like <a href="http://selenium.openqa.org/">Selenium</a>, which can automatically test a site in a browser to make sure they work correctly. I haven&#8217;t tried either of these though.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/07/03/ideas-for-testing-zend-framework-apps/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript Canvas charting/timeline example</title>
		<link>http://codeutopia.net/blog/2008/06/30/javascript-canvas-chartingtimeline-example/</link>
		<comments>http://codeutopia.net/blog/2008/06/30/javascript-canvas-chartingtimeline-example/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 14:46:53 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

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

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/06/30/javascript-canvas-chartingtimeline-example/</guid>
		<description><![CDATA[I was on holiday last week and haven&#8217;t been really able to think of anything really really interesting to write, so here&#8217;s something I made a while back: A Canvas-element powered chart/graph/timeline thing of my programming language skills, which I made as an excercise for making chart-type stuff with canvas.
I think the canvas element is [...]]]></description>
			<content:encoded><![CDATA[<p>I was on holiday last week and haven&#8217;t been really able to think of anything really really interesting to write, so here&#8217;s something I made a while back: A Canvas-element powered <a href="http://codeutopia.net/chart/">chart/graph/timeline thing of my programming language skills</a>, which I made as an excercise for making chart-type stuff with canvas.</p>
<p>I think the canvas element is starting to get quite feasible for charting, since it now works in Internet Explorer using the great <a href="http://excanvas.sourceforge.net/">ExplorerCanvas</a> script.</p>
<p>Feel free to use/take apart/break/something the canvas script in the example if you like. It should work out of the box if you just provide it with some custom data in a similar format as seen in the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/06/30/javascript-canvas-chartingtimeline-example/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Simple Photoshop-style layers using JavaScript</title>
		<link>http://codeutopia.net/blog/2008/06/23/simple-photoshop-style-layers-using-javascript/</link>
		<comments>http://codeutopia.net/blog/2008/06/23/simple-photoshop-style-layers-using-javascript/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 17:18:47 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

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

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/06/23/simple-photoshop-style-layers-using-javascript/</guid>
		<description><![CDATA[Today I wrote a small JavaScript class to display images layered on top of each other, in a similar manner as layers are shown in editors like Photoshop. 
I wanted to show my Dwarf Fortress to someone, but I didn&#8217;t just want to stack screenshots below each other like you&#8217;d usually do. Since dwarf forts [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wrote a small JavaScript class to display images layered on top of each other, in a similar manner as layers are shown in editors like Photoshop. </p>
<p>I wanted to show my <a href="http://www.bay12games.com/dwarves/">Dwarf Fortress</a> to someone, but I didn&#8217;t just want to stack screenshots below each other like you&#8217;d usually do. Since dwarf forts can span multiple depth levels, it would be pretty neat to be able to show the levels on top of each other, with transparency too.</p>
<p><a href="http://codeutopia.net/dwarf/">See it in action here</a>.</p>
<p>It&#8217;s relatively simple. You point it at a div which contains the images you want to make layers of, and a div where it should display the controls, and it does the rest.</p>
<p>If you want to use it, feel free. Just copy <a href="http://codeutopia.net/dwarf/layers.js">the script file</a> and write some similar CSS and HTML as shown in the example page. You probably won&#8217;t need all of the CSS styles, just take note of the #controls .selected one, as &#8220;selected&#8221; is the class used for highlighting the selected layer. Note that you will need to link to the Yahoo UI libraries, as it is used in some places in the code.</p>
<p>You could probably use that for a JS based image editor, to name other uses than fortress showcases. <img src='http://codeutopia.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/06/23/simple-photoshop-style-layers-using-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dependency Injection, or how to make simple concepts sound difficult</title>
		<link>http://codeutopia.net/blog/2008/06/21/dependency-injection-or-how-to-make-simple-concepts-sound-difficult/</link>
		<comments>http://codeutopia.net/blog/2008/06/21/dependency-injection-or-how-to-make-simple-concepts-sound-difficult/#comments</comments>
		<pubDate>Sat, 21 Jun 2008 13:15:26 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/06/21/dependency-injection-or-how-to-make-simple-concepts-sound-difficult/</guid>
		<description><![CDATA[You may have heard of Dependency Injection. It&#8217;s essentially a way to remove implementation dependencies from classes, or &#8220;the process of supplying an external dependency to a software component. It is a specific form of inversion of control where the concern being inverted is the process of obtaining the needed dependency.&#8221; as Wikipedia puts it.
Sounds [...]]]></description>
			<content:encoded><![CDATA[<p>You may have heard of Dependency Injection. It&#8217;s essentially a way to remove implementation dependencies from classes, or &#8220;the process of supplying an external dependency to a software component. It is a specific form of inversion of control where the concern being inverted is the process of obtaining the needed dependency.&#8221; as Wikipedia puts it.</p>
<p>Sounds complex? Yep. Is it complex? No. You might&#8217;ve even used it without knowing about the name.</p>
<p><span id="more-111"></span></p>
<h3>Three styles</h3>
<p>Let&#8217;s take a look at the <a href="http://martinfowler.com/articles/injection.html#FormsOfDependencyInjection">three main styles of Dependency Injection, as listed by Martin Fowler</a>, the simplest first:</p>
<ul>
<li>Constructor injection</li>
<li>Setter injection</li>
<li>Interface injection</li>
</ul>
<p>Let&#8217;s say we have a class which uses another class to do some task:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> Example
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$_helper</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;_helper = <span style="color: #000000; font-weight: bold;">new</span> MyHelper<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> doSomethiong<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">foo</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> MyHelper_Interface
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyHelper implements MyHelper_Interface
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066;">echo</span> <span style="color: #ff0000;">'Foo'</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>We&#8217;ll modify this class to use the three styles of DI&#8230;</p>
<h3>Constructor injection:</h3>
<p>The simplest of them all, simply uses a constructor parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> Example
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$_helper</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span>MyHelper_Interface <span style="color: #0000ff;">$helper</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;_helper = <span style="color: #0000ff;">$helper</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* rest of the class is here */</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Basically you just pass the helper implementation in the constructor. Could it be simpler than that?</p>
<h3>Setter injection:</h3>
<p>You might already guess this based on the above&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> Example
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$_helper</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setHelper<span style="color: #66cc66;">&#40;</span>MyHelper_Interface <span style="color: #0000ff;">$helper</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;_helper = <span style="color: #0000ff;">$helper</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* rest of the class is here */</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>So to use Setter injection, you simply need to define a way to set the implementation of the helper with a setter.</p>
<h3>Interface injection</h3>
<p>Finally, the most complex way of doing dependency injection, interface injection.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">interface</span> iInjectHelper
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> injectHelper<span style="color: #66cc66;">&#40;</span>MyHelper_Interface <span style="color: #0000ff;">$helper</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Example implements iInjectHelper
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #0000ff;">$_helper</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> injectHelper<span style="color: #66cc66;">&#40;</span>MyHelper_Interface <span style="color: #0000ff;">$helper</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;_helper = <span style="color: #0000ff;">$helper</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* rest of the class is here */</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This is pretty much an interfaced version of the setter injection method.</p>
<h3>In closing</h3>
<p>So while Dependency Injection is often explained in long articles and so, it&#8217;s a quite simple concept.</p>
<p>By using these three methods, we remove the dependency of MyHelper from the Example class. Instead, depending on the environment, we could provide a different implementation of the helper, for example a mock object for running tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/06/21/dependency-injection-or-how-to-make-simple-concepts-sound-difficult/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Put Excel on the net with ASP.NET</title>
		<link>http://codeutopia.net/blog/2008/06/18/put-excel-on-the-net-with-aspnet/</link>
		<comments>http://codeutopia.net/blog/2008/06/18/put-excel-on-the-net-with-aspnet/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 07:39:50 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

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

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

		<category><![CDATA[Web Applications]]></category>

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/06/18/put-excel-on-the-net-with-aspnet/</guid>
		<description><![CDATA[Remember when I introduced the idea of cloning Google Spreadsheets with ASP.NET using Excel?
Well, it turns out to be a perfectly feasible task, and I have a working prototype too!

The idea and the implementation
The idea was to look at Microsoft Excel COM interop with ASP.NET - I had seen examples of generating spreadsheets using interop, [...]]]></description>
			<content:encoded><![CDATA[<p>Remember when I introduced <a href="http://codeutopia.net/blog/2008/06/09/google-spreadsheets-aspnet-and-excel/">the idea of cloning Google Spreadsheets with ASP.NET using Excel</a>?</p>
<p>Well, it turns out to be a perfectly feasible task, and I have a working prototype too!</p>
<p><span id="more-110"></span></p>
<h3>The idea and the implementation</h3>
<p>The idea was to look at Microsoft Excel COM interop with ASP.NET - I had seen examples of generating spreadsheets using interop, but it seemed no one had actually done anything more.</p>
<p>Since I haven&#8217;t really done any ASP.NET stuff from the ground up, and it was mostly cobbled together to just see if it could be done, so it involved software development methodologies such as &#8220;Copy and Paste&#8221;. </p>
<p>There was initially a problem with talking to Excel, as the Windows version I&#8217;m using is in Finnish, and my Office 2007 is the English version. Every time I tried doing something to the spreadsheet, such as getting a value from a cell, it would throw an exception. Luckily some Googling gave me an answer to change the currently executing thread&#8217;s locale to en-US, which fixed it and let me continue.</p>
<p>Eventually I found ways to do all I needed: Getting and setting specific cells&#8217; values and their formulas. Then it was on to creating a JavaScript-based interface for it, which is essentially a very bare-bones inline editable table, which sends the modifications to the server with Ajax.</p>
<h3>A demonstration</h3>
<p>I sadly do not have a server which can run ASP.NET, and it is not actually a very good idea to run it on a live server for real users either due to things I&#8217;ll tell you about in a bit&#8230; however, here&#8217;s a screencast I made of it, which should give you an idea:</p>
<p><object id  ="flashMovie" codeBase ="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"  height   ="416"   width    ="640"   classid  ="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" VIEWASTEXT>   <PARAM NAME="FlashVars"          VALUE="csConfigFile=http://zomg.thegroup.fi/aspnet/webxcel_config.xml&#038;csColor=FFFFFF&#038;csPreloader=http://zomg.thegroup.fi/aspnet/webxcel_preload.swf">   <PARAM NAME="Movie"              VALUE="http://zomg.thegroup.fi/aspnet/webxcel_controller.swf">         <PARAM NAME="WMode"              VALUE="Window">   <PARAM NAME="Quality"            VALUE="best">   <PARAM NAME="SAlign"             VALUE="TL">   <PARAM NAME="Menu"               VALUE="FALSE">   <PARAM NAME="BGColor"            VALUE="FFFFFF">	   <EMBED id          ="EmbedflashMovie"       flashvars   ="csConfigFile=http://zomg.thegroup.fi/aspnet/webxcel_config.xml&#038;csColor=FFFFFF&#038;csPreloader=http://zomg.thegroup.fi/aspnet/webxcel_preload.swf"           src         ="http://zomg.thegroup.fi/aspnet/webxcel_controller.swf"                     quality     ="best"           bgcolor     ="FFFFFF"           width       ="640"           height      ="416"           pluginspace ="http://www.macromedia.com/go/getflashplayer" >	   </EMBED></OBJECT></p>
<p>From the screencast, you can see how it first loads the Excel spreadsheet&#8217;s current data into the grid, and then when edits are made, any changes that happen to the values in the spreadsheet are reflected in the grid as well.</p>
<h3>So is this a Google Spreadsheets killer?</h3>
<p>Well&#8230; Maybe.</p>
<p>As you can see from the above, it is a feasible concept. However, it has several issues, because Excel is not a &#8220;server&#8221; type of application.</p>
<p>Excel is built as something that the user interacts with directly, as in a desktop application. If you typed a formula wrong, it would show you a popup and you&#8217;d close it and things like that. </p>
<p>If you type a formula wrong in the JS grid, it will go to Excel, which will display a popup&#8230; but it will have no one to close it. It will effectively <i>stop the whole app</i> with the pop: It will not reply to messages until the popup is closed, and any actions done before that will throw an exception.</p>
<p>In theory you could set up the server so, that it runs an application which would automatically click any popups Excel shows to close them&#8230; but I&#8217;m not sure if that would work out so well.</p>
<p><br/><br/><br />
Finally, <b>if you want to play with the code</b>, <a href="http://codeutopia.net/code/aspnet/Webxcel">the code for Webxcel is available in my SVN.</a> To run the code you&#8217;ll probably need Visual Studio 2005 Web Developer and Excel 2007. Run an instance of Excel first, and then access the webpage.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/06/18/put-excel-on-the-net-with-aspnet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Is web application development less challenging than desktop application development?</title>
		<link>http://codeutopia.net/blog/2008/06/16/is-web-application-development-less-challenging-than-desktop-application-development/</link>
		<comments>http://codeutopia.net/blog/2008/06/16/is-web-application-development-less-challenging-than-desktop-application-development/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 08:39:42 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Web Applications]]></category>

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/06/16/is-web-application-development-less-challenging-than-desktop-application-development/</guid>
		<description><![CDATA[I have heard several times that what I do is not &#8220;real programming&#8221; - web application development is supposedly less challenging than &#8220;proper&#8221; desktop application development. But is it really so?

Argumentation
The arguments are usually as follows:

Desktop languages are more difficult than those used for the web
Web applications aren&#8217;t as complex as desktop applications
It&#8217;s easier to [...]]]></description>
			<content:encoded><![CDATA[<p>I have heard several times that what I do is not &#8220;real programming&#8221; - web application development is supposedly less challenging than &#8220;proper&#8221; desktop application development. But is it really so?</p>
<p><span id="more-109"></span></p>
<h3>Argumentation</h3>
<p>The arguments are usually as follows:</p>
<ol>
<li>Desktop languages are more difficult than those used for the web</li>
<li>Web applications aren&#8217;t as complex as desktop applications</li>
<li>It&#8217;s easier to do a web-based user interface than a desktop UI, because HTML is easy</li>
</ol>
<p>Not to offend anyone, but I think saying any of the above three only shows that you are ignorant of what&#8217;s going on in todays web-development world. Sure, it might&#8217;ve been a couple of quickly hacked together Perl-scripts and some HTML back in the day, but it&#8217;s a different story today.</p>
<p>Let&#8217;s look at the arguments. </p>
<p>#1: Desktop apps can be written in C++ which is definitely a more complex language than what you&#8217;d typically use for web development, but in todays desktop world there are other alternatives, like C# and Java - both of which you can use for web development as well. You could use C++ for web too, but is it really suited for that?</p>
<p>#2: This point really depends on the size of the application. A simple website is not very complex, just like a simple desktop application is not complex, but I think some desktop developers don&#8217;t realize that many web-developers work on complex sites too. This argument might&#8217;ve been true a while ago, though. A lot of things like unit-testing, n-tier architechture etc. was not very common in web-development not so long ago, while they&#8217;ve been around on the desktop for a much longer time.</p>
<p>#3: Do you need to test a desktop application with <i>at least</i> 4 different Windows (or some other OS) versions to make sure it displays things the same in each? No? In the web-world, if you&#8217;re serious about your website, you want it to work correctly on at least Internet Explorer 6 and 7, Firefox, Safari and probably Opera too, despite its smaller user-base. In the desktop-world, you can also use a WYSIWYG editor to lay out your UI with much less problems than what you&#8217;d encounter on the web when doing that.</p>
<p>In addition to these, it should be considered that today to make a website you&#8217;re going to need at least <i>four</i> different languages! HTML, CSS, JavaScript and some server-side language, and SQL if you want a database. Do a desktop application, and you&#8217;ll need maybe one or two. Granted, HTML and CSS are not very complex, but you have to understand how to do things with them efficiently, how to work around browser bugs, and things like semantic markup etc.</p>
<p>Also, while discussing this with <a href="http://oss.jasoneisen.com/">Jason Eisen</a>, he mentioned that web applications have to be built with high performance on the mind, as they will have a lot of concurrent users. </p>
<h3>So is it really so?</h3>
<p>I&#8217;ve recently witnessed a very important web-based application developed by a big company with big money halt and crash because of too many concurrent users. I&#8217;m not sure of the exact numbers, but the estimates I heard were quite small for a web site. The application itself was written in JSP, and was basically for doing queries to an Oracle DB and producing different looking results from that. </p>
<p>If anything, the big company should&#8217;ve been able to push out an excellent web-based system, especially if web-development was so easy&#8230; but seeing how the app was <i>late</i> to begin with&#8230; </p>
<p>As far as I know, this company is very well versed in more traditional desktop client-server solutions and database applications. So seeing this, they should&#8217;ve aced the web application too, right? </p>
<p>Well, guess it isn&#8217;t as easy to develop a web application as you might think.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/06/16/is-web-application-development-less-challenging-than-desktop-application-development/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Good habits I learnt from Django</title>
		<link>http://codeutopia.net/blog/2008/06/13/good-habits-i-learnt-from-django/</link>
		<comments>http://codeutopia.net/blog/2008/06/13/good-habits-i-learnt-from-django/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 15:39:23 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

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

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

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/06/13/good-habits-i-learnt-from-django/</guid>
		<description><![CDATA[Django has various good features I&#8217;ve previously mentioned. While they can&#8217;t be taken out and applied to other languages like PHP right away, it also has some nice ways of doing things that can be taken and used elsewhere.
Let&#8217;s look at some good habits I took from Django and started using in PHP, that could [...]]]></description>
			<content:encoded><![CDATA[<p>Django has <a href="http://codeutopia.net/blog/tag/django/">various good features I&#8217;ve previously mentioned</a>. While they can&#8217;t be taken out and applied to other languages like PHP right away, it also has some nice ways of doing things that <i>can</i> be taken and used elsewhere.</p>
<p>Let&#8217;s look at some good habits I took from Django and started using in PHP, that could benefit you too.</p>
<p><span id="more-108"></span></p>
<h3>URL generation</h3>
<p>In Django, you can define a method called get_absolute_url to your models, which should return an absolute URL to the model in question. </p>
<p>You usually might just type the URLs manually, perhaps putting some variable from the record as a parameter to the URL, or if you&#8217;re using something like Zend Framework, you probably would be using the URL helper. In any case, you would be hardcoding some values in your views.</p>
<p>Using an URL generation method in the model is a great idea. It takes away this hardcoded feature, in case your URLs change, and they might. It can also reduce the clutter of your views when you don&#8217;t need to put params to urls in long syntax and such.</p>
<p>Here&#8217;s an example with Zend Framework and Doctrine:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> MyModel <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Record
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* the usual setUp and setTableDefinition stuff here */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getAbsoluteUrl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$helper</span> = Zend_Controller_Action_HelperBroker::<span style="color: #006600;">getStaticHelper</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Url'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$helper</span>-&gt;<span style="color: #006600;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">array</span><span style="color: #66cc66;">&#40;</span>
            <span style="color: #ff0000;">'module'</span> =&gt; <span style="color: #ff0000;">'example'</span>,
            <span style="color: #ff0000;">'controller'</span> =&gt; <span style="color: #ff0000;">'mycontroller'</span>,
            <span style="color: #ff0000;">'action'</span> =&gt; <span style="color: #ff0000;">'show'</span>,
            <span style="color: #ff0000;">'id'</span> =&gt; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">id</span>
        <span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">'default'</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Of course, it might be even better idea to use a named route and only passing in the ID or some other property of the record.</p>
<h3>Models to strings</h3>
<p>This is more of a small convenience than anything else, but I think it&#8217;s still a nice idea. Django encourages you to put __unicode__ methods in your models, which should return a human readable text representation of the record - similar to what you can do with PHP&#8217;s <a href="http://php.net/__toString">__toString</a>.</p>
<p>This is quite useful if you need to output textual representations of models, without necessarily knowing what kind of model you&#8217;re dealing with; if you don&#8217;t know what model it is, you don&#8217;t know what fields it has. By simply adding a method that outputs something meaningful, you can overcome this problem:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> MyModel <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Record
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">name</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>I think __toString is an often overlooked PHP feature. It isn&#8217;t really used anywhere, so people don&#8217;t think of it. In languages like C#, ToString is used more, starting from the Visual Studio IDE, to display useful representations of things.</p>
<h3>Application structure != URL structure</h3>
<p>Since I&#8217;ve been using Zend Framework a lot, I had already fallen into it&#8217;s way of thinking about URLs. By default, ZF gives you the following URL scheme: /module/controller/action. This means it&#8217;s very easy to get nice URLs without doing anything except naming your modules, controllers and actions in a fashion that makes the URLs look good.</p>
<p>In Django, there are no predefined URL behaviors. You will need to define all URLs by hand, and at first it felt that it must be a lot of work, but in reality it is not that much.</p>
<p>While Zend Framework&#8217;s way of giving you default URL behavior can speed up getting started, it can also make you think of your application in terms of your URL&#8230;</p>
<p><i>&#8220;I want this list of big robots fighting in space show up under /japan/big-robots/in-space, so I&#8217;m going to put it in the Japan module, under BigRobotsController&#8217;s inSpaceAction&#8221;</i></p>
<p>So while it would be quite obvious where the code for the URL is if you ever wanted to edit it, it might be a much better idea to create a CategoryController and add a listAction to it, which would take big-robots and in-space as parameters.</p>
<p>Creating different kinds of URLs like this is definitely possible in ZF, but especially beginning ZF-devs seem to be falling for the easy default URL handling.</p>
<h3>In closing</h3>
<p>I can say it is definitely useful to look into other frameworks and languages than the one you&#8217;re usually dealing with. There&#8217;s a lot of things you can learn from them.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/06/13/good-habits-i-learnt-from-django/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Page2Rss and Yahoo Pipes</title>
		<link>http://codeutopia.net/blog/2008/06/11/page2rss-and-yahoo-pipes/</link>
		<comments>http://codeutopia.net/blog/2008/06/11/page2rss-and-yahoo-pipes/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 08:16:52 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[general]]></category>

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

		<category><![CDATA[Web Applications]]></category>

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/06/11/page2rss-and-yahoo-pipes/</guid>
		<description><![CDATA[There are many RSS feeds that I&#8217;ve subscribed to, and some websites that I check often that don&#8217;t have feeds, for example to read comics. With all the stuff in the feeds, there&#8217;s also some things that I don&#8217;t want to see, such as newsposts in some comic feeds that I only read for the [...]]]></description>
			<content:encoded><![CDATA[<p>There are many RSS feeds that I&#8217;ve subscribed to, and some websites that I check often that don&#8217;t have feeds, for example to read comics. With all the stuff in the feeds, there&#8217;s also some things that I don&#8217;t want to see, such as newsposts in some comic feeds that I only read for the comic. It would be nice if I could have those inexistant feeds created and those useless posts filtered&#8230;</p>
<p><a href="http://page2rss.com">Page2Rss</a> and <a href="http://pipes.yahoo.com">Yahoo Pipes</a> are two very useful services, almost like tailor made for the purprose of adressing the above problems!</p>
<p><span id="more-107"></span></p>
<h3>Custom feeds made easy</h3>
<p>Page2RSS is a service which monitors websites for you and creates an RSS feed of it with the updates. Yahoo Pipes could be called a &#8220;mashup tool&#8221; - you can use it to combine, filter, edit etc. various sources on the net: Websites, RSS feeds, web services and such.</p>
<p>Creating an RSS feed for some specific URL couldn&#8217;t be any easier with page2rss: Simply put the URL to the box on their page and they&#8217;ll generate a feed for you. Combine it with Yahoo Pipes and the result is <i>greatness</i>. In fact, combining <i>any</i> RSS feed with Yahoo Pipes is great.</p>
<h3>Pipes</h3>
<p>I personally like the Pipes UI: It&#8217;s good looking and quite intuitive, but it can be a bit confusing at first, and the tools can be difficult to use if you aren&#8217;t a programmer. It&#8217;s a two sided sword - it gives you a lot of power but you need knowledge to be able to properly utilize it. Luckily there&#8217;s a help page for each component you can use, so if you just put some time in, you can learn to use it.</p>
<p>A good demonstration of the power and usefulness of the Pipes service is the custom feed I made for <a href="http://cad-comic.com">Control-Alt-Del</a>. It&#8217;s a great web comic, but why do I have to always visit their site to read the comic? I would much rather just see the image in my feed reader. Also, there are sometimes other non-comic posts in the feed which I don&#8217;t really care about.</p>
<p>With some smart usage of Pipes, you can strip out the non-comic posts and even link the comic image to the feed itself. First, use the Fetch Feed component to load the feed, then use the Filter component to block out all items that contain &#8220;News&#8221; in the title. Now we have a feed without the newsposts. </p>
<p>Then, after some looking at the feed and the comic image names, I figured out a way to extract the name of the image from the link to the comic. So then I used the Rename component to copy the link to the description (the content) of the item and finally the Regex component to perform a search and replace operation on the description, replacing the link URL with a HTML img element to the image itself.</p>
<p>Now I only see the content that is relevant to my interests. All without closing the feed reader, too. It may sound like nitpicking, but if you have lots of feeds, it does save you time when you don&#8217;t have to delete or mark read things that you don&#8217;t even find interesting to begin with.<br />
<br/><br />
<br/></p>
<p>You could use Pipes for much bigger jobs too. You could combine multiple feeds into one, for example from various news sites and perhaps filter that so that it only contains posts that are about kittens. </p>
<p>In any case, it&#8217;s definitely a very useful tool for mucking with feeds.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/06/11/page2rss-and-yahoo-pipes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Spreadsheets, ASP.NET and Excel</title>
		<link>http://codeutopia.net/blog/2008/06/09/google-spreadsheets-aspnet-and-excel/</link>
		<comments>http://codeutopia.net/blog/2008/06/09/google-spreadsheets-aspnet-and-excel/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 10:32:53 +0000</pubDate>
		<dc:creator>Jani Hartikainen</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Web Applications]]></category>

		<guid isPermaLink="false">http://codeutopia.net/blog/2008/06/09/google-spreadsheets-aspnet-and-excel/</guid>
		<description><![CDATA[I&#8217;ve lately been using Google Spreadsheets to display project costs to my clients etc., and for that it&#8217;s quite nice. Quite similar to Excel, too, so it was easy to get going. 
What bothers me to no end, though, is that editing spreadsheets does not work in Opera at all. Why is it? It works [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve lately been using <a href="http://spreadsheets.google.com">Google Spreadsheets</a> to display project costs to my clients etc., and for that it&#8217;s quite nice. Quite similar to Excel, too, so it was easy to get going. </p>
<p>What bothers me to no end, though, is that <i>editing spreadsheets does not work in Opera <b>at all</b></i>. Why is it? It works in Internet Explorer, which means there can&#8217;t be any totally hardcore (like <i>Gandalf-level</i>) JS magic or other stuff going on&#8230; I&#8217;ll just say that Google is plain and simple <i>lazy</i>.</p>
<p>Being a programmer myself, using such an impressive web app naturally got me thinking how much work it would be to build something similar to Google Spreadsheets&#8230;</p>
<p><span id="more-106"></span></p>
<h3>Clone Excel in JavaScript</h3>
<p>Basically the task would be to clone Excel in JS. That&#8217;s what Google Spreadsheets does. Now, I&#8217;m not sure how much of the magic they are doing in JS, and how much of it is actually being done on the server and then updated on the client with Ajax.</p>
<p>Spreadsheets works surprisingly quickly even when using formulas, although updating them sometimes takes a while, which would lead me to believe they&#8217;re actually doing the major legwork on the server. Doing all the stuff Excel does, be it in JS or at the server with some other language, is a lot of work. Of course, I&#8217;d like to simplify the task as much as possible&#8230;</p>
<h3>What if you could just put Excel on the web?</h3>
<p>You know, get the Excel application running inside the browser. Well, there&#8217;s probably some ActiveX thingy for IE for doing that, but we&#8217;d like it to actually work in Opera too. And maybe Firefox, if we&#8217;re not feeling lazy <img src='http://codeutopia.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>With ASP.NET you actually <i>can</i> control an Excel instance! There&#8217;s information on the web about generating Excel spreadsheets through ASP.NET, and what if we could apply that info, create some Google Spreadsheets -style JS grids&#8230; and we&#8217;d have an online poor man&#8217;s Excel in no time!</p>
<p>You could simply use the JS grid in the browser and send all the stuff the user types in the columns to the server, along with info like which column this was etc.. The server would then talk to Excel, modifying the columns in the spreadsheet. Then, Excel would do its magic, and the server would simply reply back, telling the client which columns changed, what data is in them now and things like that.</p>
<p><br/><br />
At least in theory the above could work. I haven&#8217;t used ASP.NET Excel interop, but seeing that you can generate Excel docs, this should be very much doable, too. Sadly I don&#8217;t have access to a server where I could test this&#8230; but perhaps some day, when I also have more free time to play with interesting things like this <img src='http://codeutopia.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://codeutopia.net/blog/2008/06/09/google-spreadsheets-aspnet-and-excel/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
