DotNet

Silverlight is pretty cool

Oliver Brown
— This upcoming video may not be available to view yet.

More than two months since my last post. Which means I suddenly have a lot to say. Beware, rambling may follow… Nearly five months ago I claimed to be making “rapid progress with language learning”. Well obviously not rapid enough to actually reveal anything. Well that might be at an end soon.

One of the problems of writing the app using things like LINQ means most people will have other things to install to use the app (.NET 3.5 specifically - and possibly .NET 3.0 for non Vista users) and even then it’s limited to Windows users as Mono support for Windows Presentation Foundation will be a long way off (if they do it all). Since Silverlight 2.0 is supposed to be really cool and now supports a big chunk of the widgets from standard WPF (and has has quickly developing Moonlight support), why not write the app in that? So that’s what I’ve been doing. And it was a lot easier than I thought.

The first piece of easiness I found was that I only had to make like three changes to my non-UI code to make it compile as a Silverlight DLL. Unfortunately I can’t persuade Visual Studio to compile it as a Silverlight DLL and a normal DLL in one go, so I’ve currently got the same code added as two different projects and I copy the code between them (not ideal). The only real work I had to do was reimplement my data provider. When I started, I cunningly made sure that all resources (lessons, media, user progress) were grabbed from a data class. I wrote a new class that fetches it from a RESTful server (more on that in another post). So hopefully, a nice Silverlight version of the app will be public soon.

About Silverlight

For those that don’t know, Silverlight is Microsoft’s answer to Flash. Apparently. I’m not sure if it’s that a good analogy really. Silverlight 1.0 basically gave you access to a nice environment to draw things in the browser and then manipulate it with Javascript. Or something. To be honest I didn’t really care about version 1.0 since writing complicated things in Javascript doesn’t sound like fun. Silverlight 2.0 (formerly Silverlight 1.1) on the other hand gives you that same environment but the ability to manipulate the things with compiled .NET assemblies written in any CLR language and comes with implementations of a lot of the widgets in the WPF.

Google Docs rule - if you use them right

Oliver Brown
— This upcoming video may not be available to view yet.

I’ve been vaguely using Google Docs (specifically Spreadsheets) since it came out but never to do anything actually important. Most of the time I just had a list I need sorting, or if I was feeling sophisticated I’d use it to decide on what was best value for money (how much £/GB a range of hard drives were for instance). Recently I started using it to plan lessons for the language learning app. The ability to use it from work (or any other computer I might be on - including viewing it on my Nokia 770) was useful, but in the end I was only really writing a list with it.

Until now. I now have a nifty little C# app that generates modules directly from a Google Spreadsheet which is definitely a Good Thing. I’ve been thinking of writing an app for module editing for a while since writing them by hand is tiresome and error prone. Google Spreadsheets does half the work for me by providing the user interface for generating a table and then provides access as simple XML. Which brings me to the matter of actually accessing the data. Google provide a client library in C# for accessing quite a lot of their API. I tried using it but found it a little confusing. Luckily since I was just wanting to query data, I discovered that raw access was actually easier. You simply make a GET request to http://spreadsheets.google.com/feeds/worksheets/_key_/public/values (where key is provided to you when you “publish” a spreadsheet - access to unpublished spreadsheets requires authorization which is more complicated). This gives you an Atom feed of URLs to the individual worksheets which them contain Atom feeds of either rows or columns (your choice). The query power of LINQ (along with XElement, XAttribute etc.) make transforming the feeds into modules really easy. In fact the code that does the hard work (takes a spreadsheet key and generates the XML) is only 102 lines long, and that’s including unnecessary spacing to make the LINQ more readable (the main LINQ query is 35 lines).

LINQ is magical

Oliver Brown
— This upcoming video may not be available to view yet.

The secretly named language learning app has been revamped to use LINQ for most of the XML handling. For those that don’t know, LINQ is a new technology that provides querying functionality in the .NET world. In my case I’m using LINQ to XML and it has seriously cut down on the size of the heaviest methods. Also, the part of LINQ to XML that I found least interesting when I read about it is actually the part I’ve found the best - the new XDocument API. Anyway, LINQ combined with a new USB headset that provides some actually quite good audio means that the important fundamental features have been implemented and work. At the moment it can:

  • Generate lessons based on vocabulary1 modules
  • Generate lessons containing past content with the correct repetition timing.
  • Actually play the lessons (but only on Windows2)

There are a few more things I want to add before I release any of it (like more audio for a start). But I thought I’d at least point out development is still happening :o) 1Instead of the Conversation > Phrase > Term style of Pimsleur I’ve decided to go for a more freeform approach to start with (inspired by me listening to Michel Thomas again). A vocabulary module just contains list of words and phrases that are processed in order. 2I still need a cross platform way to play audio. At the moment I use MCI which is part of winmm.dll which is obviously Windows only. Although Wine has apparently implemented it almost completely but I’m not sure how I’d go about making that help me.

So much for Gtk#…

Oliver Brown
— This upcoming video may not be available to view yet.

Well I’ve abandoned my plans to use Gtk# in the language app (which actually secretly has a name now).

