[Ktechlab-devel] documenting QuckVector

Alan Grimes agrimes at speakeasy.net
Sun Jun 28 21:48:15 UTC 2009


P Zoltan wrote:
>   Hello,

>   I've started to put qvector.h and qvector.cpp in a shape that I like  
> more. However, there are a few strange things:

Yeah, I wrote the class for a school assignment, the methods that are
actually used are generally half-way decent.

The only real thing it has going for it is that it was much much cleaner
than the previous code.

> - can't find the implementation of the operator:
>    QuickVector & QuickVector::operator*=(const double y);

oops!

fixed.

>   The operator appeares in the header, but not in the cpp file.

> - what's the difference between
>     inline double &operator[]( const int i)
>   and
>     inline double  operator[]( const int i) const

>   These look stange to me, because C++ should make difference between
> methods by their name and parameter definition, not by the return
> type; also the same operator is constant or not?

Yeah, that might be a mistake. The way the class was really meant to be
used was through the smalltalk style "at" and "atPut" methods, these are
unambiguous reads and writes... Those C++ style [] operators allow for
some really strange code, when seen from the eyes of a C programmer...

I put the [] methods in to make it work with the existing code base.

It would probably be an improvement to force all code to use one or the
other, I prefer the at and atPut pattern because it makes it easy to
find reads and writes. In a number of places, the syntax is cleaner as
well... admittedly, I'm probably using C coding styles when I should be
using C++ styles.


> - the return type in the operator declaration
>    QuickVector &operator-(const QuickVector &y) const;
>    looks also stange, because here:
>   http://www.java2s.com/Code/Cpp/Overload/DemoOverloadtheandrelativetoMyClass.htm
>   the "-" operator returns a simple object, not a reference. The current  
> declaration might produce memory leak.

Correct.

It is designed to accommodate:

QuickVector x = a - b;

Obviously, this is much more user friendly in a garbage collected
environment.

If you don't need a, you can use:

a -= b;

Actually, I don't have a -= but oh well...

>   Also a remark: I'm starting to convert tabs into 4 spaces, as this is the  
> preferred way in kde style c++ coding.

I've been a formatting nazi myself, submitting many commits that were
nothing but formatting... I find tabs better because they are easier to
navigate by the arrow keys. The only argument for 4-spaces is that the
tab width is not always consistient and that it leads to excessive
indentation, ( which is more of a code organization issue except in the
most irreducably complex algorithms...)

-- 
New president: Here we go again...
Chemistry.com: A total rip-off.
Powers are not rights.





More information about the Ktechlab-devel mailing list