开发者

Why is there an escape sequence for VERTICAL TAB?

开发者 https://www.devze.com 2023-04-03 17:12 出处:网络
Another question, What is a vertical tab?, describes what 开发者_开发技巧the vertical tab character was originally used for.

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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消