[Bioperl-l] why string overload is bad
akarger at CGR.Harvard.edu
Fri Jul 1 11:14:40 EDT 2005
> -----Original Message-----
> From: Ewan Birney [mailto:birney at ebi.ac.uk]
> Sent: Tuesday, June 28, 2005 9:57 AM
> To: Stefan Kirov
> Cc: Hilmar Lapp; Bioperl
> Subject: Re: [Bioperl-l] why string overload is bad
> >> Do people really want to go the route of string-overloading the
> >> annotation classes? To me it's really over the top and is a step
> >> backwards for ease of using the toolkit.
> > Hilmar definitely has a point here.
> I have always been against string overloading. The subtly of the bugs
> generated and non-obvious code paths (when Perl wants a number, does
> it go via hte string-overloaded case...)
> I also (personally) think overloading in C++ is bad. I just
> think overloading
> is bad wherever.
I wouldn't say "wherever". For example, it's probably worth it for complex
number libraries, so that you don't have to use the "plus" function every
time you want to add variables. (Especially because you need to overload
+-*/% etc., so code will be MUCH more readable with the overloaded values.)
That said, IMO it should be used only in cases that are clear wins, not for
minor convenience, or even slightly increased elegance. And it's better if
the overloading is clearly defined & scoped without side effects. It sounds
like there are side effects here. String overloading is probably more side
effect-prone than number, because you do fewer complicated things with
numbers (math, change to boolean) than strings (tons of perl functions, not
to mention m// and s///).
More information about the Bioperl-l