[erlang-questions] io_lib format inconsistancies

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Sep 20 09:18:04 CEST 2012


On Wed, Sep 19, 2012 at 03:39:15PM -0400, Andrew Thompson wrote:
> On Wed, Sep 19, 2012 at 03:38:42PM +0200, Raimo Niskanen wrote:
> > These are the obvious flaws I see:
> > 
> > * Something like ~P for printable binaries is needed for strings,
> > but the value 4 characters for depth 1 seems low. An atom has max length
> > 256 bytes (I think) giving depth 1. ~P for printable binaries should behave
> > like for strings.
> 
> So what should the behaviour be? Print printable binaries completely, or
> up the depth from 4 to something larger and apply it to strings as well?
> If so, what should the limit be?

I'd say that since this is about printability it should also be about
readability. An atom of some 10 chars is readable. Perhaps it is what fits in
a line that is interesting. There is code in io_lib_pretty that does not like
to print on a line when indentation exceeds half the line length, and default
line length is 80.

So a value below 40 seems reasonable. For a non-printable list or binary every
depth prints an integer that occupies max 7 chars for the maximum unicode
value. Somewhere between 7 and 40, then. The values 8, 16, 20 and 32 springs to
mind. How about 16?

That is: every 16 chars in a printable string or printable binary should count
as a depth increase of 1 instead of today 4 chars for printable binary and
unlimited for printable string.

The value should just limit what conveniently fits as an item when printing
a complex term, so 20 or 32 might be better values...

Another option is to fill the current line. I do not know if that is doable in
io_lib_pretty, or if the code requires a fixed size for all items to decide on
line breaks...

> > 
> > * The discrepancy for ~P vs. ~W on <<>> should be fixed.
> 
> Agreed, I'll make a patch.
> 
> Thanks again for confirming my suspicions that these weren't really
> thought out behaviours.
> 
> Andrew
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list