If you follow my tweets or the IronRuby mailinglist then you would know that I’ve been working on taking IronRuby ASP.NET MVC from the prototype stages to a more complete application. For me this has been a great experience getting familiar with the insides of ASP.NET MVC as well as playing around with integrating IronRuby in an existing C# application.
Attending TechDays Belgium 2009
On march 11 and 12 this year there will be TechDays Belgium
I’m personally looking forward to the event because I will get to meet Laurent Bugnion in person. I’ve been following him on twitter for over a year now and it would be cool to finally put a face (apart from the avatar) to the author
There are some really interesting sessions there. At least they are for me, mostly towards silverlight and WPF development. I’m mostly doing WPF dev work at the moment. Silverlight is just something that interests me naturally. I started development by writing code in flash and animating 3D generated models. I turned away from flash because of the dev tools support and fully went into .NET after that. I was stoked to learn about silverlight and I even like the tools it has to design interfaces with, but of course I’m not a designer so I minimize the time spent in there and hope for somebody to come along and make it look good. I love javascript but css not that much and my velocity is higher in Silverlight to develop the complexer kind of UI so I’m also very interested in the Silverlight stuff.
Maybe it’s harder for me to get excited about the new language features of C# 4.0 as for me there aren’t that many new features to me although for the c# language the features are huge. Variance is something I’ve been waiting for since the introduction of generics, for dynamic typing I can get my fix with IronRuby of course. I rarely do COM interop but it will be nice if it gets better support for that. Named parameters however are new and pretty interesting to me. While it will be a hard sell for me to introduce IronRuby into client work. I can still do lots of tricks with the dynamic typing support in C#4 which is pretty cool too.
I’ve got my ticket have you got yours?
If you’re going too let me know so we can catch up for a beer.
See you there
Ruby <3 .NET – Alt.NET Italy presentation
2 weeks ago I had the chance to [talk to the Italian Alt.NET community about IronRuby](http://flanders.co.nz/2009/01/25/participating-in-the-italian-altnet-user-group/). I’m pretty excited about the Ruby language and I try to convey that enthusiasm onto my victims. From the talks I had afterwards it looks like I was able to infect at least one or two enough to make them go home and download IronRuby to have a play. It is the very first time that I get to see one of my presentations myself because this one got taped and put online.
Created a basic integration for IronRuby and Asp.NET MVC
As I can see the end of the chapter on Rails and I’m looking ahead to see what will be next. I decided to start working on the chapter that talks about using IronRuby with Asp.NET MVC next. [Jimmy Schementi](http://blog.jimmy.schementi.com/) and [Phil Haack](http://haacked.com/) created a proof of concept implementation a couple of months ago that actually did work.
The past weekend I’ve been looking to build on the excellent work they did and to build a more complete integration. In this post I’ll try to explain what I did to make it work. The integration work is far from complete, so if you’ve got some free time on your hands and you happen to be looking for an Open Source project to help with then this could be a candidate for you
.
Participating in the Italian Alt.NET user group
I just finished my talk at the Italian [Alt.NET conference](http://ugialt.net).
There were the following topics of discussion:
- Domain Driven Design
- User stories & planning game
- Advanced Unit Testing in the real world
- Acceptance testing (Fitness)
And of course my topic was [IronRuby](http://ironruby.net)
A new year… some changes
With 2009 starting, started actually, it might be time to look ahead at what’s to come this year.
I hope your holidays were better than mine with my grandfather dying on Christmas eve, I wasn’t in much of a celebratory mood this year.
After having tried being a consultant for a while I have a serious hang-over from enterprise style of development. At least the dev style that only listens to what microsoft has to say and swears by their judgment under the motto: “You don’t get fired for buying Microsoft”. As if it wasn’t bad enough all the CRUD went through stored procs over linq-2-sql. When somebody there told me to copy/paste instead of taking a little bit more care I made up my mind and left the place. This leaves me at the start of this year without a project/job, and as it looks now it might not be the best position to be in with the crisis and all.
Another area that I desperately need to make some progress in is the IronRuby in Action book. So far I have 4 chapters completed and the one on Rails is about half-way there. Because I’m not making as much progress as I initially thought. This partly because I decided to turn my life upside down this year.
Now that I’ve finally found a good place to live and my personal life isn’t as messy as it used to be I’ve returned to writing.
More news on the IronRuby in Action front is that I’ve got a co-author now. His name is Michael Letterle and he has contributed to the IronRuby project. Michael is very passionate about Ruby development and is currently working on the Silverlight chapter of the IronRuby in Action book.
As part of the Chapter on Rails I’ve built a twitter clone. In the wpf chapter I created a twitter client and to be ensure things continue to work both offline as online it seemed like a good idea to me to create the server side too. The last couple of days I’ve been implementing this limited version and you can find it at http://codeplex.com/mocktwitter. Finishing this application is on my to-do list for this year for now it does a little bit more than it needs to for the samples from the WPF chapter to work.
More on the IronRuby subject. I’ve also created a DBI layer for ADO.NET that you can use in conjection with IronRuby to talk to ADO.NET data sources. I don’t know yet if I will base my activerecord adapters on this DBI layer or just with the providers immediately. I put a post up on how to get started and where to get the sources etc on rubydoes.net
I intend to spend some time on agdlr as well as on ironnails as well because ironnails has been a lot of fun to develop.
Building IronRuby with Mono on OSX
**** This is a duplicate post of http://rubydoes.net/2008/12/30/building-ironruby-with-mono/ ****
IronRuby comes in 2 flavours of SCM and apparently also with 2 flavours of project layout.
I spend most of my time on the mac and I wanted to be able to test ironruby stuff on it too. I tried to build IronRuby on my mac which doesn’t work straight away you have to patch it a little to make it work. Read more »
Beating a dead horse: Stored Procedures
I seem to be having the same conversations with the dev teams whenever I switch clients. The topic of this post is one that many people have written about before. I’m just going to put my opinion on my blog so I can refer people to it in the future instead of having to repeat myself every time.
What prompted this post is that since I’ve moved to Belgium I’ve had to take a step back from living on the bleeding edge and using open source projects. Most of the work is concentrated in Brussels and is at big corporates or banks not exactly what you’d see as the progressive thinkers (with reason).
I guess it would be safe to say that I’ve been immersed in “enterprise” development. In short I still haven’t seen anything that is more complicated than a web app like [Xero](http://www.xero.com). But perhaps more about that in another post. This one is about stored procedures and their valid uses.
If you ever wanted to play fur elise in the console
At work today we were playing around with the console.. here’s one of our experiments whilst creating a stoplight workflow (WF).
private static void FurElise()
{
Console.Beep(420, 200);
Console.Beep(400, 200);
Console.Beep(420, 200);
Console.Beep(400, 200);
Console.Beep(420, 200);
Console.Beep(315, 200);
Console.Beep(370, 200);
Console.Beep(335, 200);
Console.Beep(282, 600);
Console.Beep(180, 200);
Console.Beep(215, 200);
Console.Beep(282, 200);
Console.Beep(315, 600);
Console.Beep(213, 200);
Console.Beep(262, 200);
Console.Beep(315, 200);
Console.Beep(335, 600);
Console.Beep(213, 200);
Console.Beep(420, 200);
Console.Beep(400, 200);
Console.Beep(420, 200);
Console.Beep(400, 200);
Console.Beep(420, 200);
Console.Beep(315, 200);
Console.Beep(370, 200);
Console.Beep(335, 200);
Console.Beep(282, 600);
Console.Beep(180, 200);
Console.Beep(215, 200);
Console.Beep(282, 200);
Console.Beep(315, 600);
Console.Beep(213, 200);
Console.Beep(330, 200);
Console.Beep(315, 200);
Console.Beep(282, 600);
}
Common mistakes in software development (part 2): Mixing up the tiers
In my [previous post](http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/) I explained some very quick wins to make your code a little bit cleaner. As I’ve been appointed an [asp.net](http://www.asp.net) project at work at the moment I have the chance to get more ammunition for blogging
.
This time I’d like to talk about properly separating your tiers so that the next person doesn’t have to go through the complete application and make changes everywhere just to make a minor change to the application.
One of the problems; one of the most time consuming that is; I’ve seen is that people are confused on what they have to put in the data logic layer and what is business logic. In my case this is fairly extreme because there isn’t an ORM tool but rather every entity gets populated by calling a stored procedure and then in the code the graph objects get set. Whether this is a good approach for fetching your data or not is not within the scope of this blog post, but I’m guessing there are more people who are facing this type of situation.
Anyway let’s start with the beginning and explain the typical [n-tier architecture](http://en.wikipedia.org/wiki/N-tier) people seem to follow. This is not a particular pattern like [MVC](http://en.wikipedia.org/wiki/Model-view-controller) or [MVP](http://en.wikipedia.org/wiki/Model-view-presenter) that people are talking about so much lately. This goes back to the guidance that can be found on the [msdn website](http://msdn.microsoft.com). This type of architecture is often used in combination with data sets but not in my example for this post. This architecture is generally divided in 3 parts that can, but don’t have to, run on different machines if needs be. When talking about this type of architecture people mostly talk about an n-tier application.
##The first part is the data layer (tier).
The golden rule for this one: this is the gateway between the rest of your application and the database. **NONE** of the other layers should be talking directly to the database but instead should be doing their talking through this layer. That means if you have stored procedures you provide wrappers for them in this layer. You populate your entities in this layer too.
Other functions you can perform in this layer is setting the graph members (populating relationships). IMHO if you’re talking to the database (open/close connection) you’re doing stuff that belongs in the data layer which includes populating relationships.
Encapsulating this logic in it’s own layer, which could potentially be walled off through only exposing it with remoting or WCF, allows you to reuse the code in different places of your applications or sharing this data access assembly with multiple applications.
##The second part is the business logic layer (tier).
This layer encapsulates all the operations you do on entities to express the business rules. That means you would probably do most of your work in this layer. Basically **all** of the programming you will be doing for the business rules should be done here. Business logic doesn’t live in stored procedures, it doesn’t live in the UI or the data layer. Nope this layer is where it lives and nowhere else. This statement may raise some eyebrows but only and only when you find that a certain routine is a bottleneck and it is really data intensive you can put it in a stored procedure but more on that subject in another blog post.
If you find yourself transforming data so you can display it in your GUI then you’re probably expressing business rules that aren’t explicitly stated as a business rule.
When you find yourself to be concatenating strings or writing logic to translate your pages in your GUI layer then you’re probably expressing business logic (business logic doesn’t have to come from business
in case that wasn’t clear).
Another common find in business logic is validation for example because this generally expresses some kind of strict rule that comes from the business domain your application deals with. Validation is a tricky one but the rule is you should do **all** validation in your business logic. To provide a better user experience you can maybe reuse that validation on the client side. In the case of web development you probably will have to duplicate that validation in javascript if you really need it.
Separating these rules into their own layer allows you to reuse the methods and classes you create in the business logic layer, in different parts of your UI or even reuse it in different applications.
By separating this logic it should be easier for you to do some automated testing like unit testing and/or integration testing of that code.
##The third and last layer (tier)
This is typically the UI layer but you could easily use web/WCF services as an interface to your logic. The UI doesn’t have to be a GUI it can also be a CLI (Command-Line Interface) or something. But that is how you interact with the user or external application. The idea is that in this layer you have virtually no logic except for what’s on the screen **everything** else should be handled by your business logic. To clarify this statement: you can show/hide UI elements or add/remove elements to the UI and respond to events triggered by user actions but the data of that response and the processing really belongs in the business logic layer.
The UI layer can talk to both the business logic and data logic layers. If for example you’re getting a category list with just an id and name from the database chances are you won’t need to transform that data so your UI can bind directly to the entities returned by your data layer. But more complex items like an invoice for example will probably need some processing and then it should probably pass through the business logic layer.
This is typically a somewhat harder part of your application to provide tests for although there are some libraries out there that make it easier but still there are easier parts to test in your application.
So that was a quick refresher on what the classic n-tier architecture is about an how it should be structured. I hope you will agree with me into stating that its not that hard and pretty straight-forward to implement, but what I find in the “enterprise” is far from the points mentioned above.
It is a bloody mix of everything everywhere, leaving me thinking -come on guys it’s not that hard-:
*talking to the database => datalayer*
*showing windows/adding UI elements,… => UI layer*
*everything else => business logic*
Failing to abide by the previous simple rules will result in hell freezing over, entire plagues will be released upon the world; to cut a long story short: the world as you know it will seize to exist and turn into complete chaos.
Following the rules should result in less code duplication, an instantaneously easier to maintain codebase and probably more happy successors for when you move on to the next project. It should also give you a higher degree of code reuse.
If there is one thing you should take away from this article then it should be:
**Don’t mix your tiers**
Of course there are a couple of situations when you can diverge from the ideas presented in this post but you should always be able to justify why you break the rule. So you need a good reason to break the proposed architecture and that would probably also warrant a comment so the next guy also knows what’s going on.
The most important part is to separate all non-UI logic out from the UI layer and put it in one of the lower layers.
Thanks for reading
Ivan – writing for more maintainable software -
