On 14Jan2014 20:23, Antoine Pitrou <solip...@pitrou.net> wrote: > On Tue, 14 Jan 2014 10:52:05 -0800 > Guido van Rossum <gu...@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 <c...@zip.com.au> Motorcycles are like peanuts... who can stop at just one? - Zebee Johnstone <ze...@zip.com.au> aus.motorcycles Poser Permit #1 _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com