[Python-Dev] PEP 460 reboot (original) (raw)
Cameron Simpson cs at zip.com.au
Thu Jan 16 09:10:42 CET 2014
- Previous message: [Python-Dev] PEP 460 reboot
- Next message: [Python-Dev] PEP 460 reboot
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 14Jan2014 20:23, Antoine Pitrou <solipsis at pitrou.net> wrote:
On Tue, 14 Jan 2014 10:52:05 -0800 Guido van Rossum <guido at python.org> wrote: > Quite a few people have spoken out in favor of loud > failures rather than silent "wrong" output. But I think that in the > specific context of formatting output, there is a long and IMO good > tradition of producing (slightly) wrong output in favor of more > strict behavior. Consider for example what to do when a number > doesn't fit in the given width. Would you rather raise an exception, > truncate the > value, or mess up the formatting? All languages newer than Fortran > that I've used have chosen the latter, and I still agree it's a good > idea.
Well that's useful when printing out human-readable stuff on stdout, much less when you're emitting binary data that's supposed to conform to a well-defined protocol. I expect bytes formatting to be used for the latter, not the former.
I'm 12 hours behind in this thread still, but I'm with Antoine here.
With protocols, there's a long and IMO good tradition in the RFC world of being generous in what you accept and conservative in what you send, and writing bytes data constitutes "send" to my mind.
While having numbers overflow their widths is (only) often ok for human reports, even that is a PITA for machine parsing later.
By way of a text example, my personal bugbear is the UNIX "ps" command in its many flavours. It has fixed width columns with fields that frequently overflow these days, and the overflowing numbers abut each other. Post processing this rubbish is a disaster (I don't want to write "ps", but I have written things that want to read its output).
Of course the fix is easy in some ways, use format strings saying "%-5d %-5d %-5d" instead of "%-6d%-6d%-6d". But the authors of ps didn't. And quietly overflowing these fields is exactly what breaks my post processing programs.
Morally, this is the same as mojibake.
Therefore I am firmly in the "fail loudly" camp: if the format string doesn't behave as you naively expected it to, find out early while you can easily fix it.
Cheers,
Cameron Simpson <cs at zip.com.au>
Motorcycles are like peanuts... who can stop at just one?
- Zebee Johnstone <zebee at zip.com.au> aus.motorcycles Poser Permit #1
- Previous message: [Python-Dev] PEP 460 reboot
- Next message: [Python-Dev] PEP 460 reboot
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]