Just A Summary

Piers Cawley Practices Punditry

You never know when a coracle will come in handy 1

Posted by Piers Cawley Tue, 26 Jun 2007 20:04:00 GMT

Floods 2007 159

A few years back, we got dad a place on a coracle building course as a birthday present. He had a great time and came back with a half finished coracle that he never quite got round to finishing. Until now, it seems.

Despite what you might think, the photo above isn’t taken from inside my parents’ boathouse, it’s taken from inside their garage. That’s not a river, that’s the road.

You have to love this June weather don’t you?

Cheat all you want, but don't get caught 3

Posted by Piers Cawley Wed, 20 Jun 2007 22:16:00 GMT

As far as I can tell, one of the Smalltalk optimizers’ mottoes is “Cheat all you want, but don’t get caught”.

Well, this morning, I caught Squeak with its hand in the till.

One way I attempt to bootstrap myself towards understanding of code is to try and make it better, if that makes sense. So, I’d run SLint over the OmniBrowser package and was trying to shorten a method. One thing that struck me as rather ugly was a piece of code that ran like this:

|selection|
...
selection := OBChoiceRequest prompt: nil labels: usersNames values: users.
selection ifNotNil: [selection browse].

So I thought I’d tweak ifNotNil: so that, if its receiver isn’t nil, it will pass itself as an argument into the block, which will let me rewrite that ugly code with:

(OBChoiceRequest 
    prompt: nil
    labels: usersNames
    values: users) ifNotNil: [:selection| selection browse].

So, I went to have a look at the implementation of ifNotNil: and found that it was already doing exactly what I was after.

At this point, I had a slight premonition of danger, so I brought up a workspace and tried to print the result of running 10 ifNotNil: [:i| i + 10] and got a compiler error, complaining that ifNotNil: takes a 0 argument block. Which isn’t what the implementation of ifNotNil: thinks.

I’d caught Squeak’s optimizer cheating.

What appears to happen is that Squeak catches conditional code and rewrites it before passing it to the compiler. The rewritten code uses VM level primitives where possible. I needed to fix it so that it would only rewrite any calls to ifNotNil: with a zero argument block.

