Friday, December 29, 2006

I've got a new camera


I've got a new camera, originally uploaded by b3ardman.

It's a Canon Powershot A710 IS, and already I've killed the batteries that came with it.
So far, it seems great. I'm loving the 6x Optical Zoom, and the all round photo quality seems great. I'm going to have to play with it some more. I took a picture of a christmas card from across the room, and you can read the writing in it and everything.
It does up to 7.1 Mega Pixel, and, although I'll probably never really need that power, it seems sharp as anything, so lower resolutions will be even better.
It appears to be simple enough in Point & Shoot mode, but the settings can be played with and tweaked. And, as it's a digital camera, I can erase it and put it back into P&S mode when it all goes stupidly wrong.
Best of all, is that it's about 1/2 the size of my old camera, which will hopefully mean I carry it around with me more, and thus take more pictures.

Google logging in and out

My blog is with Google, and I use Google Reader and Google Mail. They all share the same log in mechanism. This is great, as I only have one set of credentials to remember. However, it backfires massively when I have blogger, reader and gmail open in different tabs, and then sign out of one of them. Suddenly, it all stops working. Google Mail and Reader and Blogger all behave differently in this situation. Blogger and Mail behave okish - both requiring you to sign back in somehow. But Reader just kind of silently stops working. The worst thing is that I have to sign into each app separately, rather than it picking up that I'm signed in again and getting on with it.

Thursday, December 28, 2006

Putting methods in the correct place

Object-orientated programming is all about encapsulation - the principal whereby an object exposes only what is needed by other objects and, by doing so, remains in control of its state.
For example, your Collection class exposes methods to add, retrieve and remove items, as well as a Count property, which indicates how many items it contains.


In real life, however, the concept of an Item or a Collection are way too abstract. For example, you might have a collection of stamps, trains, pc components, mobile phones, screw drivers, or you may have a list of things to do, telephone numbers or groceries to buy (a shopping list!). The terms "collection" and "list" need qualifying - what is it a collection of? What does the list list?
In your program, you no longer have a collection, you have a Pupil Collection (first example that came to mind). This is exposed as a property of your Class class.

You've got this far, and then you find you need to check if a Pupil is in a Class, so you write code like this:
public class Class
{
    public PupilCollection Attendies;
    //other methods
    public bool ContainsPupil ( Pupil pupil )
{
for ( int i = 0; i < Attendies.Count; ++i )
{
if ( Attendies.GetPupil(i) == pupil )
return true;
}
return false;
}
}
Then, a few days later, you find another class needs to see if a Pupil Collection contains a Pupil. So, you write that same method again. And then, in another few days, you find another class that needs to do the same thing. In fact, checking whether a Pupil is in a Pupil Collection is a really common thing.
So, what could you have done differently?
How about if, instead of having the Class iterate through the Pupil Collection, have the Pupil Collection iterate through itself, like this:
public abstract class PupilCollection
{
    public bool ContainsPupil (Pupil pupil )
{
for ( int i = 0; i < pupils.Count; ++i )
{
if ( pupils[i] == pupil )
return true;
}
        return false;
}
}
public class Class
{
    public PupilCollection Attendies;
    //other methods
    public bool ContainsPupil ( Pupil pupil )
{
        return Attendies.ContainsPupil ( pupil );
    }
}

And the next time you need to see if a Pupil Collection contains a Pupil, the code's already there. Your code looses a whole load of duplication, and reads nicer, simply because you moved a method.
In this case, we can start to think about things like specifications [pdf], and other more intricate designs, because we no longer look at the code for the Class and have to think about how it's doing what it's doing.

Using tools (and Code Smells)
I've been using Resharper for the past two years, and I can hardly use Visual Studio without it (well, I can, but I always get frustrated that + and ++R do nothing).

Its Extract Method option is probably the one I use most. Not only does this decide what to have as parameters for the method, but the majority of the time, it's "Declare Static" box is checked too - meaning that the method it will create will be a class level method.

