|
Boost : |
Subject: Re: [boost] [endian] [bikeshed] Conversion function naming discussion
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2015-01-26 07:53:47
On Mon, Jan 26, 2015 at 5:09 AM, Rob Stewart <rob.stewart_at_[hidden]> wrote:
> On January 25, 2015 9:06:17 AM EST, Beman Dawes <bdawes_at_[hidden]> wrote:
>>
>> big_to_native
>> big_to_native_inplace
>> native_to_big
>> native_to_big_inplace
>> little_to_native
>> little_to_native_inplace
>> native_to_little
>> native_to_little_inplace
>> conditional_reverse
>> conditional_reverse_inplace
>>
>> These are quite explicit, but are a bit too long and awkward for my
>> taste. I'd be willing to change these names if someone can come up
>> with replacements that are shorter and less awkward, but still
>> reasonable explicit.
>
> One option is to use "_copy" for the first set and remove "_inplace" for the others.
>
> I generally like "to" rather than "from" in names, but the types are usually distinct, so that doesn't work so well here. Peter's "from_big", et al, aren't bad, but not great, from that perspective, but don't distinguish between little and native as the target order.
>
In general, I actually like "from" better than "to", as it typically
(although not in the endian case) solves a problem of param order:
foo_to_bar(a, b); // which is the foo a or b? ie strcpy order
(dst,src) or function-name order (foo,bar)?
foo_from_bar(a, b); // a is the foo. function-name order AND strcpy order.
(note: Stepanov admitted he got std::copy() in the wrong order and
should have matched strcpy() and assignment - destination on the
left).
But anyhow, in this case we only have a single arg, so not exactly the
same situation.
Other common words used for this are "as" and "make" (the std uses
"make" a lot, I think there are proposals for "as" - which are for
cast-like situations)
int x = as_little(y);
int x = make_little(y);
Not sure those are any better.
I would say "make" would actually be a good term for the in-place
version (ie alter this thing to make it little) if only the standard
didn't already use it everywhere with a return value. :-(
But maybe in-place could use different terms, replacing the "to/from"
with uh, something?
ie
bigify(x);
unbiggen(x);
Another alternative: use 'native' for the inplace versions
x = from_little(y);
x = to_little(y);
native_to_little(y); // in place
Probably not as clear as the other choices. :-(
Basically, I don't like any of them because I don't like that the
input's big vs little is not part of the type system (ie use the
arithmetic endian types), and is instead part of the function name
ie I'd prefer
int x = to_native(assume_big(y)); // assume_big casts y to a big
int type, without altering the bits, then to_native knows what to do
that could probably just be
int x = assume_big(y);
or
int x = assume_cast<big>(y);
because once assume_big returns a big_int32 then the int conversion is
already there.
Anyhow,
- I could live with the original long names (how often are they used?
Won't it only be in isolated code?)
- I could live with Peter's shortened names
Tony
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk