Wednesday, February 04, 2009

Why ninjas are cool

No. You are wrong. This is not yet another rant about why Dusk of Ninja & Brush is a totally awesome game. This is real ninja stuff! .NET ninja stuff – but you catch my drift.

Today I went to a Tech Talk at microsoft about ASP.NET performance. Usually these talks contain just enough to not be a complete waste of time – but they are seldomly totally awesome. Today was different. Today a ninja was doing the talk. The Ninja was Mads Kristensen. I have been reading his blog for a while, and knew that he was good. But seeing him live was a whole other ballgame. The dude knows his tech and how to present it.

First of all he cut straight to the chase saying that usually when you talk about ASP.NET optimization – or when MSDN does anyway – they talk about how optimize all the backend stuff. The point is that this matters – but not as much as you think. Usually that part of serving the page takes up less than 10% of the total time the page takes to load… What takes the other 90% is all the CSS, JS and image content stuff. So that is really where you want to optimize.

Taking it from there he ran at a gracefully fast ninja tempo through techniques like minifying, compression, outputcaching, http caching and a lot of other stuff. Techniques that I knew, but I am really underutilizing because they are somewhat hard to get into and get to work properly. Mads showed me that it was just because I was trying to use a screwdriver to drive in a nail. With a lot of handlers and helpers page, most of which were dead simple 1digit-liners, he transformed an albeit simple site page using ASP.NET AJAX, external CSS and JS from 18 HTTP requests and 200K down to 5 requests and 30K – 0K on following requests when cached. Yes – that is no content. Driving the YSlow score up to a whopping 93.

You of course have to use some thought on how to manage caching if you have a highly dynamic site. But with his handlers and helpers in that was pretty simple too. Bottom line – this can be used on almost any ASP.NET site with very little effort. I just can’t wait to get my hands on this code!

Mads. You are truly a ninja. Keep up the great work.

Sunday, February 01, 2009

Global Game Jam 09 is over

…and it has been a blast. 48 hours of game making madness around the globe. I am really looking forward to seeing how much press this event generates and to see the games that have been created. Needless to see very few will have time to play all the games that the 1500 participants worldwide has made. Here we made a massive 29 different games – and we were 150 people. A quick calculation suggests that this will result in at least 250 games made this weekend. Mind boggling. Glad I have the badge and T to show that I was in the event.

So… You are waiting to hear about our game? We went with a safe kick-ass theme: Ninjas and Zombies. You can’t really go wrong there, can you? Our game is called Dusk of Ninja and Brush and it features the last minutes of our hero Ninja while he and his friend Brush is being overrun by zombies.

Won’t go into more detail in writing, because playing says more than 1 gazillion words. But since the Unity windows beta version we used does not have the ability to publish a web player, you’ll have to wait a few days. I promise I’ll get it ready as soon as I get a capable Unity version, and I’ll post the link to the game here.

Wednesday, January 14, 2009

StringBuilder and the immutability of strings

I had a discussion today with Robin, who claimed that there was several ways to break the immutability of strings in C# – most notably by using a StringBuilder to build the string in bits. I found that very unsettling, and decided to make my own tests to see what was happening. Here is a screenshot of the program and the results.

CropperCapture[4]

The results are pretty interesting, and not as unsettling as i had feared. It seems that immutability of the string is indeed broken for the string gotten from the StringBuilder as it is not the same reference to the string. This is at least what I thought was one of the porperties of string immutability in C#. Luckily both an Equals call and == report the strings as being the same.

What practical implications does this have? Obviously – do not rely on ReferenceEquals when testing string. But when would you do that. The only case I can think of right now is when testing:

CropperCapture[6]

Using “Assert.Same” (in xUnit – Assert.AreSame in NUnit), will fail. This is not something that I would normally do – I mostly use Equals and only Same when I really mean it. If you have a different strategy, maybe it is time to revisit it.

But what is really happening here?! You have to dig a litte bit to find out what is going on. In .NET strings are usually stored in the intern pool. This is the way to ensure immutability. This is true for all cases of literal strings at least. Even strings literals concatted with + have ths ability. But in some cases, apparently when strings are generated from char arrays, like when they come from interop or StringBuilder, strings will be put in the heap instead of the intern table. To the rescue comes the String.Intern() method which will correct all wrongs:

CropperCapture[7]

There. Now you know some more about the inner workings of strings. Lesson to be learned: Never ever use ReferenceEquals to compare strings. And if you are forced to – Intern them first.

Friday, December 12, 2008

Robocopy to the rescue

This is a typical situation. I have been trying to find a tool that can solve a problem I have of syncronizing my web files properly. Without any luck. Until today. And the worst part: The solution was already installed as part of windows and has been that way for ages.

Enter Robocopy.

This is a command line file copier that as standard copares files in two directories and copies newer files over. Recursively as well. Nothing revolutionary in this. But here comes the good parts: It can purge extra files for you - typically web pages not used anymore. It can also save your parameters to a job that can be rerun. Very practical for automated builds.

So is there something this wonder cannot do? Yes... Do the sync over FTP. That would be nice. Maybe there is some other tool out there...

Wednesday, November 26, 2008

Adventures in Flash and Python

The last couple of weeks I have been making a nice little Flash application, a questionnaire, for a government project. One of the features of the questionnaire was the ability to print out results based on the answers given.

In order to do pretty printing of the results, I used the awesome AlivePDF library to generate PDFs for the user to print. Neat stuff. It was a bit dodgy to get it up and running - especially because you cannot force a download from your Flash file. Instead the library uses a neat little trick of generating the PDF content in the Flash and then posting the content to another web-page that converts the post to a download-file. Pretty neat stuff.

Included with the library is a PHP script that does that little trick, and I managed to get it up and running. Especially AFTER I discovered that the reason it did not work was that my IE8 beta just didn't accept what was going on. Not even in compat mode. So I had to use Firefox. Discovering that I had to go there was a stroke of luck.

All that out of the way. Or so I thought. Because suddenly things got spicy. Clearing the solution with operations revealed the fact that they had no PHP running anywhere, so could I please make it work with Python? Yes, of course... Because I know Python (NOT). But how hard can it be? The PHP script is only 10 lines of code for crying out loud!

So I got my feet wet in Python. The language itself does not seem that hard, but getting to know the environment and how to test was not easy. But I managed to bang out a Python script that does what the doctor ordered. And only 'round 100 times slower than a real Python haX0r. :P

So if you ever need to use Python and AlivePDF, here is the script. It is missing any kind of error handling code, and may not work in all scenarios. And I will probably not be able to fix it for you. But knock yourself out.

  1: #!/usr/bin/env python
  2: 
  3: import sys, cgi
  4: import cgitb; cgitb.enable()
  5: 
  6: query = cgi.FieldStorage()
  7: dict = {}
  8: for param in query.qs_on_post.rsplit("&"):
  9: 	parsplit = param.rsplit("=")
 10: 	dict[parsplit[0]] = parsplit[1]
 11: 
 12: 
 13: print "Content-Type: application/pdf"
 14: print "Content-Length: " + query.headers["content-length"]
 15: print "Content-disposition:" + dict["method"] + "; filename='" + dict["name"] + "'"
 16: print
 17: print query.file.read()

Wednesday, April 30, 2008

It must be a sign, but an undeciferable one

How come that the day GTA4 should have arrived in my mail, the postal delivery people in my region decides to go on a strike. So I am left out of the party even though I had done my duty and pre-ordered the game. Luckily they are showing Chelsea-Liverpool CL semi on Viasat TV6 which I can watch for free with the digital tuner in my new TV.

Nothing as cruels as this happens without a reason. So. What is there to learn? Never pre-order a game? Could be. With Halo 3 I got a fair warning getting to pay more than I had to - even though Coolshop has a pricing guarantee. Never covet a game so much that your belly hurts? Actually I am still looking more forward to Rock Band than I had to GTA4. But the last couple of days the GTA fever got to me too.

