This video argues that C's printf function is a "hack" that has caused pervasive harm in programming language design (1:57).
The speaker explains that printf combines multiple distinct operations—string templating, number-to-string conversion, number formatting (e.g., decimal places, padding), and base conversion (e.g., decimal to hexadecimal)—into one cryptic mini-language (2:50, 26:56, 29:21).
Because C was popular, many languages like Python, Perl, PowerShell, Go, and Emacs Lisp borrowed this design (2:57, 23:14).
However, these languages later found printf's design problematic and introduced their own, often incompatible, string formatting methods (8:17, 28:07).
The speaker then introduces their proposed "rock string" syntax (50:56), which aims to solve these problems by:
Eliminating escape sequences (51:19), which lead to the "backslash toothpick syndrome" (51:37).
Allowing embedding of non-printable characters and expressions directly.
Using a single, simple syntax with customizable delimiters for literal string representation (57:28).
C and unix caused pervasive harm in programing languages and computing industry.
C printf, is the quintessence of its hack nature.
Why is printf a problem? Explain. It effectively creates a mini-language that is cryptic, incomprehensible, and hard to use, and not extensible.
The reason why printf is hard to use. Explain. Because it combines several distinct operations into one, and uses a cryptic ad-hoc syntax for them. Show article.
C is designed 50 years ago, why blame c? Explain. Because, old tech is not a problem, the problem of c and unix is that it creates a cult, and instill programers a notion that it is actually the best design.
What should be the proper fix. Explain
Now, separate issue. The problems of string in general. (also due to C)
x = 3.256
print( "the price is %f" % x )
# the price is 3.256000
x = 3.256
print( "the price is %.2f" % x )
# the price is 3.26
x = 123.256
print( "the price is %5.2f" % x )
the price is 123.26
x = 123.256
print( "the price is %9.2f" % x )
# the price is 123.26
y = 17
print( "hexadecimal of %d is %x" % ( y, y) )
# hexadecimal of 17 is 11
# show 2 decimal places, with grouping
"{0:n2}"-f 123456789.123456789
# 123,456,789.12
"the decimal number {0:d} in hexadecimal is {0:x}"-f 17
# the decimal number 17 in hexadecimal is 11
(let ((x 17))
(print (format"decimal number %d in hexadecimal is %x"xx))
)
;; "decimal number 17 in hexadecimal is 11"
packagemainimport"fmt"funcmain() {
varx = 17
fmt.Printf("decimal %d in hexadecimal is %x \n", x, x)
// decimal 17 in hexadecimal is 11
}
x = 17;
StringTemplate["decimal number `` in hexadecimal is ``"][x, IntegerString[x,16] ]
(* decimal number 17 in hexadecimal is 11 *)