The main reason for changing is simplicity. I had a look at the TreeView control in Gtk and decided it was too much work. Although the theory of good MVC separation is good, the user interface is such a small, simple part of my app it wasn’t worth it. The stuff I need from System.Windows.Forms should work in Mono (and .NET 1.1 and hopefully even the Compact Framework).

I still prefer the way Gtk handles layout of controls in general, but I console myself with the Windows form designer in Visual C# Express.

Cross platform games on the PS3 and the Xbox 360

Oliver Brown
— This upcoming video may not be available to view yet.

In case you didn’t know, the PS3 can run Linux. Not only that but it’s officially supported by Sony. You can download (for free) a utility to put a boot loader on to some media (most likely a hard-drive but memory cards, memory sticks and anything else the PS3 can read (and can hold 10Mb) are supported) and set it to boot “Other OS” (that’s what the menu says).

There are already videos on the Internet of it running Fedora. Zac Bowling already has one running Mono, a task simplified by the fact that the cell processor appears as a PPC. So where does the Xbox 360 come into this? Well Microsoft are releasing something called XNA, a modified/extended version of the the .NET 2.0 run-time with emphasis on Managed DirectX that is available for Windows and the Xbox 360. A version of XNA called Mono.Xna that is built on top of the Tao framework is in development. The end result is that in theory, games developed using XNA will run on Windows, Linux, Macs, PS3’s and Xbox 360’s. A few problems still exist. The processor that the PS3 uses is rather strictly an in-order processor so most stuff that isn’t written specifically for that will run slowly (although video playback will be pretty zippy) and so far there is no hardware 3D support for an “Other OS” so XNA (if it were available now) would run slowly.

A safe language on a safe OS

Oliver Brown
— This upcoming video may not be available to view yet.

Have you heard of “managed” code? Generally it refers to code that has no direct access to memory and instead has to access everything through a protected interface of sorts. The main advantages are that a program can’t go poking memory that it shouldn’t and useful rules can be enforced like type safety.

The most prevalent example of managed code is nearly everything running under .NET/Mono. Admittedly you can mark parts as “unsafe” letting you use pointers and stopping the garbage collector arbitrarily moving your data around but most of the usefulness comes from avoiding this where possible.

The problem is, you can’t always avoid it. The main reason for this is you have to access existing non managed systems. Rewriting everything in managed code is not feasible and although you can lessen any problems by writing wrappers so there is only one point of contact between managed and unmanaged code, problems can still occur - the sort of problems the managed code was supposed to prevent.

Microsoft are investigating a solution. After reading that last paragraph, the form of the solution should be obvious but for the most part it’s unworkable in the real world - eliminate all unmanaged code.

A lot of people claim managed code, or specifically .NET is slow and inefficient. Well it is. But it can be made faster. Most inefficiency is caused by a lot of run time checks to make sure everything is as it should be. If the code lives in an entirely managed world however most of these checks can be removed since (barring random hardware failure) the program can be guaranteed to satisfy the run time checks at compile time.

For more details about Singularity, Microsoft’s research operating system written in C#, check out this article by James Larus, Galen Hunt, and David Tarditi over at MSDN.

ASP.NET sucks

Oliver Brown
— This upcoming video may not be available to view yet.

I recently bought a book about ASP.NET: Pro ASP.NET in C# by Apress, mainly because when I was looking for jobs there were lots of ASP.NET jobs advertised. And I have to say I have no idea why. Part of the problem may be that is book isn’t very good (there are bits of vague contradictions and a general obsessive (and inaccurate) preachiness about it) but I think there are major limitations to ASP.NET.

Firstly the inability to post to a different page. Who the hell decided that was good idea? I know it can be faked but that’s just silly. And you can only really have one form on a page. Well you can only have one “rich” form that ASP.NET can access in a clever and high level way.

I’m assuming people will disagree with me (if not, why is it so popular). If you do, please explain why ASP.NET is supposed to be so amazing because I don’t see it…

Updated - Clarifying my position on ASP.net

Got Mono?

Oliver Brown
— This upcoming video may not be available to view yet.

A few years ago Microsoft released the .NET platform. It was supposed to be an open standard that anyone could implement although in reality only Microsoft did. That’s all changed now as Mono is gaining momentum.

Mono is a cross-platform implementation of .NET complete with a execution environment (JIT compiler, garbage collector and so on) as well compilers for C# and VB.net. There are sections of it that a largely complete but all the important stuff is there.

The best thing about Mono is that it has stimulated development of .NET tools by people who normally wouldn’t touch Microsoft if they could avoid - specifically lots of open source developers. This includes the creation of some brand new programming languages such as Boo and Nemerle.

Normally a programming language with very few users is useless - libraries won’t exist and you’ll have to do lots from scratch and things are generally bad. However since every CIL language can use and extend features written (and compiled) in any other, this problem goes away. You can take a C# class and extend it in Boo and then put it in an ASP.NET page written in VB.NET.

An important part of Mono for cross platform use is the development of GTK#, a managed version of GTK that allows you to write cross platform windows applications with essentially a native look and feel. Mono Project