[Prev][Next][Index][Thread]

Re: Extending format strings.



On Tue, 14 Nov 2000 10:30:01  
 Michael T. Richter wrote:
>"Rob Myers" <robm@h2g2.com> wrote in message
>news:974199664.28658.0.nnrp-12.c3ad61e3@news.demon.co.uk...
>>> I'm a little fuzzy on the distinction between %= and %S.  When would
>>> I use which one?  Why?
>
>> %= is when you don't know what you're going to be printing, it's just
>> some subclass of object, anything goes. %S is when you know what you're
>> going to be printing and you'd like some type safety.
>
>How does %S give me type safety?  If I override print-message for <foo>,
><bar> and <booger>, I can still screw up by using the control string "%S %S
>%S" and calling with (<foo>, <booger>, <bar>) instead of the expected
>(<foo>, <bar>, <booger>).  And since there's a print-message for <object>,
>it isn't even as if my not having a handler for a particular type will get
>caught.  I'll just get irritating results instead.

I've always thought of %s as being the display function for users,
and %= as the display function for developers. So debugging code
and error messages typically use %=, but any other output is
better with %s.

In particular, %= needs to be able to print nested objects properly,
which means that it has to quote strings, characters etc to avoid
ambiguity. As %s doesn't have this requirement, it lets the
developer have complete control over the output. So the simplest
example of the difference is:

  format("%s", "hello") => hello
  format("%=", "hello") => "hello"

Hope this helps,

Andy

---
Andy Armstrong
andrewa@functionalobjects.com



Get FREE Email/Voicemail with 15MB at Lycos Communications at http://comm.lycos.com