Hacker News new | past | comments | ask | show | jobs | submit login

That's an interesting question. I couldn't find any summary of the history of string interpolation. The first version of PHP in '94 had it. Bash predates that by 5 years and Perl by another 2, but I'm not sure about the initial feature set of either of those. The first POSIX standard for command interpreters is from 1992. I suspect the feature comes from early versions of csh in the early 80s.

However I think it's fair to credit PHP with introducing generations of programers to the idea.




String interpolation was there in the first versions of the Bourne shell, and I suspect the pre-Bourne shell in PDP-7 Unix in 1970 or so, but of course programmers have been generating strings by pasting together bits of constant and variable strings for a lot longer than that; Church defined the λ-calculus in terms of string interpolation in the 1930s, before there were even any computers. Computer-generated printed letters were already a commonplace occurrence in the US in the 1950s (at least if references in the fiction of the era are to be believed), and those are of course built with string interpolation. Around that time, assembly languages became the first languages to claim to make computer programming obsolete (because at the time "programming" meant programming in binary), and rather quickly some of them developed macro capabilities — before 1960, I think. Macro assemblers typically do their macro magic with string interpolation, even today. High-level languages of the time commonly used template strings, like those in (1964?) BASIC's PRINT USING statement, though FORTRAN's "edit descriptors" used a non-interpolation-based syntax. COBOL's "edited picture" feature is a kind of string interpolation, but I have no idea when it was added to COBOL.

In the 1970s string interpolation really got going with languages like sh, cpp, and m4, which was popularized on many platforms by the "Software Tools" book (which in a sense is a slow buildup to the presentation of m4); m4 is Turing-complete entirely through string interpolation (more so even than Tcl decades later).

I suspect Perl had string interpolation from the beginning (1988), given its shell roots, but I don't have a copy of Perl 1 to test with.

For an overview of modern languages' string-interpolation syntax, I suggest https://www.rosettacode.org/wiki/String_interpolation_%28inc....

Hope this helps!


Bourne shells as early as Version 7 Unix (1979, [1]) had rather elaborate interpolation of variables into strings (i.e., not just ${foo} but ${foo?bar}, etc.).

I'm reasonably sure that earlier versions of sh had some facility for this as well.

So, it's not really a PHP innovation, although some people might have seen it first there.

[1] https://www.in-ulm.de/~mascheck/bourne/v7/ -> "Parameter substitution"


Apparently Unix Version 6 (1975) used Thompson Shell which (provided the manuals are correct [1][2]) didn't support arbitrary variables (and even environment variables were not a thing back then). However for use in scripts $0, $1, etc were replaces with the script name and the arguments.

1: https://www.in-ulm.de/~mascheck/bourne/v6/

2: https://etsh.nl/man/_tsh.1.html




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: