What happened to "explicit is better than implicit"? "Only one way to do stuff"? One of the more baffling Python features if you ask me.
What happened to "explicit is better than implicit"? "Only one way to do stuff"? One of the more baffling Python features if you ask me.
> name = ‘Jane’
> print(f”Hello, {name}”)
and PHP’s:
> $name = “Jane”;
> echo “Hello, $name”;
> name = 'Jane'
> print 'Hello, %s' % (name)
but I can't exactly reproduce all the discussions from back then. As for me personally I can see that I dislike the new
> print(f'Hello {name}')
format because my editor cannot instantly show me that {name} is in a fact a variable, and now that I wrote this down I remember that this was one of the complaints made against PHP's use of "Hello, $name" . But maybe newer editors do in fact recognize {name} as a Python variable, in any case it looks and feels "impure", for a lack of a better word.
PHP:
print("Hello, $name")
print("Hello, ${getName()})
Python: print(f"Hello, {name}")
C# Console.WriteLine($"Hello, {name}")
Javascript Console.Log(`Hello, ${name}`)
Ruby puts "Hello, #{name}"
etc.However I think it's fair to credit PHP with introducing generations of programers to the idea.
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"
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!