Original URL: https://www.theregister.com/2013/03/11/verity_stob_text_editor/

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?

By Verity Stob

Posted in Columnists, 11th March 2013 09:02 GMT

Stob When I heard, in a tutorial video, the multi-platform programmer's editor Sublime described as "the cool kids' code editor" (or possibly "the Cool Kid's code editor" - the speaker didn't enunciate his capitals and apostrophes very clearly) I was puzzled. As the goto (or, rather, the call-by-reference) consultant on Agile Harlem Shake in the northwest corner of our floor, surely no such assertion could plausibly be made without first interviewing me?

Nothing would have come of this if TextPad, normally as reliable as a tax demand, had not crashed. Twice. Unprovoked. Editing piddly little config files.

I mean, in about 1998 I actually registered it with my own money. Possibly as much as £12. So I have invested nearly a quid for each year of ownership, and seen nothing back for my dosh except a few thousand hours of heretofore bug-free editing, and 20 or 30 new versions, including several major version upgrades.

This counts for nothing when there's a brace of bifurcated .ini files squirming about on my hard disk like sadistically razor-bladed earthworms. TextPad is going on a written warning, and this is me writing it.

The Plan

Here's the programme. I am going to put TextPad and Sublime through Verity's Immutable, Scientific And Absolutely Perfectly Fair Six Point Programmers' Editor Test, and see who wins.

I am aware I am treading on sensitive and subjective ground here, so I am going to apply legendary Microsoft blogger Raymond Chen's anti-nitpicking strategy. I will attempt to anticipate and dismiss in advance every possible objection, and leave the right-thinking reader with an impression of calm, reasoned rationality, and definitely not obsessive paranoia. Let's lay down some protective cover right now.

Anticipated Q. Does each editor support a "folding"  feature to allow the user temporarily to "collapse" a block of code by clicking in the margin?

Perfectly Rational A. Who cares? If you don't want to look at it, why put it in your program?

Q. Does the editor support user extension via an internal, C-like macro language?

A. Oh, for heaven's sake. Welcome, Marty McFly, to 2013.

Q. Those two editors are cool, but what about...

A. No, I won't be testing your favourite pet editor. Because.

This last point applies especially if your favourite editor - like that of Dave, who sits behind me - happens to be Notepad++. Years ago I had a very bad run-in with it. It had an evil bug which silently truncated the replace buffer, which I did not discover until too late. Betrayed once, I have sworn a dreadful oath with real, post-watershed swearwords that I will never give it a second chance.

Besides, I don't like its icon.

Off the mark

OK, on with the test. The first of the Six Immutable Blah-di-blah.

1. A programmer's editor must get its backside off the disk and into the air in no time at all. No problems here, both candidates achieve this, with perhaps a hint of stickiness from Sublime.

If either program had failed this test, I would have had to regrade it as an IDE, and it would be game over. Counter nitpick: the technical definition of an IDE is, of course, "any text editor whose add-ons have sufficient time to paint cute loading messages onto the splash screen", but cut me some slack here.

By the way, I do realise that there are some people who fire up, say, Visual Studio 2010 to edit one command parameter in their batch files. They sit there stolidly, their faces cast greenish in the glow of their default Windows XP "grassy hills" wallpaper, their trains of thought necessarily shunted into weedy sidings of forced idleness.

Meanwhile, the hard disk rumbles ominously under the strain of fat, juicy .NET components dropping ploppily into vast expanses of RAM, like ambiguously sauced and -sourced meat products being poured into the strata of a low-budget, lasagne-style ping meal.

I do feel such persons are ill-advised.

2. You don't need to be an enthusiast to drive it.

I don't mind enthusiasts banging on about using "finger memory" to improve their productivity.

I don't like it much when they wag those memorial fingers and write long sermons on their blogs, rhapsodising about the importance of learning a core 35 keystrokes. But hey-ho.

I absolutely can't be doing at all with editors that contrive, by absurd UI design, to make the acquisition of these keystrokes a prerequisite to getting anything done.

It turns out that my brain was only fitted with 72 bytes of "finger memory"; furthermore it turns out to be EPROM, not Flash. I need to wipe out all the WordStar keystrokes from 1986 (Ctrl+Y to delete a line, anyone?) before I can add any more, and I have lost the ultra-violet wiping-out gadget (ask your dad) needed to achieve this.

Counter nitpick: If all this ranting this seems suspiciously like a repeat of my recent  attack on R Pi, then: so it is.

Anyway, neither editor makes unreasonable demands in this direction. Another double pass.

3. Support for the languages that I use. Natch both editors offer syntax highlighting. TextPad looks pretty much like every other Windows programmers' editor since 1990 - basic syntax colouring against a white background.

Sublime, on the other hand, reveals Mac influences - it is a multiplatform beast -  with a 'coloured chalk on a blackboard' appearance, vertical scope lines and a navigable-image doodad on the right-hand margin:

Another giveaway: Sublime comes with a set of colour schemes with names like Dawn, Expresso Libre, Monokai, Slush & Poppies and the Smell of Napalm in the Morning (I may have made one of those up). Contrast this with an equivalent list from a Windows product (in fact Delphi VCL skins): Carbon, Charcoal Dark Slate, Emerald Light Slate,  Golden Graphite, Slate Classico and Dark Beige Slate Classico Carbon (I may have made one of those up). Talking of Delphi, I'll just, um...

*ooof*

One moment. Please wait one moment.

I don't believe this. Sublime comes with support for seven variations of TeX, five for the Rails framework, plus a selection of exotics like YAML and D, but NO support for Object Pascal. Not even as a Googlable freelance download. 'BEGIN' and 'END' are just random collections of characters as far as it is concerned.

Oh right, so you are really telling me, Sublime, that all the cool kids are frittering their lives away chaining together jQuery methods like digital daisies, when they could be experiencing the pleasure of the "Fish Facts" database using code that is very nearly unchanged since 1995? I must say I find that very hard to believe.

What's that? Anybody is free to devise their own syntax definitions? Don't come with that. I am far too busy and important for that sort of malarky. Minus one million points.

4. The editor should contain no implementation of Lisp. Self-explanatory - no need for a counter-nitpick here. Both OK, as far as I can tell.

5. Sooner or later, you need to skim through a huge log file. In the interests of science, and ignoring the danger of introducing some objectivity, I found a 74MB text file left over from Christmas, and tried loading it.

Sublime creaked, gasped, paused, debated... but didn't fall over. Scrolling from one end to t'other triggered a multi-second, fingers-drumming-with-impatience pause.

TextPad just ate it, chomp. Easy win to TeePee.

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);
et cetera

(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:

  1. Knife-and-forking it by hand, the Yvonne Gumby approach, which is not really on if you have more than three lines;
  2. Contriving some sort of regex search-and-replace, in which case Zawinski's Observation Applies; or
  3. 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.

Danger, gusher

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

Notepad. ®