When it does this, I take it as a sign to assess whether this newly created method wouldn't be better off somewhere else. Sometimes it doesn't make sense to move it, but often, just thinking about what the new method does means I put it somewhere more appropriate, and I find my code reads a lot better for it.

So, next time you see a static/class level method, ask yourself if it doesn't belong elsewhere.

Seasonal stuff

Happy christmas and all that kind of thing.
I can write some other stuff now.

Wednesday, December 20, 2006

Monday, December 18, 2006

Veg Box

I've had veg boxes from several different sources, and invariably they are poor.
I can understand that, in the winter, it's going to be hard to put together locally sourced organic food for the same price as during the summer (and I suppose I'm surprised the price doesn't reflect this), but they are invariably full of stuff that you don't eat - either because you don't know what it is, or because there's so many of them (e.g.: one massive squash that you'd not even think about buying from the shop).
Even the "best ever veg box" that Amy and I had (from Goosemoor Organics, who don't deliver to where I live now) still had a large celeriac every week. They did leave it out when we asked, but there were a few that turned runny before we actually got to eating them.
The other thing is that they are not tremendously good value. This true of organic veg in general, but I've found that, from a £25 "mixed" box, typically I end up buying another £5-10 worth of veg. This is sometimes simply because there weren't basic things like onions, but also because, being vegan, I tend to eat a lot of fruit and veg, and there wasn't enough variety in the veg box to keep me healthy.
We tried doing a veg box where we got to choose what we got. It was a nice idea, but it turned out that, because the supplier was so unreliable, we'd usually only get half of what we ordered. Very annoying, especially if you were trying to get specific ingredients. Also, we had to order the new veg box the day after we got the old one, so we'd have to try and predict what we'd need a week in advance.
It's hard to know what to do, as the best places I've found for organic fruit and veg are Beanos (Leeds), Beanies (Sheffield), and On the Eight Day (Manchester), so it's not really viable to go and choose my own veg unless I want a two hour round trip. (I know I work in Manchester, but Eight Day is about 20 minutes from where I walk, and then the stuff would have to sit in my bag for 3-4 hours before being bumped around on the train, and so would be unlikely to last very long. Getting things like tomatoes just isn't practical.)
I currently get one from Carnival Organics in Manchester (they only sell boxes), which is conveniently situated between where I work and the station. It's not great, but it's just good enough to stop me getting one.

Friday, December 15, 2006

Coffee

I haven't really been drinking coffee lately. I quite like coffee - not nasty NesCrappy, but freshly brewed coffee, preferably from fresh grounds (although they're usually not quite so fresh).
I have to take my hat off to Union Coffee Roasters <http://www.unionroasters.com/> for having made the nicest coffee I've ever tasted. The packets I've tasted are smooth and fresh tasting, and have a pleasant citrus element. The only places I've found to buy it are Waitrose (nearest is either Otley or Sheffield), Beano and Just Bean (both in Leeds). It's subsequently a bit of a treat when I do get some.
Since I've been tired, I've been drinking coffee everyday this week - I think it was three cups on Monday. It started because I was shattered after staying out late on Saturday night, then waking up early on Sunday morning. So on Monday I drank lots of coffee to get me through the day. Monday night I had about five hours sleep.
Tuesday was a busy busy day - was at work by 8am, and, after taking the cat to the vet's, didn't get home until nearly 8pm. Not much coffee drunk, and I took some Nytol before bed, and I slept deeply.
Wednesday, I had 1 cup of coffee, felt really bad when I got home from work, but managed to drag myself out to Yoga, and unsurprisingly, slept really well, (and I managed to get up slightly later than usual). I felt really awake yesterday (Thursday), but I still had some coffee, and didn't sleep at all well last night.
So, from tomorrow, I'm going to stop the coffee, and hopefully I'll sleep better.
Right now, I just need one more cup now to get me through the day...