Bottom line. I am angry, hurt and confused. And I don't know why...

Tuesday, April 29, 2008

Installing on consoles

One of the reasons that I have ditched PC gaming in favor of console gaming is that it is just much easier. I mean, buy the game, put the disc in the drive, off you go. Can't get better than that. But in the next gen game things have changed somewhat. Sometimes when i put the disc in my 360 I need a title update. So an installer has been downloaded, runs and reboots either the game or the console. Usually this doesn't take long and you are back in the action.

This is all well and dandy but the other day when I wanted to try out the Gran Turismo 5 Demo, oops, PROLOGUE, on the PS3, I got a nasty surprise. Not only did the game need an update of the PS3 core system - which took a couple of minutes - but before starting the game proper it needed to install to the harddrive... WTF?! Seriously. I was treated with a non-progress bar teling me how the install went. Five minutes later it read somewhere between 5 and 10% complete, so I decided that I really needed to get back to work instead of this.

Now I don't own a PS3, so I don't know if this pain is something every PS3 owner needs to endure before every game experience. What I do know is that it is the most mind numbingly stupid thing I have experienced on a console. Not only have they ruined the slot-in-and-play experience that makes consoles such a joy. They have introduced onto the user the ardurous task of disk management. Good grief. And for what? Reducing load times. Bullcrap. I have no hard stats on this, only a gut feeling. But apart from the odd elevator experience, load times are not that much worse in this gen. Developers need to get clever in order to alleviate this until we get a new portable media with almost instant load times. With this moves, Microsofts seemingly troubling decision of making the hard drive optional on the 360 suddenly seems like a wise defense against developer zeal.

Let us revisit the issue of the game requiring a specific system version before playing. In my book this is also somewhat unsettling. It stresses the feeling that the PS3 system was not finished from the get go. But worse, can you trust Sony not to let this slip the other way so that you cannot play an older game on a newer system revision? You have to wait for the devs to put out an update for the game. Potentially rendering some unplayable for an uncertain amount of time.

All in all this is not the way to go. Not only did Sony mark the wrong date in the calendar for the next-gen party. They showed up unprepared, sloppily dressed. They didn't bring anything to the bar and all their exclusive friends are doing good business in other circles. Now they are acting obnoxious. No wonder the hard-core gaming audience has moved to another room to party. People who bought the system to play games are really getting thrashed with the short end of the stick. The system is really only attractive as a home theater system. And that is quite a different party.

Sunday, April 20, 2008

Caught on film

Razu came by the other day and caught me for an interview for Microsoft. I think the result is actually quite good. See for yourselves, and please do comment.

The Real Story

Friday, March 28, 2008

Do YOU see ANY connection?

How can something so good be free?!?!

I have long been wanting to take a look at the Umbraco open source .NET CMS system, and now I finally have had the opportunity to do so in conjunction with the website I am creating for my new buddies at GamingSchool. I must say that what I see amazes me. I have had some experience with CMSes in the past. I used SiteCore contracting for AlphaSolutions. Currently I am using CompositeCMS for the Clubzone.es site that I took over from another company.

Umbraco blows them both out of the water - effortlessly. Moreover Umbraco is free while the others cost huge amounts of money!

So here is a little list of pros and cons of Umbraco that I have discovered so far.

Less is more.

Umbraco may not be as fully featured as the other CMS'es. Just my guess though, haven't studied it properly. But it is so smooth to use that anyone can figure it out. And it does pack a lot of punch under the hood for developers.

Seamless install

When I had to set up CompositeCMS for Clubzone, I had to install it on my machine to get it running. Furthermore it doesn't run on Vista. So I cannot run it on my dev machine making local development impossible and debugging a pain. Getting a test version of the site running on my test server took several days of tampering to get it somewhat aligned with my build cycle. This is just plain annoying.

