Category Archives: General

Refactris

This post is in lieu of writing a proper one, either on the generic maths operators which Marc Gravell has been hard at work on, or on C# 4 which I have a number of opinions about (no surprise there). I will write about both of those topics, but I really ought to do some more work on the manuscript for chapter 2 of the book before I go to bed. Posting a blog entry is a reward for finishing indexing chapters 2 and 13, but both of the serious posts will take longer than I really have time for right now.

So, Refactris. This is a silly idea born a couple of weeks ago, at work. You see, several months ago, I had run out of work on a Friday afternoon at 4pm. My then-team-leader, Rohan, foolishly challenged me to write console-mode Tetris in an hour. I had great fun, and had a demonstrable game of Tetris working precisely one hour later. Now combine that with refactoring, one of the ideas of which is that you can remove lines of code by finding code duplication etc. Put the two together, and you get Refactris.

Letters, digits and symbols would fall from the top, and whenever they landed (in a normal Tetris manner) the game would try to compile the code in the bucket, finding as much to compile as possible. It would try the top line, then the top two lines, then the top three lines, etc, until it reached the bottom – then try the second line, the second and third lines together, etc. Code which compiled would be removed.

Clearly it’s a stupid idea, and I haven’t actually tried to implement it or anything silly like that. Funny enough to share though, and if any of you wish to give it a go, I’d love to see the results.

LINQ to Silliness: Generating a Mandelbrot with parallel potential

I’ve been writing about LINQ recently, and in particular I’ve written a small amount about Parallel LINQ. (Don’t get excited – it’s only about a page, just to mention it as a sort of “meta-provider” for LINQ.) I was wondering what to use to demonstrate it – what general task can we perform which could take a lot of CPU?

Well, I used to be quite into fractals, and I’ve written Mandelbrot set generators in various languages. I hadn’t done it in C# before now, however. Calculating the colour of each pixel is completely independent of all the other pixels – it’s an “embarrassingly parallelizable” task. So, a great task for PLINQ. Here’s the “normal LINQ” code:

 

var query = from row in Enumerable.Range(0, ImageHeight)
from col in Enumerable.Range(0, ImageWidth)
select ComputeMandelbrotIndex(row, col);

byte[] data = query.ToArray();

Changing this into a parallel query is really simple – although we do need to preserve the ordering of the results:

var query = from row in Enumerable.Range(0, ImageHeight).AsParallel(QueryOptions.PreserveOrdering)
from col in Enumerable.Range(0, ImageWidth)
select ComputeMandelbrotIndex(row, col);

byte[] data = query.ToArray();

Without being able to actually use PLINQ yet, I can’t tell how awful the order preservation is – Joe warns that it’s costly, but we’ll see. This is on a pretty giant sequence of data, of course… An alternative would be to parallelize a row at a time, but that loses some of the purity of the solution. This is a very, very silly way of parallelizing the task, but it’s got a certain quirky appeal.

Of course, there’s then the code for ComputeMandelBrotIndex and displaying a bitmap from it – the full code is available for download (it’s a single C# file – just compile and run). Enjoy.

Update!

This blog post has been picked up by Nick Palladinos, who has written his own Parallel LINQ provider (much kudos for that – unfortunately for me the blog is in Greek, which I don’t understand). Apparently on a dual core processor the parallelised version of the Mandelbrot generator is indeed about twice as fast – it works! Unfortunately I can’t tell as my laptop only has a single core… it’s very exciting though :)

Yeehaa! Framework source code, here we come!

It’s just been announced on Scott Guthrie’s blog that Visual Studio 2008 will allow debugging into the source code for the .NET framework – at least for some areas. I’ve wanted this to happen for a long time, and blogged about it before now – but I didn’t honestly expect it to happen, at least not for a long time.

This is a fabulous move, and one which MS should be commended for. I’m sure many people will spend a long time discussing whether the licence can be described as “open” (you can’t copy the code or recompile it) but to me that’s relatively unimportant. I will be able to view it, debug into it, and potentially spot/report bugs in it. I don’t really have much use for copying or recompiling it, personally.

Well done, Microsoft.

On a side note, I’d love to see the traffic logs for Reflector before and after this happens :)

Announcement: Partnership with Iterative Training

I’m delighted to announce my association with Iterative Training, a new .NET training company in the UK. It’s been founded by a colleague of mine and his girlfriend, and ran its first course earlier in the year – a WCF Master Class taught by Juval Löwy of IDesign. As you can tell from its starting point, Iterative Training is dedicated to providing really top notch training from genuine experts.

Where do I fit in? Well, I’m promoting the company on my website (the GoogleAds are now replaced with course adverts – but still without getting in the way of the content, I hope) and will be attending the last couple of days of TechEd in Barcelona to give some visibility to what we’re doing. Beyond that, I may well end up giving “taster talks” at user groups, and possibly even end up as a very occasional trainer. Who knows what the future holds?

I’m really excited about this opportunity to see more of the training side of development, and hopefully contribute to it. I have no idea what proportion of my readership comes from the UK, but I hope that if you do, and if you’re interested in some of the new .NET technologies, that you’ll have a look at the courses on offer and hopefully find something of interest. If you have suggestions for courses we should be offering but aren’t, we’d love to hear them – although we’re trying to keep to a relatively light schedule for the first year or so, focusing on quality rather than quantity.

None of this changes my existing situation: I will still keep up this blog and my articles, the book is still in progress, and I’m still in permanent employment. It’s expanding rather than replacing my range of activities :)

Writing user interfaces

Some of you may know that I don’t do a lot of user interface work. Well, in the last couple of weeks I’ve been doing little but user interface work. I thought it might be time to share a few reflections.

Designers

The designer in VS 2005 is actually very good – for a designer. It still has its “thou shalt not touch this bit of code” which of course you then have to touch in order to include some controls which aren’t in the toolbox, but overall it’s pretty reasonable. I particularly like the “GenerateMember” property it uses to decide whether or not to create a member variable for controls. No more silly label variables for no reason!

One day I’ll be able to use WPF/XAML, which is of course another step up again, but until then this isn’t too bad.

TableLayoutPanel

Hooray, a half-decent layout in WinForms. Whatever people may say, just using Dock and Anchor doesn’t give enough control over layout in my view. Lining things up with absolute positioning should have been a thing of the past years ago.

TableLayoutPanel appears to have some significant shortcomings, however. In particular, I was in a situation where it would have been really nice if TLP allocated all the “Absolute” sizes, then gave as much as possible to the AutoSize rows, then gave any spare to the percentage rows. However, it goes top to bottom, left to right. Basically I wanted a couple of buttons below a multi-line label, and for the label to become a scrolling area if there wasn’t enough room for it, with the buttons always present just below the label. Maybe there’s a way to lay this out the way I want, but having sworn over it for most of an afternoon, I’ve given up.

Scrolling is also a pain – it tooks me a long time to get any scrollbars to appear when I wanted, and I still don’t know exactly what triggered it suddenly working. Even now they aren’t quite right, as the appearance of a vertical scrollbar forces a horizontal scrollbar to let you get at the bit of the panel which is now taken up by the vertical scrollbar – even if there’s nothing there! All very frustrating.

Overall architecture

I really suck at this. I’m trying to separate everything out appropriately, but I don’t know enough about it to cope when things get tricky. All the samples of MVC, MVP, Humble Dialog etc are fine when they’re doing relatively simple stuff, but it feels like UI is particularly prone to “I know I shouldn’t have this logic here really, but it’s much easier than doing it properly…” Hmm.

Frustration/Joy

I have really mixed feelings about the satisfaction derived from UI. A lot of the time it seems like very slow work – implementing a small UI feature seems to take a lot longer than implementing a small server-side feature – but when it’s working, it’s very visible. You can show people the results. Just demonstrating hundreds of working unit tests and a few database tables filled with data doesn’t have nearly as much of a pull. I think a prototype UI (not prototyping the real UI, just enough to demonstrate backend features) is possibly the way forward here.

Basically, I suspect I’ll never be a GUI person at my core. I can grow to be passably good at it, but I suspect that you have to keep working at it for a high proportion of your time to know all the gotchas and tricks involved and keep a clean design.

 

In other news – the book is still coming along. Sorry to have kept so quiet about it, but I’m hoping I’ll be able to announce something properly (and tangibly) fairly soon.

Who do the “stars” look up to?

I follow a reasonable number of blogs. Not a vast number, but most of the ones I read (about computing, anyway) are written by people who are way out of my league. I mean, I can just about peer into the league of people like Simon Tatham who I’m proud to have as a friend even while I generally gape at his grasp of algorithms (verging on the obsessive at times, I have to say). Such people I regard as in a league above my own, and that’s fine – but then there are people like Don Box and Joe Duffy. If ever I’m tempted to start regarding myself as an “expert” in threading because some very kind people occasionally label me that way, all I need to do is think of Joe to come back to reality.

So my question is: who do these people look up to? Each other? I mean, I’m sure Don wouldn’t want to go head-to-head with Joe about detailed concurrency issues, and Joe probably wouldn’t try to bluff about web services around Don (which isn’t to say they couldn’t stimulate interesting discussion in each other’s area, of course). But there must be some recognition that they’re playing in the same league, just with slightly different equipment. Who do they regard with the sort of awe I have for them? Is there some uber-elite which us mere mortals don’t even hear about?

I think it’s healthy to be able to see people who are smarter than you. It can be a bit scary when you see just how wide the gap is (or at least appears to be) but it’s generally a good thing. The web has made this much easier – and simultaneously made it harder to be “big fish” because everyone gets to see how big the pond is.

If I get delusions of grandeur (well, more of them) I hope my friends will kick me back down to the right league. And if they don’t, I sincerely hope I’ll still be able to read the works of people like the ones listed above, and shrink back to Ronnie Corbert size again. Disclaimer: this doesn’t for one minute mean that I’ll avoid plugging my book like crazy when it’s nearer the release date.

Why hasn’t Microsoft bought JetBrains yet?

For those of you who aren’t aware, JetBrains is the company behind IntelliJ IDEA, the Java IDE which I’ve heard amazing things about (I’ve tried it a couple of times but never got into it – I think I need an expert sitting beside me to point out the cool stuff as I go) and ReSharper, the incredibly useful (although somewhat resource hungry) add-in to Visual Studio that turns it into a respectable IDE.

What would happen if Microsoft bought JetBrains?

I’m sure that killing off the reportedly best Java IDE would do .NET no harm (even if it would be a fairly cruel thing to do, and still leave other perfectly good IDEs in the Java space), and surely they could use the ideas and experience of the company to improve Visual Studio significantly. I strongly suspect that tighter integration could make all the ReSharper goodness available with less performance overhead, and while it’s no doubt too late now, wouldn’t it have been wonderful for all of those features to be available in Orcas?

Anyway, just a thought.

Implementing Ruby on .NET, and the importance of specifications

This morning, when following links to Jamie Cansdale’s ongoing tiff with Microsoft (best of luck, Jamie) I came across Martin Fowler’s concerns about Ruby on .NET. Most of the responses I’ve seen have – entirely reasonably – been about Microsoft’s relationship with open source and with the community as a whole. All of that is fine, but two points particularly caught my attention in Martin’s post:

Soon-to-be-ThoughtWorker Ola Bini, a JRuby committer, reckons that it’s almost impossible to figure out how to implement a Ruby runtime without looking at source code of the MRI – but Microsoft imposes drastic limitations on its employees’ ability to download open source software, let alone look at the source.

and

The overwhelming sense I heard in the community was not “Ruby will kill evil Microsoft” but “how can we overcome the problems to get Ruby on Microsoft.”

Now, as a disclaimer, I’ve done virtually no Ruby. I reviewed some early drafts of Ruby For Rails, and I’ve heard wonderful things about it from my ThoughtWorker friend Stuart, but I haven’t used it. As such, I certainly am in no position to judge it as a language in terms of elegance, power etc.

However, the first quote above raises a concern. My reading of it is that unless you look at the MRI, you don’t know how Ruby is meant to behave, and thus can’t implement it. Frankly, that puts me off the language a bit. I’m all for the agile idea of only documenting when it really adds a benefit, but surely specifying how a language is meant to behave is a real benefit. Now, I know there will always be kinks in languages where sane developers wouldn’t use the corner cases, but those developers who have used them really want them to work on every implementation, but I would hope those can be documented at the same time. Heck, there are plenty of details like that in C#, for instance.

This also answers the second quote I’ve included – what the community can do to overcome the problem of getting Ruby onto the .NET platform. If one of the main problems is that the team can’t look at the MRI source code, and currently the MRI source code is the only way of understanding how an implementation should behave, then surely changing the latter state of affairs would overcome the problem and help the rest of the community at the same time. Microsoft changing its interaction with the open source world would also overcome the problem, but in some ways that’s irrelevant – it in no way stops the community from writing a fully-fledged Ruby spec.

My concern when writing this is that this world is full of very smart people, and Martin’s obviously one of them, so I guess I’ve missed something. I’ve seen that there are some projects to specify Ruby’s behaviour, but if these projects are going well then that should make John Lam’s task more feasible, and if they aren’t then that would call into question either the Ruby community’s desire to see Ruby on .NET or its competence to actually get a spec together. Having watched a small part of the process of getting Groovy adequately specified, I know it’s a lot easier said than done, but even so…

So, what am I missing?

Wacky Ideas – Introduction

I’ve been having a few wacky ideas recently, and I think it’s time to put them to virtual paper. They’re mostly around how we think about OO, and how future languages and platforms could do things. I very much doubt that any of them are new. I suspect they’ve been mulled over by people who really know how to think about these things, and then write papers about them. Probably using TeX. I’m not going to that much effort, so there will be several things I haven’t thought through at all. I won’t go so far as to say that’s your job, but knowing my readership you’re likely to come up with loads of things I’d never considered anyway.

Most are likely to be phrased in C#/.NET terms, but they’re likely to apply to Java anyway. Some may have a few better fits in one language than another – I’ll point them out when I think of them.

I don’t necessarily think these are good ideas. Some are probably stinkers. Some may well be useful. Some may even occur one day. Some are bound to exist already in languages I don’t know, of which there are many. Almost all of them are likely to introduce new syntax (or take some away) which makes them non-starters for many scenarios. Don’t take it all too seriously, but I hope you have fun.

What would make a good Java book?

So, Groovy in Action has been out for a little while, and I’m missing it – or rather, book writing. I’d like my next project to be a solo effort, almost certainly on Java. However, I’m interested in hearing what you good folks think would make a good Java book. I’ve got some ideas myself, but I’d rather hear unprejudiced opinions first. (I may be soliciting more feedback at a later date, of course.) So, shoot – what would you like me to write about?