Blog Posts

Deprecation! That's what you need!

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).

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

The pleasures of baking

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.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

The sky is not evil

Joss Whedon writes strong female characters, he’s the mind behind some of my favourite TV ever and he’s 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 #

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Metaprogramming == Programming

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.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Domain Agnostic Languages

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...
  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Finally learning JavaScript

For years I’ve managed to dodge learning JavaScript. People have told me it’s a fine language with some dodge implementations. Friends have built an entire business model in the language, and I’ve continued to treat as if it were The Sound of Music (I’m 39 now and I have managed to completely avoid watching that film).

Except, today I finally had a technical need that I couldn’t dodge by writing another .rjs file, so with the help of the Prototype docs, a helpful article or two and healthy dose of cribbing from others, I was off.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

What the?

Wow:

$ rake spec
...

156 examples, no failures

$ ./script/spec spec
...

156 examples, 2 failures

$ rake
\[unit tests, all pass\]
\[functional tests, all pass\]
\[specs...\]

156 examples, 2 failures


For extra points, the 2 failures from running the plain `rake` are not the same as the failures from running `./script/spec spec`. And if I run `./script/spec spec` after a full `rake` run, I get a host of extra failures.

I wonder what I'm doing to so comprehensively screw up test isolation.

Ho hum.
    
  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Things which are fun

It’s definitely fun to commit a major rework of something that’s been bugging you to SVN. It’s slightly less fun to check it out in your production server and have it fall over until you remember you to retweak the environment.rb file.

Anyhow, we’re now running on Typo 4.1.1+r1438. Typo 4.1.1 got released last night and, pretty much as soon as it had cleared the gates I checked in a major rework of the Article and Feedback state mechanisms.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Other things which aren't fun

Last year, you would have been forgiven for thinking that Typo was pretty much dead in the water as an ongoing project. Typosphere was a placeholder, changes were few and far between, the app was a bloated monster. So, people switched, in droves, to Mephisto the new, (and excellent) kid on the block. Heck, even Tobi, the original author of Typo, has switched.

Mephisto’s a great piece of software, and I’m as sure as I can be (without taking a closer look) that its underpinning code is cleaner than typo’s. When you’re developing on a rapidly moving platform like Ruby on Rails, there could be said to be a second mover advantage - the later you start, the more likely Rails is to already do what you want, and the less likely you are to zag where Rails later zigs.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Things which aren't fun

Let’s say you’re running tests against your rails application and a test fails.

“Hmm…” you think, “I wonder what could be causing that, let’s run that test file by itself.”

The test passes.

“Okay… I wonder if it’s the rake test loader, let’s run that test file using that.”

The test passes

“Right, it’s only the third test file on the list that’s failing, let’s try running just the first 3 test files.”

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Why don't more books work like this?

When you read Christopher Alexander’s ??A Pattern Language, the patterns within the language are interdependent and ordered from big patterns down to small ones. Each pattern has a number and wherever one pattern refers to another it’s referenced with both the pattern’s name and its number.

Beck, Fowler and the Gang of Four (if memory serves) go one better, wherever they reference a pattern, they give the pattern’s page number (ah, the joys of computer typesetting). I’m not sure it’s an enormous improvement over pattern numbers with the pattern numbers in the running heads, but both practices make the books easy to use.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Why I love Smalltalk

From Extreme UI Testing:

Method wrappers. Easily possible in VW and Squeak since you can subclass CompiledMethod and much with the method dictionaries […] Niall uses a strategy pattern to automatically wrap threads that get forked off by looking up the stack to see if the code is under test (and if it is, make sure to install a wrapper)

So what if the language doesn’t give me the callbacks I need, I’ll just rejig the system classes until it does. Until Avi needed them for Seaside, Smalltalk didn’t have continuations, but it’s malleable enough that he could implement them.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Routing Speed

So, since I couldn’t sleep, I’ve been hacking on the routing drop in replacement.

I’ve reached the point where things are mostly working and I can at least run the benchmark tests.

On this machine, Rails recognizes routes at a rate of around 22K url/s.

At the start of the night, with the recognizer rparsec, to do the recognition, my new routing system was running at around 5K url/s, which isn’t exactly great. So, I rejigged things to build a regular expression and use that to parse the request URL and the recognition rate jumped to 12K url/s. I’m really pleased with that number for the time being.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

What happened to the routing rework?

Those of you who’ve been reading attentively will be aware that I’ve been working on a drop in replacemen for a chunk of Rails’ routing subsystem. You will also be aware that things have gone a bit quiet on that front.

I got a job.

Which is lovely, and fabulous, and safeguards my mortgage payments and all that good stuff. But it has rather put dampeners on any non paying work.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

That was fun

On Monday I was down in Brighton for a Brighton Coding Dojo where I had a crack at doing Kata four in Smalltalk.

It took a while to find the balance, but once we got going I think it went well.

We stuck in what seemed like the strangest places though. At one point, I had a method that did almost exactly what I wanted for a new method I was writing so I called up the method in the browser, changed the selector and the few bits that needed fixing up and accepted the changes.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Rails, CRUD, REST and the importance of adjectives

Consider a web request:

GET /articles/2007/04/17/adjectives-rule;edit

“What does it mean?” #

If we pass it through the prism of Rails routing, it breaks apart as follows:

`GET`
The `:method`, sometimes called the verb.
`/articles`
The `:controller`, the thing that's going to handle this request
`/2007/04/17/adjectives-rule`
Parameters, passed to the controller method that handles this request
`;edit`
The `:action`, some way of specifying what this request does
It's certainly one way of looking at it, but if you do I think you're limiting your understanding of what it means to program in a RESTful fashion. It's an obvious fit for Rails where the dispatcher builds an appropriate controller and then does `controller.send params(:action)`[1] but it's a very 'imperative' view and that's not necessarily a good view. The problem is that `:action` at the end.

What’s happening is that Rails’s implementation is leaking into the abstraction that is the URL. If you let that happen you end up programming with CRUD (Create, Read, Update, Delete)dy blinkers.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Soundbite

An argument for peace and love is always an argument for self-preservation.

Go Giles Bowkett, you speak truth. You also speak it way better than I managed a couple of years ago.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Mmm... parsers

So, in my quest to get Rails routes to accept routes like:

articles/:comment[article]/comments/:comment[id]

I’ve been playing with parsers for the first time in my programming career. Quite how I’ve managed to get this far without them I leave as an exercise for the interested reader.

At the moment I have a parser that will parse

articles/2007/05/12/slug

and give back an ActionSelector that yamlizes as

--- !ruby/object:ActionSelector
  controller: articles
  action: show
  params:
    :article:
      :year: 2007
      :month: 05
      :mday: 12
      :slug: slug
Which can be easily turned into the kind of params hash that rails wants from its routing system in order to dispatch the request to the right place.

For my next trick, I need refactor the parser I have so that it’s generated via a set of parser builders. Then I need to write a parser for routing specifiers that can use those builders to build a URL parser.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Wanted: module/starter.rb

I sometimes think that one of the reasons that CPAN is such a huge advantage for Perl is the ease with which you can contribute to it. It’s all very well having a tool for installing libraries from the archive, any fool can do that, but CPAN has tools for getting started with a new library too.

If I want to start a new Perl project, I do:

module-starter –module=AuthenticationFairy

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…