When I ran SiteCore it took "only" a day to get it up and running on my dev machine, but this was with the help of a long time SiteCore developer by my side. Even he hated doing it because he knew it sucked.

Umbraco comes in two flavous - install and zipped. I like the latter. Unzip. Tell IIS where'z'at. Set permissions correctly (got me at least once). Go to /install and complete a wizard. Bang - good to go. Making a test version of the site is even easier as you just copy the files over and don't have to do the 2 minute "install" part.

Great .net integration

When you want to make the more complicated stuff you use Macros in Umbraco. These can be either XSLT scripts or .NET user controls. I have always loathed XSLT for being the over-complicated non-compiled write only language that it is. So I use .NET user controls, and making them for Umbraco is so very easy that it makes you want to jump up and down with joy.

ASP.NET AJAX IN THE BOX

Now this is both a pro and a con. I am very divided on ASP.NET AJAX. Having used it extensively for "StryBergs Blå Bog", I got a love/hate relationship with it (save that one for another post). I prefer some of the more lightweight JS libraries out there - MooTools and JQuery rank highly right now. Since ASP.NET AJAX and these libraries does not go together well - if at all - I am forced to use ASP.NET AJAX. I hate that. I want a choice. I thorughly understand why this might not be very easy to do - but thats what I would like.

The pro is that you can just go ahead and use it. Drop the AjaxControlToolkit in and you're all set.

documentation?

Now this is always the achilles heel of all open source projects. And it is no different with Umbraco. Niels Hartvig - Mr. Umbraco - has even gone to the lengths of adding an easy way of writing books on the web site for everybody. But still the documentation is a cluttered half assed mess in disarray. The main source of info is in the forums. A classic. The forums are reasonably good. But could somebody please explain to me why all links on Google searches for forum posts give a "page not found"? Seems like they have reorganized their forum breaking every link in the process. Meh...

Pure "luck" that Umbraco is easy to pick up on. But it takes a while to get into developing Macros and stuff.

Just in on their blog is that Niels and newcomer Per will be focusing on improving documentation. Wise decision.

concluding thoughts

So... I may have more to add. But time is running out on me. (It is a quarter past 1 and Halfdan wakes me up at around 6).

Anyways: Check up on Umbraco. You won't regret it. I am not getting kickbacks. It's really true! ;-)

Technorati Tags:

Friday, February 22, 2008

The three project solution

Ayende just brought up the issue of project structuring, and his experience was so similar to mine that it cannot be a coincidence.

In my old job I spent a lot of time trying to "do things properly". Splitting up into a lot of logical assemblies, promoting reuse by having special helper assemblies and so on. The result was a huge amount of lugggage that each application had to carry around. When we deployed a simple windows service or console program, it consisted of 9 or 10 assemblies. And don't get me started on versioning all of these, because we were very methodical there too. It sort of worked, but only because we had build a very rigid CI monster controlled by a horde of NAnt scripts that no one - even me who wrote most of them - could figure out after two months away from them.

Today I consider that a learning experience, and I go for the "three project solution". Ayende says two, but I think having a third is worth the hassle. Especially when you create solutions that have different application components in a workflow.

The three projects goes a little something like this:

  • Application.Core : Holds all the logic and data for the solution. I split up classes in a logcal folder/namespace structure. As I favor using MVC pattern a lot, it usually holds Model, Controller, DataAccess and Helper folders.
  • Application.Core.Test: A test library for the core lib, same structure as the Core.
  • Application.<Type>: This is the application itself. The type can be Website, ConsoleApp, Service or whatever it is that I am creating. If there are more apps, there usually is, they get their own projects. All application projects have as shallow code as is can - usually only the View parts of the MVC structure.

I find that it reduces friction both when developing, but especially when deploying. Only two assemblies to deploy. No inter version dependency nightmares and so on. Simple and smooth.

Monday, February 04, 2008

Mass Salvation