It took a while, but my local image now optimizes ifNotNil: correctly (the ifNotNil:ifNil: and ifNil:ifNotNil: forms are another matter though, but I shall live. Now, if I can just work out where to submit the changeset to…

I have mixed feelings about this. On the one hand, I’ve just changed something in the workings of Squeak, on the other, it’s not been quite as easy as I’d expected it to be. It seems that, if you go poking around in methods that are defined on ProtoObject, don’t be surprised if changing things doesn’t quite do what you expect.

Maybe I should have just written a ifNotNilDo: taking a single argument block, but that just felt ugly… Ho hum.

How I learned to stop worrying and love aggressive mockery 2

Posted by Piers Cawley Wed, 06 Jun 2007 10:21:00 GMT

There’s something enormously liberating about writing an RSpec description that starts like:

describe ArticlesController, "feeds:" do
  before do
    @the_mock = mock('everything', :null_object => true)
    ActiveRecord::Base.stub!(:find).and_return(@the_mock)
  end

  it "/articles.atom -> atom feed" do
    get :index, :format => 'atom'
    response.should render_template('_atom_feed')
  end

  ...
end

The :null_object flag to rspec’s mock function is remarkably potent.The resulting mock will return itself from any method call that hasn’t got some other expectation set up. When I’m testing that my index methods render the appropriate views for the format, I don’t care that all the various variables have been set up correctly – I’ve already tested that in another description – I just want to get to the point where I’m about to render a template.

What this does is decouple my tests. I can change the way that the index method fetches its stuff from the database and I’m only going to have to change the innards of the specs that test that.

I tend to think of this as being analogous to the object oriented pattern of trying to write your methods at a single level of abstraction. Within a given spec, I should only be setting up expectations that are directly related to what I’m testing.

Dogfood time again 5

Posted by Piers Cawley Sat, 02 Jun 2007 08:08:00 GMT

So, I just pushed the first step of what I’m thinking of as the Great Typo Controller Reorganization to the typo repository and updated things here. It’s always scary when I do that – local testing’s all very well, but running on a live site is a different matter.

I’ll be talking about the changes in a later post, there’s a couple of things in the recent change that I’m rather pleased with, as well as a Rails plugin that I hope will be widely useful, but which I need to document.

Deprecation! That's what you need!

Posted by Piers Cawley Thu, 31 May 2007 15:04:00 GMT

So, I’m quietly beavering away at Typo with an eye to slimming down our somewhat monolithic ArticlesController class, tweaking our routing to use the new datestamped_resources plugin that I’ve developed to help dry up our routes, making a couple of new resourceful controllers for comments and trackbacks and generally tidying the place up. Hopefully Typo’s code is going to be much more habitable when I’m done.

The problem is themes. Typo has an awful lot of ‘em. And what I’m planning to do will almost certainly break many of them. So, it’s time to deprecate a bunch of controller and helper methods and start dropping huge warnings in the log files at the very least (I’m thinking evil thoughts about having deprecation warnings show up in the admin interface every time to go to make any changes too, but that needs a bit more thought).

So, for the next few revisions on the edge, expect to see a depressingly large amount of code duplication – I hope to keep it to a minimum by pushing everything I can down into the models, but it’s still going to be ugly for a while.

The upside should be that we’re going to be ready for Rails 2.0, it should be reasonably easy to add the Atom Publishing Protocol to Typo along with a handy dandy ‘direct manipulation’ AJAX based administration interface I’ve been busy designing in my head.

The pleasures of baking 3

Posted by Piers Cawley Sun, 27 May 2007 12:52:00 GMT

You know, I’m sure, how good fresh baked bread smells. But, good as that smell is, the real pleasure for me is the way it sounds.

I’ve just pulled a loaf of sourdough bread out of the oven and it’s sat in front of me, scenting the air and rustling gently – it shrinks as it cools and that stresses the crust which occasionally gives up the battle with an audible crack. It’s an awfully pleasant thing to listen to.

Test Match Special on the radio doesn’t hurt either.

The sky is not evil 11

Posted by Piers Cawley Sun, 20 May 2007 17:06:00 GMT

Joss Whedon writes strong female characters, he’s the mind behind some of my favourite TV ever and he a wise man. Here he is reacting to seeing camera phone footage of the murder of Dua Khalil Aswad on CNN almost alongside the trailer for Captivity:

The trailer resembles nothing so much as the CNN story on Dua Khalil. Pretty much all you learn is that Elisha Cuthbert is beautiful, then kidnapped, inventively, repeatedly and horrifically tortured, and that the first thing she screams is “I’m sorry”.

“I’m sorry.”

What is wrong with women?

I mean wrong. Physically. Spiritually. Something unnatural, something destructive, something that needs to be corrected.

How did more than half the people in the world come out incorrectly? I have spent a good part of my life trying to do that math, and I’m no closer to a viable equation. And I have yet to find a culture that doesn’t buy into it. Women’s inferiority – in fact, their malevolence—is as ingrained in American popular culture as it is anywhere they’re sporting burkhas. I find it in movies, I hear it in the jokes of colleagues, I see it plastered on billboards, and not just the ones for horror movies. Women are weak. Women are manipulative. Women are somehow morally unfinished. (Objectification: another tangential rant avoided.) And the logical extension of this line of thinking is that women are, at the very least, expendable.

You should read the whole thing. Seriously.

Dress for success: wear a white penis

Sexual violence and intimidation isn’t an ‘over there’ thing, it’s not a muslim thing or a hindu thing or a christian thing. It appears to be a humanity thing. We live in a culture where ‘She was asking for it! She wore a short skirt!’ actually seems to carry weight in rape cases, where an intelligent, confident woman can be brought to the point where she feels it necessary to put herself into some kind of purdah because she fears for her life. And where she is castigated by some sections of the community for writing about it.

Not long ago, I blogged about the organizer of a professional programming conference who thought it was good business to advertise his conference by laying on an after show party with lovely girls pouring drinks that the delegates were encouraged to chat up. In response I had my sexuality brought into question1, got phoned up by the organizer and threatened with violence and, funniest of all, got called a sexist. Charming.

Closer to my current programming home, Audrey Eschright has blogged about the #railsconf backchannel and don’t get me started on some of the parties at OSCON.

The odds are depressingly good that, if you’re reading this, you’re a man. I’ve written before about the gender imbalance in open source communities (2% women, 98% men at the time I wrote it) and the poisonous nature of some of those communities. We’re so used to it that we hardly even see it any more, and when we do, there’s always someone ready to stand up and blame women for it.

We have met the enemy, and he is us

We geeks pride ourselves for our intelligence, so why do we have this huge blindspot about the fact that we are (consciously or unconsciously) excluding nearly half the population from our community for because… er… what is the reason?

There isn’t one. It’s irrationality, pure and simple: a Big Lie, and we bought it.

Yes, there are bigger fights than the cause of equality for women in the open source community, all of them worth fighting. But so what? This is something we can do something about simply by deciding to speak up when we see or hear abusive behaviour. We don’t have to put our bodies on the line, we just have to play fair; it shouldn’t be much to ask for.

Further reading

1 Don’t get me started on the geek attitude to homosexuality…

Metaprogramming == Programming 14

Posted by Piers Cawley Sun, 20 May 2007 16:21:00 GMT

While I’m tilting a windmills, I should just like to tell all those people who bang on about ‘metaprogramming’.

It’s all just programming.

That is all.

Domain Agnostic Languages 11

Posted by Piers Cawley Sat, 19 May 2007 23:52:00 GMT

Windmill tilting time again I’m afraid. Blame chromatic and David A. Black.

What is it that characterizes domain specific languages? Before you trot out something like “Programs written in them read like domain experts talk”, take a look at some examples of code written in domain specific languages:

/(?ms)"((?>[^\\"]+)?(?>\\.[^\\"]*)*)/
S3
R$*                     $: < $1 >
R$+ < $* >                 < $2 >
R< $* > $+                 < $1 >
R<>                     $@ < @ >
R< $+ >                 $: $1
R@ $+ , $+        @ $1 : $2
R@ $+ : $+         $@ <@ $1> : $2
R$+ @ $+                $: $1 <@ $2>
R$+ < $+ @ $+ >            $1 $2 <@ $3>
R$+ <@ $+ >             $@ $1 <@ $2>
>gi|2501594|sp|Q57997|Y577_METJA PROTEIN MJ0577
MSVMYKKILYPTDFSETAEIALKHVKAFKTLKAEEVILLHVIDEREIKKRDIFSLLLGVAGLNKSVEEFE
NELKNKLTEEAKNKMENIKKELEDVGFKVKDIIVVGIPHEEIVKIAEDEGVDIIIMGSHGKTNLKEILLG
SVTENVIKKSNKPVLVVKRKNS

If you’re reading this on the front page, try and work out what the ones you recognise do before you dip below the fold…

Woohoo! Live comment previews are live. 10

Posted by Piers Cawley Fri, 18 May 2007 00:45:00 GMT

Control.TextArea.ToolBar.Textile.js is currently rocking my world and, if you wish to comment on anything in this blog, will shortly be rocking yours I hope.

I might need to fix up some of the feedback on commenting, but it’s nearly 1 in the morning and I’m going to bed.

Older posts: 1 ... 5 6 7 8 9 ... 29



Just A Summary