Wednesday, December 13, 2006

Holmfirth

On Saturdays, normally I end up going into Huddersfield for groceries. Mostly, this is because I think that supermarkets are evil, and Saturday is the only day when I'm not at work and the smaller, local, shops are open. 
However, last Saturday, as well as getting my delivery from Black Isle Brewery (more on that in another post), Amy + I went to visit the cattery Henry will be staying in over Christmas, and ended up doing our shop in Holmfirth.
I've not really been to Holmfirth that much. It's where Last Of The Summer Wine was filmed around, and apparently the Café capital of West Yorkshire. Apart from that, I've never really had reason to go there.
I have to say, I was pleasantly suprised. Not only is there a respectable wholefood shop, called Your Nuts, but behind Your Nuts is a veggie, organic cafe called WOW. There are also a few green grocers, and we ended up getting the things we couldn't get anywhere else from Co-op, which is one of the less evil supermarkets.
So, from now on, we're going to try going to Holmfirth for our groceries on Saturdays (and probably squeeze in a visit to WOW too!).

Spam

Dammit, I started getting spam on my Google Mail account. For the moment, it's about one a day, and the spam filtering catches.
Also, it's clearly designed to fox spam filters, resulting in some rather surreal text:

Coming from where? I asked.
A galactic garbage dump! I cried aloud. Where you holier-than-thou
Now is the time, Captain. For at this meeting I am not only going to
Oh, I do appreciate a sense of humor, stranger. The tentacle took
there. Stand up, Jim! I got as far as my knees and he came on.
will not shout or you really will be dead. You will speak to me softly
slumworld. Think quickly, Jim, before things get any worse.
Very gradually the wall became higher as we walked beside it. In
tearful thanks in advance. This is the experience that will change
the bed, turn off the searing lights, stumble on all fours to my pack
everything was in great swing already. I ready. And gory too; I

Monday, December 11, 2006

Armando says...

"isn't there a possible compromise to be reached on the successor to Trident? How about taking all the money and saying we've spent it on a fresh batch of nuclear warheads, but quietly spend it on other things like street parties and the Olympics. Blow the money big time on fun and, instead, construct a missile system made out of bars of soap."
...and I whole-heartedly agree with him.

Hooray for Open Source!

Jeremy and Ayende (and probably others by now) have been considering the Microsoft attitude to Open Source.
I can see why companies don't like GPL, but it can turn out to be a good thing.
The very fact that Linksys decided to use Debian Linux kernel for their NSLU2 device, and were obliged by the GPL to release (bits of) their code, has meant that a whole community has sprung up around it (http://www.nslu2-linux.org/), who figured out how to run Debian on it, which has resulted in their product being used as a lightweight, low-cost, server. (yeah, 32MB ram and 266Mhz is hardly going to win any performance awards, but for ~£40 + cost of storage device, what do you expect?) [Edit: Thanks to Øyvind Repvik for setting me straight on this]
Jeremy makes the point about Agile development in .Net only being possible with open source tools tools. I don't think that this is just related to OSS. In the places that I've worked (my view of the 'Microsoft world'), people don't seem to want to know about something unless it comes from Microsoft. (The only notable exception is the miles of sub-standard code that's been copy-pasted from the code project).
Agile? Not until MS announced they'd been dabbling with SCRUM.
Unit Testing? Not really, and still not very much (too much poorly written code based on sample provided by Microsoft).
IoC/Dependancy Injection? Despite working with numerous "plug-in" frameworks, based on DLLs, then COM, and now .Net, people still don't see the benefit of taking it that one step further and creating all of their code based around this model.
In my view, the problem in the .Net world is that there are too many .Net developers. Many of these have come to it from VB and from ASP, and have little experience of rich OO architecture, and many wouldn't know a proxy from an abstract factory.
What happened to the Visual C++ developers? Most of the Visual C++ programmers I know are still developing in unmanaged C++, claiming the performance of .Net prevents them from moving.
To be honest, I've been trying to plot ways of leaving .Net, and moving to RoR or Java, as a way to escape the crippling laziness/poor practised that I consistently experience in Microsoft based developments. I'm fed up with having to teach people about loose coupling, dependencies, and other really basic stuff - the kind of things that other development communities seem to have tackled years ago, and from which they are now reaping the benefits.

