Mad Props!

Omniscience is just a Google-search away.

Login

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

AWDNUG June 2010

Last night at the June meeting of the Albury/Wondonga .NET User Group we covered OData.

I spent a few minutes going back over some ground we’d covered last month on Entity Framework, then walked through the steps covered by Scott Hanselman in this great blog post where he creates an OData service from an EF model. The only snag I hit (and it was a pretty major one) is that I didn’t have SQL Server Express installed on my laptop so I was just using SQL Server Compact Edition, which decided it would throw a NotSupportedException when I tried to use it in a web application.

Undeterred, I instead connected to the net and started browsing around the Netflix OData feed, demonstrating how to build queries by altering the URI. I then downloaded LinqPad and wrote some ad-hoc LINQ queries against Netflix data, and finally created a console application in Visual Studio to perform queries of our own.

Despite dwindling numbers, it was a fun evening. We even had a brief look at the Halfwit code. :)

See you next month!

DDD Melbourne 2010

On Saturday, Andrew and I attended the inaugural DDD Melbourne (that’s "Developer Developer Developer Melbourne") "community conference" at Docklands in Melbourne.

Big props to Alex Mackey and Malcolm Sheridan, as well as all the other organizers and sponsors, for what turned out to be a great event.

Keynote Here’s a quick rundown of the sessions we attended (after the introduction and the opening keynote from Roger Lawrence):

Getting Started With Silverlight and SharePoint 2010

Really we just tagged along to this one to get a glimpse of SharePoint 2010 in action. We don’t do any Silverlight and we’re only ‘end users’ of SharePoint, so the presentation was of little real value to us. It was interesting to see just how complex the creation and deployment of SharePoint “features” is, even in Visual Studio 2010. Nalaka ran a very slick presentation though, so all credit to him.

Design by Contract - Code Contracts in .Net 4

One of the most interesting sessions for me was Bill Tulloch’s demonstration of code contracts. Bill had managed to lose all his code snippets while doing some last-minute testing the night before, so this was very much an “on the fly” presentation. Still, he did an excellent job of demonstrating how code contracts work and the benefits of using them.

I’m not sure that I’m game to introduce them into any existing code. Seems like it’s something that would be much better suited to a “green field” project. Still, it’s powerful stuff and gives us an idea of what the future holds in terms of static analysis on code.Code Contracts

Developing your data access layer using ADO.NET Entity Framework 4.0

Prasanna‘s demonstration of EF4 was extremely valuable for me. I’m keen to look at the Entity Framework as a direction for our data access layer (despite being stuck in .NET 3.5 SP1 for the foreseeable future). I was especially happy to see the “code first” (also known as “code only”) approach to building a model. That looked like a really nice “fluent” approach to constructing mappings without having to deal with a design surface or XML files.

Secrets to Becoming a Better Developer  

Sorry, Chris. I really wanted to get to this session (and in fact I saw a few tweets describing it as the “best session of the day”), but I was engaged in conversation with a  bunch of folks from the Twittersphere outside, and we didn’t even realise that the next session had started until it was already half way through. So we missed this one, but I found our conversation outside very interesting, so it wasn’t a total loss.

Building large scale LOB applications with WCF RIA Services  

By this stage, late in the day after a late night and an early morning, I was really starting to struggle. My eyelids were heavy, and I actually caught myself nodding off during Sergey’s presentation. I’ll be honest: This presentation was dry. There was very little code – mostly slides – and that meant that you had to pay close attention to what Sergey was saying to follow along. Perhaps if I’d not been falling asleep I would’ve enjoyed the session more, but on the other hand, if there had been more code I might not have been falling asleep.

Non-Relational Databases  

Tarn’s presentation was probably the most entertaining of the day. He did the whole thing from Ubuntu, using (I think) Vim and Monodevelop along with the command line to demonstrate his code. It was a fun look at the world of “NoSQL” with some compelling arguments.

The Wrap Up

That's some bad hat, Slace. The final “session” was a chance for the guys to give away some prizes and thank the sponsors. Wouldn’t you know that my name was the first to be drawn for a few ticket to REMIX Australia? Unfortunately I had to turn it down ‘coz I can’t make it to Melbourne when it’s on, so instead I got a cool organizer/presenter’s polo shirt which I will wear with pride to our local user group next month. :)

The best thing about events like these is the opportunity to meet face-to-face with people I consider “friends” online. I got to meet (for the first time) Paul Jenkins, Brendan Forster, Aaron Powell, Michael Kordahi and Nick Josevski, as well as catch up with some old friends that I usually only see at Code Camp Oz.

If you missed DDD Melbourne, I can recommend checking out DDD Sydney, which is scheduled for late July at this early stage. I probably won’t be able to make it all the way up there, but if it comes off as smoothly as DDD Melbourne, it should be awesome.

Username Auto-complete in Halfwit

A couple of nights ago I finally started working on username auto-complete in Halfwit. What’s username auto-complete? That’s the feature whereby you type an “@” sign, and then as you type extra characters, Halfwit looks up your text in the list of recently-seen users and fills in the name for you. Here’s a screen cap:

image

So in this screenshot I’ve typed “@m” and Halfwit has filled in the first matching name – my own. I then typed “o” and it’s picked the next match – MossyBlog (you can pay me later for the free linkage, MossyBlog).

For the technically minded, here’s how it works.

First, I keep a static List<String> of the 1000 most recently seen usernames. I figured 1000 usernames “ought to be enough for anybody”, but I can make that number larger if the need arises.

Next, I’ve defined an attached property that I can apply to any TextBox. It hooks the KeyUp event of the TextBox and does some simple string manipulation to find a matching name.

The cool part is that this lookup can be based on either the text after an “@” sign, or just the whole text. We need that because there’s another TextBox in Halfwit where you can simply type a username without the “@” prefix. The auto-complete works there, too.

I won’t include the code here – you can grab the whole thing from CodePlex. Check out the “UsernameLookup.cs” file for the attached property class.

Saved Searches in Halfwit

Build 57 of my Twitter client Halfwit is now available, with a bunch of new features since I last blogged about it. The one I’ve added tonight is the ability to talk to Twitter to save common searches.

When you visit the Search page, Halfwit will ask Twitter for a list of saved searches and populate the items of the ComboBox with them. If you want to save a search you can simply press the “Save” button to save it back to Twitter. Here’s a screenshot!

Halfwit's Saved Searches

As you can see, each saved search has a “Delete” button alongside it in case you want to get rid of it.

Give Halfwit a try today and let me know what you think!

Immutability in C# 5?

On the latest episode of .NET Rocks, Carl and Richard spoke to Anders about the new release of .NET and C# and what the future might hold. Predictably, Anders revealed that parallelism will be a focus on C# 5, with language enhancements to make use of things like Parallel Linq.

One of the things he spoke about was how difficult it is today to make a truly immutable reference type, with compile checking etc. This got me thinking about how immutability might work in a hypothetical future version of C#, without adding new keywords or language constructs. Immediately the “readonly” keyword sprang to mind.

The readonly keyword is applied to fields in a class. Fields declared as readonly can only be initialized inline or in the type’s constructor. Once they’re initialized, they are, as the name implies, read only.

public class Foo
{
    public Foo()
    {
        Bar = 5;
        // Bar can now only be read 
    }

    public readonly int Bar;
}

Imagine if you could declare a class as readonly. All of the class’ fields would have to be declared as readonly too (a bit like the way static classes can only have static members), and its properties would have to have getters only – no setters. Any fields or properties would also have to be either a value type or a similarly read-only reference type, so there was no cheating by changing the property of a property. Let’s mock up a class to see what it might look like:

public readonly class Foo
{
    public Foo(int bar, string buzz)
    {
        Bar = bar;
        _buzz = buzz;
    }

    // this would be fine 
    public readonly int Bar;

    // no setter on our property, so that's fine too 
    private readonly string _buzz;
    public string Buzz { get { return Buzz; } }

    // Fizz is a readonly class so this is also fine 
    public readonly Fizz Fizz;
} 

This class would be guaranteed, at compile time, to be immutable. It would be safe to pass around between threads since nobody could change its state. It’d be fine to add methods to it which perform calculations based on the class’ fields and properties, since even they wouldn’t be able to modify the values (they’re all read only too).

I suppose the next step in this evolution would be a way to constrain methods or generic classes to only accept readonly types as their parameters, so that multithreaded code could be guaranteed not to change state. A simple “where T : readonly” generic constraint might suffice.

