Six things a text editor must do - or it's a one-way trip to the trash
Does your source code editor pass the Verity test?
The TADREP Test
6. The Tedious And Domain Related Editing Pattern. This is the big one. This is where good programmers' editors really get to show that there are more than just text controls, elaborately decorated with pretty colours and more unused features than Word.
TADREP is a pattern never seen in programming tutorials, but in actual programming-for-money it occurs quite frequently. It comprises taking a block of domain-sourced text like this
0001, 3000, Adam, London
0002, 1000, Bonnie, Manchester
0003, 2000, Catherine, Edinburgh
0004, 3000, David, New York
continues like this for 20 more lines)
and munging it into code of some sort:
db.add("0001", "Adam", "London", 3000);
db.add("0002", "Bonnie", "Manchester", 1000);
db.add("0003", "Catherine", "Edinburgh", 2000);
db.add("0004", "David", "New York", 3000);
(Counter nosepick: I realise this isn't a very good example. I couldn't think of one, ok? You do know what I mean, really.)
I claim there are three common ways of achieving this:
- Knife-and-forking it by hand, the Yvonne Gumby approach, which is not really on if you have more than three lines;
- Contriving some sort of regex search-and-replace, in which case Zawinski's Observation Applies; or
- Recording a keyboard macro which, by a very cunning selection of keystrokes, will apply to all the lines that need to be manipulated. Then play it back as many times as needed. Then go back, and fix all the lines it has stuffed.
TextPad has an excellent search-and-replace dialog (non-modal, but goes translucent when it doesn't have focus, so can be left open without getting in the way). Its regexs, however, smell of mothballs. These are formulated to some ancient POSIX standard that omits, for example, the \w character class that everybody enjoys complaining about. Its keyboard macros are adequate.
Sublime recovers some marks for offering the full Perl regex syntax - mysteriously, few editors seem to do this, given that most programming languages now throw it in for free. And, yes, it lets you record keystroke macros.
However, it also offers a whole new way of tackling TADREP.
OK, turn down your sensitivity, and lock your British sense of embarrassment into the upright position. I am going to have to do something rather unusual here. I am going to express naked, uncynical enthusiasm.
Sublime's multiple cursor feature is completely top. You select a block of text, press Ctrl + Shift + L (if you are following along on your Mac, just press squiggle squoggle shift Home), and now you have a separate cursor on every line in the block. As you move left or right, they all march together. Cut out a block and paste it somewhere else on the line, and it is repeated n times for n different blocks. Typed characters go in on every line, and Ctrl + Z also operates in parallel.
This is powerful, simple, clever and I have never seen it done quite like this before. Sublime has penetrated my battle-hardened crust. Restore its million points, Mr Scoreboard Runner, and bring me the final results.
Judgment of Verity
I only really performed this test to frighten TextPad into better behaviour in future. The threat of replacement is a more satisfying way of achieving improved performance from applications than conventional techniques such as upgrading or reporting bugs, and approximately as effective.
However, now that I have spent time with Sublime, I confess I will keep it on my hard disk for its show-stopping gadgets, and will in due course register it (they want $70 a shot for a multiplatform licence, which seems reasonable). Damnit, fallen for another gadget.
Post Script: shortly after I wrote the above, we found a bug in a logger which, to my chagrin, I could coax neither TextPad nor Sublime to identify. However, Dave loaded the log file into Notepad++ and displayed it like this:
<Rolf>Can you tell what the problem is yet?</Rolf>
Worse even than this humiliation of my favourites, the bug was initially discovered by my boss. And he first noticed something amiss with the line endings while poking around in - and, dammit, I swore I wasn't going to use this word - while poking around in...
Sponsored: Customer Identity and Access Management