Nordic Game Jam is over, and as last year, it was a hoot and a holler! Man, we had fun! I was lucky to get a great team. crew_highFour programmers, four game desginers/artists/sound engineers and a great idea. So we managed to get a full a full game up and running on the XBox using XNA in only one and a half day.

The game is called "Mass Salvation" and in accordance with the theme for the Jam, which was Taboo, is about religions. The "back story" is that it is the day before judgement day, actually 1 minute and 30 before, and humanity is a mess. Everybody is atheists and now reckognize their mistake. You take the role as a religious leader and have to convert as many followers to your cause and send them to the sweet afterlife in style.

It is played using a controller geometry wars style by up to four players. You are playing short rounds (1:30), and the pace is frantic. You can pick up and play the game right away, but as you play more, you will learn how to use the rally point to your advantage as well as different strategies for grabbing followers. So the gameplay has several levels of skill.

Below is a video of the mayhem. I will post a link to a downloadable version of the game soon. Just have to repackage it and make a ccgame version as well. So stay tuned!

Tuesday, January 29, 2008

OMG! It Rocks!

Not that I had any doubts about it. But I just tried Rock Band today, playing the guitar and drums. Man, it is fun. Why, didn't I sing? Dunno. Next time. Playing the drums was just as muc fun as I had imagined. The guitar takes a bit getting used to. It is much more sturdy and heavier than the GH guitars and has a much different feel. But it actualy feels more like playing a real guitar than GH does, much more than I had thought. Is there a flipside?! Yes, the version I have access to here two months prior to launch is a PS3 version - so no achs for me for the time being. Darn it.

Sunday, January 06, 2008

XNA Tweener library

My second open source project is live now at Codeplex - and it has a release and everything! Check it out here.

The project is a Tweener library for XNA making it easy to create animations for your games. I was inspired by the Tween class in ActionScript although it is not a direct port. All the cool easing functions from Robert Penner that you know and love are of course there, ported from the js code. So the release is functional.xnatweener

I am actually quite pleased with myself for doing this, because it has been short and focused work. The first code was created this Thursday - this was the basic Tweener class and the first ported equation as well as a very basic demo. Today (technically yesterday) i squeezed in the rest of the work, adding stuff to the Tweener class and the last equations. Then I spend some time polishing up the demo so it would look cool - getting to know my own library in the progress.

Best of all: I didn't create the library alongside a specific other project. This made it easy to focus on not making all kind of proprietary stuff and KISS. I am pleased with the result, and will use it in my games. But i find that I lack some of the fancy dynamic features from JS lacking in C# which could have made the class so much cooler - but I have some slick ideas for making it rock even more.

The project is made on Codeplex, and having tried both Codeplex and SourceForge now - I will say that Codeplex really whips the llamas a**. Or at least SF's. When I made the d20Sharp project on SF it took me ages to get up and running properly. With Codeplex it literaly took 5 minutes. And the interface on Codeplex is much better and more intuitive than the one at SF, and I won't even begin on the features... I would like the Codeplex interface for my own projects - I know it is somehow based on TFS but I haven't checked out the product as I know it is way out of my league at Gosuman pricewise. If there were a hosted licensed version out there I would probably consider it.

Anyway - download the library and take it for a cruise. Then tell me what you think. Then I will improve it.

kick it on DotNetKicks.com

Thursday, December 13, 2007

More Mocking of HttpContext for MVC

I was actually preparing this for a comment to my last post in answer to chris7's comment. But it got long. You know!

Chris7 asked if it was possible to abstract out the Record/Playback syntax in the example to make the code clearer. And you can of course do that and put the Replay call into the MockContextFactory like this:

protected IHttpContext MockContextFactory(string url)
{
IHttpContext httpContext = mockery.Stub<IHttpContext>();
IHttpRequest httpRequest = mockery.Stub<IHttpRequest>();
SetupResult.For(httpRequest.AppRelativeCurrentExecutionFilePath).Return("~" + url);
SetupResult.For(httpContext.Request).Return(httpRequest);
mockery.Replay(httpRequest);
mockery.Replay(httpContext);
return httpContext;
}


The code in the test method would then look this way:



[Test]
public void WorldDetailsRouteExists1()
{
IHttpContext httpContext = MockContextFactory("/World/Details/9/3");
RouteData routeData = routes.GetRouteData(httpContext);
Assert.IsNotNull(routeData, "There is a route to the URL");
Assert.AreEqual("World", routeData.Values["controller"], "We are using the world controller");
Assert.AreEqual("Details", routeData.Values["action"], "With the details action");
Assert.AreEqual("9", routeData.Values["x"], "And the correct x");
Assert.AreEqual("3", routeData.Values["y"], "And the correct y");
mockery.VerifyAll();
}


I actually chose the Record/Playback model as I find it nicer to look at than the other syntax. But I guess it is a matter of taste. In this example it is probably not obvious why I prefer that syntax, but for more involved mocking scenarios it makes it easier to see what is record and what is playback.



Phil Haacked also commented with a post of his own describing how to the same thing using extension methods instead. I encourage you to look at that as well to see yet another way of doing it.



kick it on DotNetKicks.com

Tuesday, December 11, 2007

Mocking HttpContext for MVC route testing

First I have to say thx a bunch to MS for releasing the CTP of the MCV framework. This really is Da Bomb. I think they are doing a great job here.

So I am setting up my first MVC.NET based site, while digging through all the relevant posts on how to use the framework. So while setting up my routes, doing the proper TDD, I stumble upon the MockHttpContext for testing routes in ScottGu's part 2. This bugger is not explained anywhere nor part of the framework. So you have to whip up your own. Googling it - lazy as I am turned up nothing. DIY time. But being the friendly coder, I will share what I made.

So without further ado - here is how you could create a MockHttpContext for testing your routes using Rhino.Mocks. Note, I have used the same way of setting up the routes as Scott is showing in his post.

[TestFixture]
public class RoutesTest
{
protected RouteCollection routes;
protected MockRepository mockery;

[SetUp]
public void SetUp()
{
routes = new RouteCollection();
Global application = new Global();
application.RegisterRoutes(routes);
mockery = new MockRepository();
}

protected IHttpContext MockContextFactory(string url)
{
IHttpContext httpContext = mockery.Stub<IHttpContext>();
IHttpRequest httpRequest = mockery.Stub<IHttpRequest>();
SetupResult.For(httpRequest.AppRelativeCurrentExecutionFilePath).Return("~" + url);
SetupResult.For(httpContext.Request).Return(httpRequest);
return httpContext;
}

[Test]
public void TestRouteRegistration()
{
Assert.IsNotEmpty(routes, "We have filled the routes list");
}

[Test]
public void SearchRouteExists()
{
IHttpContext httpContext;
using (mockery.Record())
{
httpContext = MockContextFactory("/Search/Beverages/2");
}
using (mockery.Playback())
{
RouteData routeData = routes.GetRouteData(httpContext);
Assert.IsNotNull(routeData, "There is a route to the URL");
Assert.AreEqual("Search", routeData.Values["controller"], "We are using the search controller");
Assert.AreEqual("Results", routeData.Values["action"], "With the details action");
Assert.AreEqual("Beverages", routeData.Values["query"], "And the correct query");
Assert.AreEqual("2", routeData.Values["page"], "And the correct page index");
}
}
}
kick it on DotNetKicks.com

Friday, October 12, 2007

CodeBehind handlers in ASP.NET

I was creating an HTTP handler for an ASP.NET project today for returning a CSV report to a customer. And naturally I wanted this to CodeBehind style as everything else. This turned out to be a small gotcha, since it is not supported out of the bag with VS.NET 2005. So for further reference here is what to do.

1. Create the handler as usual - for instance MyHandler.ashx.

2. Create a new code file for the handler - MyHandler.cs - make sure this goes in the App_Code directory otherwise it will not be compiled properly and you will get a "Could not find class: MyHandler" error.

3. Copy all code from MyHandler.ashx to the new code file, replacing all code there.

4. Add CodeBehind="~/App_Code/MyHandler.cs" to the WebHandler directive at the top of the MyHandler.ashx file.

Done deal. Why the code file has to go into the App_Code directory and cannot stay alongside the ashx-file as other handlers do is an open question. I am betting that there is some odd web.config fix for this.

Friday, August 17, 2007

Wierd ActiveRecord "bug"

As I have written earlier I am using the Castle ActiveRecord framework extensibly. It is an extremely cool framework that has cut down on the amount of database work I am doing - shortening development cycles considerably. But I am still learning, and today I finally squashed a very odd bug that had bugged me for a while.

The scenario is this: I am storing some data for the Warlocks game server in a database. This database uses the ASP.NET 2.0 Membership API to store user data as well. The part where I am at right now involves setting up some user data and then using some ActiveRecords. And for some reason this did not work.

The problem, it seemed, was that the schema for the ActiveRecords did not exist in the database. I spent several debugging sessions assuring that I had calld the "Init" method of the AbstractModelTestCase (kindly provided by Castle for making unit testing of ActiveRecords much easier) - which in turn creates the scheme. But the error was there nonetheless.

Working systematically through the test by uncommenting lines to find out what caused the error, I found out that the problem occured when I added the code that added users through the Membership class. Without that it ran fine! I tried adding a new Init call after that code, and the test worked like a charm.

So what is up here? It seems like initializing and using the Membership provider will in some way reset the database. The database is a local file database that is in the project and is copied to output - ie. the data directory. Maybe the Membership framework copies the database file again, thus overwriting the database that has had the Schema created in it. I haven't cracked it yet - but if you know what is happening, please tell me. For now I have fixed my AbstractModelTestCase to initialize the Membership framwork before creating the scheme.

If you are wondering why I am not using a database on a server, it is simply because it is much easier to use a file database so the tests can be distributed to other developers and my buildserver without setting up anything.

Thursday, July 26, 2007

The Interface Tax

Evan has an OK post here, detailing the intrisics of Object Composition and Inheritance. He is very right in the way he is doing stuff, but while I was reading, something was bothering me as well. The thing that bothered me was that the code I am writing in the projects I am doing right now does not look a lot like what he is doing - and I think that I am following the OOP principles just as well as he is. So what is the difference? Actually it is that I am not "paying the Interface tax".

When I had my Advanced OOP course at ITU we really got down and dirty with using interfaces and loosely coupling everything everywhere in the programs, and for a while I followed that road in my stuff as well. But then I began to bug me that for every odd class there was an interface mirroring the methods on that class. Every time I needed new functionality in that class, I off course duly changed the interface. The great thing here is that the only class ever implementing the interface now, and propably forever, was that class that caused the interface in the first place. I call that paying the Interface tax, and in my eye it is a bad case of YAGNI.

I am not saying that interfaces are bad. They are good - for the right occasions. If you find yourself making interfaces for data entity classes, you are probably getting taxed badly. I usually only get to the point of using interfaces when making "framework stuff". Things I know will be used over and over in different projects. In an application, good old inheritance will more often be what I am after. It can save me a lot if implementation by inheriting functionality and save me the hassle of having YAGNI interfaces only being used by one class hierarchy at a time. And you can always refactor into an interface when the need arises.

So before signing up for the interface tax, remember that simplicity is King.

PS. Have you noticed the great TLA for todays topic. *DUCKING*

 

kick it on DotNetKicks.com

Friday, July 20, 2007

The Wii song

This is just SO much fun! SarcasticGamer.com is my new fave RSS feed. Their podcast is a hoot. Honest, no-punches-pulled opinions about the gaming hype sprikled with great radio sketch material. w00t!