Thursday, September 19, 2013

The Great Backslash n Escape

From our Black Magic department.

One reason the newly publicized pervasive digital rape will likely continue is that computers and software are, to many people, really the contemporary equivalent of black magic or of the equally baffling magic tricks of Harry Houdini and David Copperfield.

Since some of Houdini's most famous stunts involve escaping from handcuffs and other restraints, we'll tell you a little about "escapes" in software.

As a regular user of non-glamorous computers (aka PCs with Windows OS), we know you have been wondering about that "Escape" key, and there are some jokes on the web if you are curious.

It may come as a surprise that "escapes" or "escape sequences" are f***ing everywhere in software. Wikipedia as a page on "Escape sequences" from the stone age of computing, which ended about 25 human years ago.

In programming, someone once decided that the backslash, the \, being a little used character in written communication would make a great little switch or marker for telling the computer to stop doing what it was doing and start doing something else.

For example:
This is a line. We do not have enough room, so we use the backslash \
in order to display it as a single continuous line to the user.

Which means that if we want to display a backslash to the user, our code has to have two like this: \\

All of a sudden, you can end up having four in your code like this: \\\\

Crazy?

That's one of the two reasons why programmers get paid big bucks. The second reason is that they have to translate perfectly good real world statements and processes into lots of lines with backslashes and other escapes, such as "".  At the same time, if they have, say, two things, they need to tell the computer that thing 1 is thing[0]. Or, in some programming languages, thing 1 is thing(1) to the computer, hard to remember after a night out.

Not getting the escapes right and starting to count from the wrong "base" (0 or 1) are two problems that have cost untold millions of dollars in the short digital age.

On the positive side, you can become a rock star if you pull a Houdini with an escape sequence or two.

A real life example? Sure.

There was a company with a great software that allowed you to manage assets, keep track of all kinds of material in your company and do fancy things.
Complex software requires training. So, some thirty people we sitting in a class room in sunny California, learning from scratch or updating their skills.
The students really liked the software (it was not at Microsoft) but they had a problem with the reporting feature. Reports would be long, many pages listing different stuff and the last line, the total, of each sub group was not offset.

They wanted an empty line, like the one just above this sentence.

But the form on the screen did not allow it. File a request and it might take a year for the new version to have the feature -- or not, if the decider didn't feel like adding it.

During a break, one of the students sat down at a training computer, brought up the report form and added a \n in front of the text that the user could enter to label the last line, the total, of the sub-group, like so:

\nTotal number of Houdini handcuffs in department A

And "Print", and there was the empty line on the printout. Another try, like so:

\n------------\n\nTotal of cuffs:

Which gave an empty line, then a line of -------, another empty line, then "Total of cuffs".

Try it, the student told the others. Minutes later, everyone was chattering and clucking, and the teacher was busy taking notes.

Getting entangled in a "newline" will not kill you, which partly explains why nerds are not a bunch of modern day Houdinis but it can still do lots of damage and send programmers scurry off with the newlines between their legs.

No comments:

Post a Comment