Mad Props!

Omniscience is just a Google-search away.

Login

You're reading Mabsterama, the weblog of Matt Hamilton. Enjoy your stay.

.NET 3.5 SP1 and Client Deployment

So if you're a software developer and haven't been living under a rock all this week, by now you've probably read about the beta release of .NET 3.5 SP1. If not, read about it here on ScottGu's blog or here on BradA's.

I'm not a big fan of the naming conventions here. I still believe that .NET 3.5 should have been 4.0, which would make this next release version 5.0. Both 3.5 and 3.5 SP1 introduce enough new stuff to warrant a full version bump - particularly compared with the change from 2.0 to 3.0.

Anyway, one of the most exciting announcements for me was around client deployment in .NET 3.5 SP1.

First, Microsoft are introducing a cut-down "Client Profile" framework deployment, which brings the entire framework back to about 26MB. It does this by excluding all the "server" bits - ASP.NET, Enterprise Services etc. This will make that initial installation of the framework on XP much smoother.

Second, it seems that we will finally be able to deploy an application using ClickOnce without having to digitally sign it. For freeware developers like me, this is a big deal. I mean, I was able to generate a certificate for Mad Props from the command line, but why bother? It's not like that certificate has any real meaning. Anybody installing Comicster, for example, won't be too worried about whether the developer has been blessed by Verisign or somesuch - they'll just want to install the app and start playing. So I'm really looking forward to checking this change out.

Oh, and off the topic of deployment for a moment - they're also introducing a WebBrowser control for WPF! That means that my WPF version of Comicster (which I'm sure will see the light of day at some point) will be able to use the same (HTML-based) skinning system as the current version! That's good news for anybody who has developed their own Comicster skin.

I won't be downloading the beta of 3.5 SP1 since I don't really have a "play" machine that I can risk beta stuff on, but I'll be first in line when it's finally released. Bravo!

Developing with Confidence

Over the course of my career, the way I develop software has gone through a lot of changes. Coming from Clipper, talking directly to flat-file xBase tables, then to Delphi, still talking to the database directly but this time to a "proper" database like Informix and SQL Server, and then to .NET Windows Forms, talking to SQL Server via web services.

But even the move from single tier to n-tier isn't the only change. There are fundamental differences in the way we approach a project now. In fact, there are differences every time we start a new project. Even in the past few years using .NET we've gone from using ADO.NET DataSets to using strongly typed DataSets, and from there to using an object model. We've gone from a bottom-up "model-driven" approach to a "test-driven" approach with NUnit and Moq. Before long we'll be looking at ORMs and code generation. So much change.

Every time we switch gears it's a good feeling. I feel like every change is a step in the right direction, that somehow we're more "correct" this time than last time.

However, the constant flux does mean one thing - it means I'm never 100% sure of myself. What if we're painting ourselves into a corner with this new project? What if tomorrow we find a better way? Should we be taking the time to learn ORMs now or should we just get this project done and look at it next time?

For me, software development is constantly having a conversation with two little characters sitting on my shoulder. One is the pragmatic devil, saying, "Get it working! Ship it! Forget about elegant code or new technologies!" The other is the dogmatic angel, saying, "Make it maintainable! Don't code that - use code generation! Declarative, not imperative! Handle those exceptions! Test first!" etc etc.

Does anyone else feel this way? Is software development a constant battle with your conscience? Or are you 100% confident in your methodologies? One way to stay confident is to not upgrade ever. I know people who develop applications in MS Access and have no reason to move forward - they're making functional, income-generating, single-tiered applications and they're happy. That's not how my brain works, though - I want to continue moving forward.

So who's with me? Who else feels a nagging sense of self-doubt every time they start a new project? It's a good thing, right?

ORM - Ur Doing It Wrong

I had a brief IM discussion today with Adam Cogan. Adam doesn't know me but I've known him since back in ... hmm ... 2001(?) when I attended a presentation he did on Reporting Services for SQL Server 2000 in Canberra. Since then I've seen him present a few times (both in person and on DNRTV) and I've even had the honour of being quoted on his company's web site.

So we were chatting (among other things) about the ADO.NET Entity Framework, about which Adam ran a presentation at this year's Code Camp Oz. Unfortunately we had to be back in Albury by 6:30 so we didn't get to see all of the presentation, but I made it pretty clear on my Twitter feed that I was yet to be convinced about the EF.

Adam asked whether I use an ORM right now, and I had to admit that right now we're on something of a cusp at work. We're just now starting to abandon typed DataSets and use our own class hierarchy to model our business domain objects. However, we haven't yet started using any kind of ORM. We're rolling our own using plain old ADO.NET.

Why would we be wasting time coding old-fashioned ADO.NET rather than using a proper ORM? I don't have any good answer to that, but I'll put some thoughts down here and see if I can come to some sort of conclusion.

When I first started doing Windows development at work, we were using version 1.0 of Borland Delphi. Delphi was an awesome product with a rich component framework, but every once in a while there was something that was easier to do if you called down to the Win32 API. Not only that, having a knowledge of what Delphi was doing "under the hood" (in terms of window handles etc) came as a real advantage.

I guess that attitude has kind of stuck with me over the years, and any time I see a new technology come along, I'm interested in starting (as much as possible) with "first principles" and doing things "the long way" before jumping in. So I guess subconsciously I've decided to try rolling my own ORM before jumping head-first into a third party one.

Another reason I haven't leapt straight into using an ORM is that right now at work we're introducing a lot of new things. Not only the idea of using an object model instead of DataSets, but also some more fundamental changes like unit testing and mocking. As much as possible I want to limit the amount of "new" that I introduce at once - not just for everyone else's benefit but for my own too.

Where to from here then? I think we'll roll out a project or two using hand-written ADO.NET code until we have a good grasp of what we're doing, and then start investigating our options: The likes of NHibernate, SubSonic, LLBLGen, and the Microsoft offerings like LINQ to SQL and the Entity Framework.

In the meantime I'll keep my eyes (and mind) open!

Code Camp Oz 2008

As you saw in the previous post, this weekend I travelled (twice!) to Wagga with Andrew and Fordy from work to Code Camp Oz.

I had known from reading the agenda that this year's code camp was going to be something special - presentations from the likes of Paul Stovell, Joseph Cooney, Shane Morris and (visiting from Spain) Fernando Guerrero made it a must-see -  but I didn't realise just how much better it was going to be than previous camps.

You see, this year we started using hashtags to track everybody's twitter feeds, and there was maybe a dozen of us live-twittering the event. As each presenter ran through his talk, we were able to argue the finer points of the topic and share experiences. It absolutely changed the tone of the conference (can I call it a conference?) for me. Instead of being a mute member of the audience, I was a living, interactive part of every presentation.

On top of this, I got to meet in real life a bunch of people that I'd hitherto only known online. Paul Stovell, Craig Bailey, Angus McDonald, Warren "ManiacD" (whose surname I don't know), and (from across the room) Jodie Miners. I also picked up a few more twitter followers and followees, mostly people who were also at code camp but whom I didn't get to meet face-to-face.

Highlights? For me probably Paul's presentation on SyncLINQ and Joseph's on Silverlight vs WPF, but Phil Beadle's talk on test-driven development was probably the one that caused the most ripples across the twittersphere as people debated its pros and cons.

Geek Zenith at CodeCampOz

Just wanted to blog the fact that I just twittered about IMing with Andrew, who is in fact sitting right next to me at Code Camp Oz. Three layers of geek indirection. Glorious!

My Stack Floweth Over

I suppose you'd have to have been hiding under a rock to not know this by now if you're any sort of real geek, but Jeff Atwood (of Coding Horror) and Joel Spolsky (of Joel on Software), both luminaries in the software-development-blogging arena, have started a new site called Stack Overflow!

The site right now is a placeholder page but they've already recorded the first in what will be a weekly podcast where they talk about what the site will be and various other topics as they come up. The first episode unfortunately has pretty ordinary audio quality - it actually sounds like each of them recorded the other over the phone rather than recording themselves and then merging the audio - but from what Jeff says on his Twitter feed, it doesn't look like it's going to improve. Strange that they'd go for a smaller file size over better audio quality in this day and age.

As something of a podcast addict I'm overjoyed at this new offering, and I look forward to seeing what the site will evolve into!

ValidationResult<T> FTW!

In a previous post I described a "ValidationResult" class we've created here at work for "lazy validation", where the "IsValid" property is a nullable boolean and is set to null if the code can't determine its value without the user's help.

