Regex Readability

Piers describes a foul abuse of programming. I’m totally with him on this one. People should just learn to use regexes—they’re an enormously powerful tool for pulling apart strings. And they’re not difficult. Unless of course, you’re of the “Java is the one true language and I must know nothing else” school of programming. Don’t laugh, there are people like that.

But the second crime, which Piers fails to point out is parsing XML with a regex. There are so many ways in which this will blow up in your face. Really. What about character encodings? Attribute order? Entities? Even unexpected tag order would blow up most XML regexes I’ve seen. Don’t do it, folks, you’re just setting yourself up for a fall.

Update: Dave and Piers both correctly point out in the comments that I misread the original article. Piers does in fact state that parsing XML is “one of the canonical no nos”. Mea Culpa. I still agree with everything he says.


TextMate book

Last week, a copy of TextMate: Power Editing for the Mac landed on my desk. TextMate has been a part of my life for about a year now. I can’t be doing without it (“Edit in TextMate” is worth the price of entry alone). I consider myself a reasonably advanced user.

Boy, was I wrong. From the very beginning of the book, I was getting something new off of each page. Not necessarily earth shattering, but a drip, drip, drip of new knowledge about textmate and how it works. By the end of the chapters on Editing, I felt hugely more confident about using the abilities of TextMate to the full.

The book is split into three main sections: Editing, Automations and Languages. Editing is well, editing. Do it hard, do it fast. The Automations section takes you to the next level, and lets you customize TextMate to your own unique workflow. From the simple snippet to the do-anything command, it really shows you how to take control.

What I particularly love about TextMate is that unlike vim or Emacs, it doesn’t have an extension language. Instead, you get to use Ruby, or Perl, or /bin/sh. You could use PHP if you prefer. In many ways it feels far more “Unixy” than either vi or Emacs. In fact, it’s much more like sam.

The final section, Languages, should rarely be needed. TextMate comes with builtin support plenty of languages (and many more are available). But when you need it, you really need it. James Gray manages to walk through the process of adding a simple language (JSON) in a very effective manner, showing you what’s possible in a succinct manner.

In fact, succinctness is present throughout this book. The text is clear and informative, never taking too long to explain, but not leaving you confused either. And at 200 pages, it’s nice slim tome. You could get through it in a couple of hours, but don’t worry—you’ll be coming back to it.

If you edit text on the Mac, do yourself a favour and get this book.