Comp Lang: the Hack of C Printf Format String
The origin of format code %f %x in programing languages
- in programing languages, the format code %d %f etc, where did it origin
- https://x.com/i/grok/share/SSwIug2PWct8GJ6geCnVwWzqy

The origin of escape sequence in string
which programming language started the \n \t escape sequence

C Programing Language Printf Format Damage
- Computer Science.
- The C programing language printf did huge damage to programing languages.
- It is fairly complicated.
- Involving multiple issues that are not related to each other.
- These tasks are done by a single function due to hack nature of C lang.
- Also, its syntax is very complex, effectively a mini-language.
- C, due to popularity, made other programing languages inherit badly designed C printf syntax and semantics. e.g. Cpp, Java, Python, Perl, PHP, Ruby, Golang, Emacs Lisp.
Because the printf is very badly designed, we see that, in past ten years, many programing language tries to fix this problem. e.g. python had 3 totally different formatting mechanisms each separated by few years.
JavaScript doesn't have the C format to this day.
Analysis of the Tasks Done by C Printf
Here's an analysis of what the c printf do exactly. It does many things, related but distinct.
- A string template system.
- Number to string. Needed for output.
- Formatting number, e.g. number of digits, number of decimal places (important in finance), padding 0 in front, or scientific notation for very large number.
- Convert decimal to binary or hexadecimal. Needed because numbers in digital computers are in binary, and hexadecimal is a condensed representation of binary. many different needs. E.g. IPv6 address. (Convert number to different bases also means convert number type to string type.)
Related tasks that printf does not do
- String to number. Needed because the input is often string, and numbers in programing language must be represented as number type, for efficiency reasons. Input may come from human, or from other programs.
- Convert binary or hexadecimal to number. (special case of string to number) Needed because input often are in hexadecimal or binary. E.g. IPv6 address, UUID.
What is a Better Design of Printf
Separate functions for:
- String template. (it should allow embedded variables.)
- Convert number to string
- Convert number to hexadecimal or binary or other bases.
- Formatting number.
Format String in Different Programing Languages
- Wolfram: String Template
- Wolfram: Convert to String
- Wolfram: Convert to Binary, Hexadecimal, Base 64, etc.
- Python: Format String (Convert to String)
- Python: f-String (Format, Template)
- Python: The .format (String Method)
- Python: Print with Percent Format String