Tuesday, December 05, 2006

Sufjan Steven's Christmas Songs

On the Asthmatic Kitty site, you can listen to Sufjan Steven's latest release, Songs for Christmas (a 5 CD set, that appears to be a compilation of previously unreleased stuff).
Admittedly, there's some only slightly above average stuff on there, but there's some wonderful bits too. Definitely a chrismas album worth having.

.Net Testing And Assemblies Signed with Strong Names

I've been trying to NUnit to test assemblies that reference some other Assemblies which are signed with Strong Names, and which aren't installed in the Global Assembly Cache.
I keep getting "Method Not Found" exceptions, which I tracked down to the Assembly Download Cache not being refreshed when the Assembly's Manifest hasn't changed (which it hasn't, just the code). Because the signed Assemblies aren't in the GAC, the ones in the Assembly Download Cache get used instead (I'm not quite sure why, but it does, so there!).
I can't put compiler directives around the AssemblyKeyFile directives (I could propose this, but I'm the only one using NUnit for unit testing, so no-one else would see the point).
Fortunately, Suzanne Cook mentions how to sort this out. Run "gacutil /cdl" everytime I recompile a signed assembly. Not a lot of fun, but it works.
I've thought about using DEVPATH too, but I've got a solution I can live with (for the moment), so I'll investigate that when I get fed up of typing "gacutil /cdl".

Monday, December 04, 2006

Development Metaphors

At the moment I'm reading Domain Driven Design and A Confederacy of Dunces (which is quite amusing in a very dry way). So no doubt, I'll be posting reflections on parts of the former.
Today's reflection is about a bit about the Motor Industry metaphor for software development. I
n the motor industry you have a team of highly skilled engineers who design a car, and then the assembly gets done by lower skilled people. Basically, this metaphor is used to support the idea that the hard part of software is the design, and that the important thing is to get the design right. If you do that, then you can have code-slaves putting it all together.
How does the "getting the design right" happen in the motor industry? By the engineers designing, and building, prototypes, testing them out, and then refining them. I might be wrong, but I'm sure that most of the engineers have the knowledge, if not the mechanical skills, to build a car.
In software, the prototype is the product, and so software development is all design. The low skill part - producing distribution media and packaging, can be done by machine. (The low skill repetative bit of coding should be done by machine too.)
To this end, I propose that a more useful metaphor: building a F1 racing car. In this case, you want the best people possible designing and building the car. You want them to interact, to talk about design decisions and how they can be implemented. At no point do you want someone who doesn't understand the interactions of what they're doing working on your tip-top machine.
Software development is all design (yeah, that's a quote from the book).

[Update: this is written about far more eloquently on coding horror, which I read quite coincidentally]

Sunday, December 03, 2006

Ubuntu

Gary's written a reflection on using Ubuntu. It's kind of reassuring.
I've been using Ubuntu in a virtual machine for a while for some projects I've been working on. I kind of like it (although, I have switched to using Xubuntu, as it has a lower resource overhead).
There are still a few areas where the open source community lacks strong software. These are .Net development (nothing comes close to Visual Studio and Resharper), and music.
There's one DAW solution, but I tend to use Ableton Live, which is a bit of a hybrid, and I've not really seen else like it. That, and Guitar Rig. There is FreeAmp, but Guitar Rig is soooo amazing, I don't know how anyone else could do that.
There are some components out there that could be put together to arrange something ableton like, but, as always, it's time, and tweaking, and it's time i could actually spend playing guitar.
Yeah, so use ubuntu if you don't want to do music on your pc.