In theory it might be possible to take an existing “non-readonly” class and wrap it dynamically into a read only “proxy” (similar to a mock), but that would be complicated since any reference-type properties would need to be wrapped in a similar way, to prevent users changing their values. Not only that, but any collection property on the class would have to be converted to a ReadOnlyCollection or IEnumerable to prevent it from being modifies. It’d be a pretty hardcore piece of code.

I think a way to create a compile-time guaranteed immutable class in C# would be very helpful for people writing massively parallel code. This could be one way to do it … maybe the gurus like Anders have something entirely different in mind. Time will tell!

Windows Mobile development in Visual Studio 2010

So Visual Studio 2010 and .NET 4 have been released, and they’re awesome. I’ve been using VS2010 since beta 2, and it’s a big step up from 2008 when it comes to the code-editing and designing experience.

Which is sad, because I can’t use it.

You see, Microsoft have recently announced Windows Phone 7, which is an all new operating system for mobile devices. It looks fantastic, and I’m really excited about the announcement. To develop applications for WP7, you must use Silverlight. Again, a great idea and I’m all for it.

However, Microsoft seem to have decided that Silverlight on WP7 will be their only mobile development strategy going forward, and have opted to drop any support for Windows Mobile/.NET Compact Framework in Visual Studio 2010. Basically if you want to continue developing your Windows Mobile applications, you’re stuck in Visual Studio 2008.

Let’s be honest about Windows Phone 7 and the enterprise:

Windows Phone 7 is slated to be released some time at the end of this year. Apparently there’ll be a “classic” version that allows enterprises to deploy their own applications to the device rather than going through the public “marketplace”.

That means that we might see in Australia early next year. More realistically it’ll be late next year.

Even if we do, our company has a significant investment in Windows Mobile devices. We have as many WM2003 devices as we do WM6. There’s no way we can simply throw those away and upgrade all our devices to WP7.

If we go by our historical turn-around in devices, I’m looking at being stuck with Windows Mobile until at least 2012, probably more like 2014.

Since our major system here at work targets both the desktop and mobile platform, we have both kinds of projects in every solution. That means we can’t open any of our class-library solutions in Visual Studio 2010.

So right now we have two options:

1. We split the code into separate solutions (one for mobile and one for desktop), but the mobile solution would still just be “links” to the desktop source code. Then we could use VS2010 to modify the code, but we’d still have to use VS2008 to build the mobile projects. Since the two projects would be separate, there wouldn’t be any instant compiler feedback if a change you made in the desktop project broke the mobile project.

2. We stay in Visual Studio 2008 for all our solutions except maybe the WPF-based desktop application. That’s really depressing, since it means we can’t use any of the new .NET 4 features – VS2008 will only compile all the assemblies it depends on to .NET 3.5.

I kind of feel like I’m stuck under water with Microsoft’s boot on my head. I’ve seen hints here and there that a Windows Mobile development “toolkit” for VS2010 will be released out of band some time in the future, but nothing concrete.

AWDNUG April 2010

Last night’s meeting of the Albury/Wodonga .NET User Group featured a presentation by Nathan on NHibernate and Fluent NHibernate. For those of us (yes, myself included) who haven’t really played with NHibernate it was an edifying experience.

We also had a few new faces, which was great to see.

Next month we’re going to continue on the ORM theme by looking at Entity Framework 4. Hope to see you there!

I’m an MVP!

I mentioned it on Twitter on Friday, but figured I might as well announce it on my blog too:

I’m an MVP!

I was awarded Microsoft’s “Most Valuable Professional” award for the “Client Application Development” category. It’s the first time I’ve received an MVP award, so this is a big deal for me.

I suppose the main reason for my nomination was the time I put into helping people over at Stack Overflow, and I intend to keep doing that because it’s a lot of fun! Of course, releasing Halfwit as open source and contributing to the local user group probably helped too.

Anyway, I’m off to learn more about the benefits of being an MVP!

I’m 37! I’m not old!

Happy birthday to me!

I’m on a Podcast!

I’ve finally made it! ;-)

Richard Banks, who has just kicked off the Talking Shop Down Under podcast, invited me on to episode 2 to chat about Halfwit and anything else that came up in conversation. It was a thoroughly enjoyable half-hour. Give it a listen on your next commute and let Richard know what you think – I’m sure he appreciates every bit of feedback.

I just hope he makes it past the “difficult second episode”!