[mythtv] API suggestions
Renchi Raju
renchi at pooh.tam.uiuc.edu
Fri Feb 6 11:37:56 EST 2004
On Fri, 6 Feb 2004, Joseph A. Caputo wrote:
> On Friday 06 February 2004 06:26, Henrik (Mauritz) Johnson wrote:
> > Hi, a few questions and suggestions regarding the API. These are not
> > in any particular order and I'll probably find more stuff as I keep
> > working with it.
> >
> > 1. The use of QString and const is totally messed up. For instance
> > why use the "const QString" datatype... ever? The correct usage
> > should be "const QString &" which will save one extra copy. I know
> > that QStrings are shared and therefor quickly copied, but that
> > doesn't make it right. Someone should go through the API and clean
> > that up. (I volunteer if someone give me CVS access).
>
> Just to clarify, the proper usage of QString when calling functions is
> as follows:
>
> -As a value-based argument to a function (read-only): "const QString &"
> (you could also pass "QString" or "const QString" by value without
> incurring too much overhead, since the class is implicitly shared, but
> if you don't need write access to the argument, then pass-by-reference
> is preferred)
you are right. but const in "const QString" is redudant. but then
again, its a trivial issue.
>
> -As a reference-based argument to a function (caller expects argument to
> be modified inside the call): "QString &"
> (I imagine this is not encouraged)
its useful sometimes like when you want to do an assigment
A.text() = "some string";
but i usually prefer a set/get style.
> -As the return value of a function: "QString"
> Most definitely *never* return a "QString &" or "const QString &" from a
> function unless you are very sure of what you are doing!
"const QString& function()" never hurts. in fact i would recommend it over
just plain "QString function()"
renchi
More information about the mythtv-dev
mailing list