14

(Let me know if this is the wrong SE for this)

Why is a Here Document (or Heredoc) called that? Wikipedia didn't have anything to say on that particular subject. I did find unix docs describing a "Here is document", is that the original form?

14

Some teleprinters* had a sequence of a dozen or two characters that could be programmed (mechanically) into the unit and was sent when the host sent an ENQ character or the operator pressed the HERE IS key on the keyboard. A number of glass-tube terminals had the same feature.

A "here-is" document in shells and programming languages that support the same construct serves essentially the same purpose: it's a canned sequence of characters that doesn't change unless the program does.

*These are also the origin of the term tty that appears in Unix.

  • Aha! That's the kind of trivia I was looking for :D Thanks! – Yamikuronue Apr 12 '12 at 14:50
  • 2
    Sometimes it pays to be old. – Blrfl Apr 12 '12 at 14:53
16

Well, the document is right here. Here it is. It's a logical name for the thing, yeah?

When people speak of 'here documents' they are generally speaking of a unit of data that is embedded into code. That data will be displayed to a user or used to compose a request to a server or to write information to a log or to update a configuration file, or, or, or,or... It's a mistake to overload the name with meanings and connotations. It's a programming technique and it has a name.

  • 2
    Since when is a prettily formatted string a "document" necessarily? The one implies data connotation that a heredoc doesn't necessarily have. +1 for making me smile though :) – Yamikuronue Apr 11 '12 at 15:18
  • 7
    I hate to get all Forrest Gump on you, but a document is as a document does. When people speak of 'here documents' they are generally speaking of a unit of data that is embedded into code. That data will be displayed to a user or used to compose a request to a server or to write information to a log or to update a configuration file, or, or, or,or... It's a mistake to overload the name with meanings and connotations. It's a programming technique and it has a name. – Adam Crossland Apr 11 '12 at 15:47
  • Huh. Maybe it's a regional linguistics thing: I usually see "document" used as "The kind of file you'd make in Word" and "file" or "data" for more generic uses. The term "Heredata" would make more sense to me >.> – Yamikuronue Apr 12 '12 at 12:27
  • 1
    The 'here document' idea predates Word by many years. – Adam Crossland Apr 12 '12 at 13:17
  • Sure, but I wouldn't call a picture a 'document', even if it fulfills some of the technical requirements outlined in Wikipedia – Yamikuronue Apr 12 '12 at 13:39
7

It's called a here document because it is 'here', in the source file that needs it, rather than being elsewhere, as a separate file. I guess looking deeper into it would be rather like trying to analyse the term '4 wheel drive' in great depth.

It can be very convenient to have your data within your code.

5

Because it's all data from << HERE

all the way

down

to

right about

wait for it

HERE;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.