8

Another question, What is a vertical tab?, describes what the vertical tab character was originally used for.

But why was U+000B VERTICAL TAB considered important enough to be allocated an escape sequence ('\v') in the first place, in C and many other programming languages?

See also: some guy complaining about this.

Community
  • 1
  • 1
Mechanical snail
  • 29,755
  • 14
  • 88
  • 113

2 Answers2

10

Correct Answer: TELETYPE

It has nada to do with delimiters. My parents worked with big data and a lot of broadcasters and Fortune 500s were still using punch cards up to the 80's. Remember that most languages were originally designed to be entered and used on a teletype machine, not a screen. The printer was not just for printing documents like it is today. There was no monitor at all. The print-out was the display.

With that in mind, vertical tabs were pretty useful. Even post-teletype my parents used them render forms faster by overwriting just the parts that changed. Because back then even text-only display was too slow!

Fun video: https://www.youtube.com/watch?v=qv5b1Xowxdk

But more to the point: Many, many, many things in modern operating systems are relics of the teletype machine... not just vertical tab. We're just so used to them that people don't even think about them anymore, but they're no less weird. I sure many don't realize where these conventions come from unless they've been coding since the 70's.

  • Do you text-wrap your code or e-mail at 80 columns?
    Because IBM punch cards were 80 characters wide.

  • Do you use graphics that support bottom up encoding, such as Windows bitmaps, or any graphics libraries with the origin in the lower corner?
    Because teletype machines scrolled from the bottom up.

  • Do you use \n to indicate a new line of text?
    Because \n stands for line feed, which comes from manual typewriters before it was used in teletypes.

  • Have you ever sent a message to a friend by writing to /dev/tty under Linux?
    Because TTY is short for teletype.

  • Have you ever told someone to use an existing library instead of reinventing the wheel? Have you ever used a library or framework yourself?
    Because that's how old code hangs around. Certainly, the benefits outweigh the harm, but libraries built on top of libraries built on top of libraries leads to this creeping dependency such that even when the original library is long since gone, everything that was ever compatible with it causes its conventions to live on... and on... and on...

These teletype conventions are so firmly entrenched into the operating system itself I fully expect this will always remain until someone writes an operating system from scratch, and even then I'm not so sure. There's no question why the C language picked them up. Remember, C came long after LISP, Forth, COBOL, FORTRAN, Pascal and even BASIC.

P.S. Using the bell character as a delimiter would have been an insane thing to do. Grind grind grind BEEP grind grind BEEEEEEP grind chuka chuka BEEP grind chuka grind grind BEEEP. Whizzzz clunk. Grind grind BEEP...

lisa
  • 1,292
  • 12
  • 8
2

It's possible that when C was created, it was expected that the vertical tab and bell characters were expected to be sufficiently useful as delimiters within code that would be ported between ASCII and EBCDIC that code had to provide a readable and portable way of notating them. Although one could write

#define QVTAB "\013"
printf("Field1" QVTAB "Field2");

I don't think such usage was legal in the earliest dialects of C. Further, even if such usage is permitted, using special macros for quoted version of characters would probably have been considered a little ugly. I know such things ended up being necessary in printf portable-type format specifiers, but that doesn't mean it's pretty.

Another thing to consider is that C was not desgined to be a programming language that people would use in the decades to come. It was designed to solve some immediate needs. K&R wouldn't have cared about whether anyone would want VTAB characters after the 1970's; if their immediate customers would have use for them, that was a perfectly good reason to include them.

supercat
  • 77,689
  • 9
  • 166
  • 211
  • To think that several decades later we're having \v in pretty much every language still. – Camilo Martin Apr 08 '13 at 21:22
  • @CamiloMartin: From an embedded systems perspective, I've found myself wishing for a nice way to notate that a string should be stored using a particular mapping from the source character set into characters within a `char[]`. Such a mechanism would have eliminated the need for special-casing `\v`, and would have made it much easier to write code for the countless embedded devices that use internal coding schemes which bear relation to ASCII. A weirder inclusion in the C language is trigraph support, which is astoundingly hideous no matter how one slices it. – supercat Apr 08 '13 at 21:38
  • @CamiloMartin: In absolutely *any* context, two consecutive question marks followed by one of a number of other characters may be used to represent certain other characters which may not exist in certain character sets. For example, if I recall `??(` and `??)` may be substituted for `[` and `]`, `??<` and `??>` for `{` and `}`, etc. Such substitutions occur even within quoted literals, and quotes are among trigraph substitution characters, so `"What were they thinking???"` translates as `"What were they thinking?~` [which then lacks the closing quote]. – supercat Apr 09 '13 at 14:54
  • That doesn't look very pretty. But well, C was developed in a different age, so I guess there must have been use for that then... – Camilo Martin Apr 09 '13 at 20:03
  • @CamiloMartin: From what I read, trigraph support has been deprecated; my recollection is that in deciding to deprecate support, the Standard's committee searched for evidence of production code using trigraphs; the *only* code that was found which used trigraphs was in compiler test suites. So I don't know if there was *ever* a use for trigraphs. – supercat Jun 10 '15 at 13:05
  • @CamiloMartin: IMHO, everything that can be done with trigraphs could have been done, in more-compatible fashion, by specifying a directive which could designate any particular character outside the C character set to behave as backslash, and then adding backslash digraphs for any other possibly-missing characters. The only code which could be broken by such a feature would be code which used a compiler extension that looked like the directive to set the backslash-escape code; if the extension was chosen suitably the probability of such problems would be essentially nil. – supercat Jun 10 '15 at 13:11