Earlier this week we were working on a method that should create a row in a database table and return the identity (a Guid) of the row it just created. However, we also wanted to return a ValidationResult (true if it succeeded, false with an error message if it failed). We started out by using an "out" parameter, like this:

public ValidationResult CreateFoo(int someProperty,

string someOtherProperty,

out Guid id)

This design, however, had a few problems. Firstly, we're trying to unit test everything in this project, and our mocking framework, Moq, can't mock "out" parameters. I don't think this limitation is specific to Moq, but it was enough to make us consider a different approach. Secondly, FxCop actually complained that "out" parameters should be avoided, as per this rule.

So we needed a way to return two things: the success/failure result of the call, and the identity of the created item. Enter ValidationResult<T>!

With this new class, we have an extra bit of "payload" data that we can return along with the validation result. So now our method signature looks like this:

public ValidationResult<Guid> CreateFoo(int someProperty, 

string someOtherProperty)

... and it has some code like this to return its stuff:

var vr = ValidationResult<Guid>.Success;
vr.Data = (Guid)param.Value;
return vr;
Pretty handy! Now we can test it and we're down one FxCop warning!

TDD, Pipelining, Queries, Oh My!

Over the past week or so we've been keeping an eye on Rob Conery's blog, watching his series of "MVC Storefront" screencasts. Rob's putting together an e-commerce site using the new ASP.NET MCV framework, and he's doing it from the ground up as an exercise in test-driven development (TDD).

Rob's approach involves a "repository" layer, which is essentially a class that's very close to the underlying data store. If I'm right, it'll eventually give him basic CRUD operations that he can call from the next layer up, his "service" layer. Right now it has a "GetProducts" method which returns an IQueryable<Product> - so he has a way to get a query that can give him a list of all products. To that he has added some extension methods so that he can dynamically add "where" clauses to that query. He ended up with code like this:

var prods = _repository.GetProducts().WithCategory(1).ToList();

This is a really interesting approach, in that he's able to "pipeline" his "where" clauses to chain together a query, which he then "executes" by calling ToList() at the end.

Here's where I'm not following him though:

Right now, all of Rob's tests are hitting a faked-out version of his repository. He's got his GetProducts fake method just returning a dummy list of products which he's instantiating on the fly. His goal, as I see it, is to eventually plug in a LINQ to SQL implementation so the queries are passed directly to the database. However, LINQ to SQL is going to want to define its own entity classes for Product, Category etc. I know that LINQ to SQL has some sort of rudimentary mapping technology so you can map your custom classes to it, but is that the direction it's going to go? What if his Product class had an actual Category property of type Category, rather than a CategoryID property of type int? Surely then it would be much harder to map that directly to a LINQ to SQL entity?

In a small project we've just started here at work, we're trying to emulate Rob's approach - TDD, repository and service layers etc. However, I don't think I want to go down this "chaining queries" path using IQueryable<T> just yet - I'm just not convinced that it'll work when we come to implement the repository as a LINQ to SQL class. Instead we're going to give the repository methods that wrap entire queries (eg "GetProductsByCategoryID").

I'm really looking forward to part four of Rob's screencast, though - it's has been very enlightening.

AWDNUG April - Unit Testing

Last night at our April meeting of the Albury/Wodonga .NET User Group I did a small presentation about unit testing and mocking.

I'm a self-confessed noob at this stuff: I have a keen interest in the concept of test-driven development, testing, mocking, all that stuff, but I haven't ever actually done it in a "real" project. The presentation was a great way to show the idea to a bunch of guys who were unclear on the concept, and it really showed how practical unit testing can be.

For the demonstration I used NUnit for my tests, and Moq (a relatively new project) for mocking. Daniel "kzu" Cazzulino was kind enough to email me an early build of version 2.5 of Moq to use for the presentation, so big thanks to him.

Anyway, the whole night went swimmingly, and I think I've inspired a few people (including myself) to look closer at unit testing.

Next month's AWDNUG is our local Heroes Happen {Here} event to launch the 2008 suite of products from Microsoft! Hope to see you there!

Still Alive

Wow - I just realised how long it has been since last I blogged!

Rest assured I'm still alive and kicking. If you need constant updates (and who doesn't?) then make sure you follow me on Twitter.