Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: Boost.String.Convert
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-02-18 08:52:35


On Tuesday, February 17, 2009 5:43 PM
Emil Dotchevski wrote:
> On Tue, Feb 17, 2009 at 2:34 PM, Steven Watanabe
> <watanabesj_at_[hidden]> wrote:
> > Emil Dotchevski wrote:
> >>
> >> The two approaches are:
> >>
> >> 1) Define a "to_string" interface and a separate, independent
> >> "from_string" interface
> >>
> >> 2) Define a single interface that can go to and from string
> >>
> >> The second approach introduces coupling between to_string and
> >> from_string. This coupling must be justified, you need to get
> >> something in return. The only "something" I see here is
> that it lets
> >> you write code which doesn't "know" if it's going "to" or "from"
> >> string.

The coupling is not of implementation but of interface. They are opposite sides of a single coin, so coupling them is not a terrible thing.

The directionality you see is due to focusing on string with the other things converting to and from strings. If, instead, you view it as converting from one thing to another, where string can be the source or destination type, then all conversions are, effectively, one way.

> > The only other benefit, is possible syntactic nicity. Note that
> > this function can be in a very light weight header that forwards
> > to the correct implementation, so the coupling would be minimal.
>
> Your description is identical to 1) as far as I'm concerned because
> there is no coupling between to_string and from_string (the coupling
> is between convert() and to_string/from_string). However, in this

Indeed, conversion to string is implemented apart from conversion from string, but that hardly necessitates total separation.

> design it makes sense convert() to be a separate library altogether,
> assuming it's scope goes beyond string conversions alone.

It may well be, as I previously suggested, that there is an underlying set of functions for converting to strings and from strings to which convert defers. That would permit you to get your preferred interface while others could use a more generic convert() interface, provided both were documented.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk