I think it's again helpful to consider golang as "roughly as modern as
Python, but definitely more C-inspired".
The thing that Python f-strings do (other than allow interpolation of
arbitrary code to be executed, which can be very handy) is that they
generally provide a sane default representation of the value you want. For
instance, you can say:
print(f"Value of foo == {foo}") and you get either something sane if foo is
a primitive type, or you get whatever foo's __str__() method gives you if
it's an instance of a class; the default class general does something
not-terrible with that, but you can add __str__() and __repr__() if you
have opinions about how you want to represent your class when printed for
humans or for machine consumption (effectively, __repr__() should let you
reconstruct the object, while __str__() is for display to humans).
This overcomes something C doesn't easily let you do. Most of the time I'd
rather not have to care whether the thing I'm printing is a string, or a
pointer, or an integer, or whatever: I just want to see its value.
Go has %v for exactly this. It's very nice for debugging.
On Fri, Aug 4, 2023 at 1:15 PM Larry McVoy <lm(a)mcvoy.com> wrote:
Perhaps it is a stretch, but I'd say that
printf() is a good example of
the type of thinking done by the original Unix folks. Seeing how other
people didn't learn that lesson kind of underscores the good engineering
done at Bell Labs.
On Fri, Aug 04, 2023 at 04:11:02PM -0400, Noel Chiappa wrote:
How is discussing Python's output options
related to the history of Unix?
Noel
--
---
Larry McVoy Retired to fishing
http://www.mcvoy.com/lm/boat