[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Arithmetic on strings
- From: Miles Bader <miles@...>
- Date: Mon, 09 Jul 2012 13:38:11 +0900
Rena <hyperhacker@gmail.com> writes:
>> Speaking as a Python developer, I agree with you. Things should
>> coerce *to* strings much more readily than they should coerce
>> *from* strings.
>
> +1, I've expressed a few times that functions expecting strings as
> input should call [__]tostring. It'd make life easier when dealing
> with objects that may or may not be strings but can be converted to
> them. The C API is where this bugs me most, as few libraries bother
> to do it themselves.
There's certainly a time and place for implicit to-string coercion in
various functions (not in the VM), but it's just silly to say that
_every_ function expecting a string should do this. It's a judgement
call.
E.g., I agree that the format %s directive should call tostring on its
argument. But I think (1) string.concat should not, (2) in general
functions which are "obvious" string-only operations, and would only
be used with non-strings in "weird" circumstances (e.g. some sort of
"set_title" function) should not, (3) more "primitive" functions
should tend towards less coercion, and (4) more "debuggy" functions
should tend towards more coercion.
Sorry if that's all a bit handwavy, but ... I expect many of you "know
what I mean" ... :]
-miles
--
Yossarian was moved very deeply by the absolute simplicity of
this clause of Catch-22 and let out a respectful whistle.
"That's some catch, that Catch-22," he observed.
"It's the best there is," Doc Daneeka agreed.