Ben Finney writes:
"Stephen J. Turnbull" <stephen@xemacs.org> writes:
But when you don't have a TABLE element available for formatting tables, width, precision, base, and the like are *necessary* information for nice output. Do you really think it's readable to write
"I propose a fine of ${payment: type=float precision=2} for not reading the docs.".format(payment=100)
vs.
"I propose a fine of ${payment:.2f} for not reading the docs.".format(payment=100)
The first is far more readable, because it is explicit and doesn't require special knowledge to know what the parameters are.
Ah, but the example isn't really very good. In most cases in running text "everything default" is what you want, which I think we all agree is most readable. (Somebody wanted Perl-style $VARIABLE, but I don't see a big difference between that and {VARIABLE}, especially in cases where you want concatenation with trailing identifier characters and would have to spell it "${VARIABLE}" or something like that anyway.) Where you'd want precise control of formatting is a multicolumn table, which will add a "width=10" parameter for a total of 45 columns for the format for a single variable. As soon as it wraps (two columns ;-), it becomes unreadable. The "10.2f" in the idiom of .format() will take only 16 columns, so you can easily get 5 readable columns in an 80-column window, and in general about 3X as many columns in the same window as with the "locally" more readable explicit format. That's not at all inconsistent with your statement that "sometimes concise expression is important", of course, but I did want to point out that concise expression has important readability benefits.
An uninformed guess by a casual reader is much more likely to be right in the first case; I think that's an important criterion for readability.
I'd argue that the casual reader most likely doesn't actually care about the formatting, especially in in the running text case. YMMV, but I'd bet on that, and would take the current formatting with keyword arguments for content and short moderately mnemonic codes for style as "most readable" for the cases where the styling of presentation matters.