string conversion, format functions

Chris Pressey cpressey@REDACTED
Thu Apr 24 01:07:48 CEST 2003

On Wed, 23 Apr 2003 23:39:28 +0200
Matthias Lang <matthias@REDACTED> wrote:

>   9> B = 3.
>   3
>   10> io:fwrite("~4.4.0w\n", [B]).
>   0003
>   ok
> integers are formatted using the 'term' format (~w), there's no need
> for an explicit 'integer' format.

Wow.  Would you believe, I got so used to using ~p that I completely
forgot ~w even existed?

When I started using it, I just assumed ~p behaved exactly like ~w, only
prettier.  I didn't think to check that the format parameters had a
different meaning.

Now I'm starting to see some of the lovelier warts of io:format :)

If ~n is defined to be \n on all platforms then it's completely
redundant.  It just gives you a false sense of abstraction.

~r doesn't exist.

If format parameters mean different things for different formatting
codes then programs written with io:format become that much harder to
read and maintain, becuase they require that much more memorization.
(I can never remember which leading integer is field width and which
is precision anyway.)

And then there's ~i.  That's just disturbing.  It's almost funny. 
Thankfully, I couldn't find it used anywhere in OTP with a quick grep.
(If it is, it's used with a field width or precision... and that's even
more disturbing.)

If hex/other bases are added to io:format, it'll just get nastier.  Not
really a problem at this point though, since whatever elegance there
once was in it has apparently already left town :)

It's kind of strange, when you think about it, have there even been any
significant advances in "output formatting technology" since, what,
FORTRAN?  None that have caught peoples' imagination enough to be
adopted, anyway - Perl's 'reports' are pretty nice, but I don't think
I've ever seen a Perl program that actually *uses* them...


More information about the erlang-questions mailing list