Rss

Archives for : December2012

Constable Peter Grant

When one of your favourite authors mentions she thoroughly enjoyed a book she just read, then I find it’s worth taking a peek at it.

With the Kindle version of Rivers of London at just £1.99 I couldn’t resist. So onto my new paperwhite it went. I got hooked very quickly and finished the book in one sitting. I loved it enough that I’ve now also finished the two sequels which were equally as good.

The books are basically an urban fantasy. The premise is a simple one. Take one freshly minted police constable, a very good author (who has written for TV including the likes of Doctor Who), twist one piece of reality (magic is real!) and you end up with a great story (actually three, and hopefully many more).

“So magic is real,” I said. “Which makes you a… what?”
“A wizard.”
“Like Harry Potter?”
Nightingale sighed. “No”, he said, “not like Harry Potter.”
“In what way?”
“I’m not a fictional character,” said Nightingale.

There is wry humour all over the place, and this is hardly the best example, although I have to admit it rather tickled me and I actually laughed out loud when I read it.

Along with the wry humour, the fact that it’s set in London and I get the chance to recognise a number of the locations there’s also the simple fact that it just feels so right.

The science geek in me was hooked beyond redemption when our hero first entered his new headquarters…

[…] and I knew his name before I saw the plinth, which read:
Nature and nature’s law lay hid in night;
God said ‘Let Newton be’ and all was light.

Nightingale was waiting for me by the statue.
“Welcome to the Folly,” he said, “the official home of English magic since 1775.”
“And your patron saint is Sir Isaac Newton?” I asked.
Nighingale grinned. “He was our founder, and the first man to systemise the practice of magic.”
“I was taught he invented modern science,” I said.
“He did both,” said Nightingale. “That’s the nature of genius.”

One of the things I’ve always had trouble with in modern fantasy novels (and many more “classical” fantasy books) is the blatant disregard for common sense when dealing with the magic of their world (c.f. Harry Potter). Some stories are strong enough to get away with it, but it can still be jarring. This book isn’t like that.

One of the things I really like about these books (other than a great fast moving plot, witty and wry humour, great characters and excellent descriptions) is that Ben Aaronovitch writes Peter in a way I can so easily identify with. When he starts playing with magic his first questions amount to WTF? How is this possible? Laws of Thermodynamics anyone? He then promptly starts applying the scientific method (Hi again Sir Isaac!) to what he’s learning. A small sub-theme that runs through all three books so far and while it adds only a little to the plot does a lot to make the world and the protagonist believable.

As I’m also a great fan of Harry Dresden, it’s very hard to not make comparisons. In many ways I think Ben Aaronovitch is a much more skilled author than Jim Butcher, yet both write books that are extremely entertaining and above all fun to read. The same first person narrative; a hero who is a detective (Detective Constable vs. Private Eye); in a modern urban setting (London vs Chicago) the wry humour in the story telling (although Butcher does stray towards slapstick on occasion), fun characters, enjoyable story and a fast pace.

I like them both but I think I felt much more quickly at home and immersed in the world Aaronovitch spins than I was in Butcher’s world. Perhaps because I could more easily identify with the places, culture and slang of London and the Met. than with Chicago.

Setting things in London though gives Aaranovitch a big advantage over Butcher, I feel. There’s a lot more stuff to draw on for your back story and plots in a city that’s been settled since 43 C.E. as opposed to a city only settled in 1770.

In any case… cannot wait for the next book in both series.

Common Get-ScriptDirectory in Powershell doesn’t always work

This function has been written dozens of times, in dozens of places, by dozens of bloggers, but I keep finding myself looking for it, so I thought I’d make myself a note. But I also discovered that there’s a problem with it.

If you’re writing a script in a module, it’s easy to use $PsScriptRoot  to get the current script path. For others situations there’s:

This function, and ones like it, appear in loads of blog posts, and it generally solves the problem, but it doesn’t always work, though, as it contains a flaw.

The problem is  -Scope 1. The this switch tells the script to look at the parent scope. This works as long as you have the Get-ScriptDirectory function at the top level of your script and you call it from that top level.

Here’s an example script demonstrating the problem:

Invoked as: PS> ./invoctest.ps1you get:

In Script (scope 1): []
In Script (scope 0): [F:tempinvoctest.ps1]
In Script (scope script): [F:tempinvoctest.ps1]
In t() (scope 1): [F:tempinvoctest.ps1]
in q()
In t() (scope 1): []
In t2() (scope script): [F:tempinvoctest.ps1]
in q2()
In t2() (scope script): [F:tempinvoctest.ps1]

Notice how when the call to t() is nested inside q() the function breaks, and you get nothing. The reason is that -Scope 1 is no longer looking at the script scope, but looking at the scope inside function t(). You’d need to have -Scope 2 if the function t() is invoked from inside q(). The higher the nesting level the higher the value to give to -Scope. 

You could look at the call stack, if you wanted to, but my script above already includes the answer. You need to use the “script” option for -Scope. That will ensure you always get the correct invocation variable.

This even works when the script is dot-sourced, or run in a debugger, like in PowerGUI.
The corrected function is therefore: