How long have you been at work? A Windows Hack.

I get into work anywhere between 8:00am and 9:30am. As the end of the day draws on, I’m sometimes not sure whether I’ve served my time. To make sure I don’t go home too early, I use this little trick.

Windows tracks your logons in the event log. So to find out when you came in;

  1. Open the event viewer; *windows+r, ‘eventvwr’, enter*
  2. Select ‘Custom Views’
  3. Right-click and choose ‘Create custom view…’
  4. Open the ‘XML’ tab
  5. Check ‘Edit query manually’
  6. Enter this XML;

    <QueryList>
    <Query Id="0" Path="Security">
    <Select Path="Security">*[System[(EventID=4672)] and EventData[Data[@Name='SubjectUserName'] = 'your-name-here']]</Select>
    </Query>
    </QueryList>
  7. Replace ‘your-name-here’ with your domain username
  8. Choose ‘OK’.
  9. Set the name to ‘Logins’
  10. Hit ‘OK’.

And there you go. There in Custom Views will be a list of your login events. Find the earliest one in the day and that’s when you first logged in.

On Learning to Write Languages

I’ve been learning to write languages recently.

I read Steve Yegge’s thought-provoking post, in which he talks about how, if you know how to deal with language problems like lexing, parsing, translating, and compiling, then you know how to solve a large number of common programming problems.

I’ve been using very simple custom languages at work to write integration tests. Just little bits of work, but they’ve really helped quality by allowing us to write loads and loads of tests quickly and confidently. I think we have about 500 integration tests written which rely on small setup languages.

I think this has become possible because the system we’re writing against is pretty stable. The underlying classes and database tables we’re writing against don’t change too often.

This seems to be the key time for writing your own languages; the underlying libraries have reaches a point of stability, and you are being asked to do complex things to the underlying data.

So if you deal with classes or database tables called ‘Document’, ‘Alert’, and ‘Error’, then you can start making statements using those objects; things like

‘When the document is saved, if the document is not Signed Off, alert the document owner and log an error’

Now, it should be possible to write a translator that turns this into c-sharp; something like;

public void OnSaved(Document document)
{
if (document.State != DocumentState.SignedOff)
{
SendAlert(document.Owner);
LogError(document);
}
}

The first version is significantly easier to understand and write. You can show this to your customer and ask if he agrees with the statement. The language helps communication. The c-sharp is no help at all in communicating.

So, custom languages can help put together systems that are easier to understand, because the language is tuned to the problem, and easier to modify, because the code is invariably shorter than it would be in the general-purpose programming language.

To my mind, if I can learn to write interpreters, compilers, and translators, it allows me to write software in a way that is significantly more easy to maintain.

There are, however, two big problems;

First, learning to write languages is not trivial. It’s a significant investment of time. Your manager is not going to be happy about a proposal that starts “Can I spend the next month learning about languages and not writing production code…” so I think you have to learn about these things in your own time.

Second, once you know how to write interpreters, they are themselves fairly hefty beasts. If it takes you 300 lines and a day of work to write a lexer and parser, you’d better be certain you save more than 300 lines and a day of work in the course in writing scripts in the new language — otherwise what was the point? So you have to pick your battles, picking only those areas that are ripe for better automation.

If you meet these two criteria — you’ve learned languages on your own time and you’re picking an area that’ll benefit from it — I think writing your own languages is a very valuable ability.

So, I’m now reading heavily in the area, writing my own lexers and parser by hand, and starting to look at automated tools like ANTLR and Irony. Irony .Net Language Implementation Kit

iOS4 bluetooth keyboard first impressions

I installed iOS4 yesterday; here are the first impressions of the bluetooth keyboard support. Being able to use a keyboard with the phone, without jailbreaking, is absolutely great. The phone starts to become a really viable writing platform; for blog posts, mail, and fiction. I’ve got one of the old foldable keyboards originally designed for a Palm, and it folds down to the size of a paperback book. This makes it really easy to write while on the move.

Of course, this makes it even more important to have a decent editor. I’m still going for Simplenote, which uses syncing with the cloud, but I’ve got a terrible urge to write some kind of subversion integration so that I have all my writing in the same source-controlled location.

As yet there are still some issues; for instance, the bluetooth keyboard means that the on-screen keyboard doesn’t need to be on-screen, but the wordpress app still reserves space for it.