Linked by Eugenia Loli-Queru on Sun 3rd Dec 2006 23:31 UTC
General Development Quickly becoming a de facto standard C++ library, the Boost library includes a powerful graph data structure that's also easy to use. Jeff Cogswell discusses some interesting theory behind graphs, and explains the Boost library's graph structures.
Thread beginning with comment 187876
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[3]: Awful
by CrazyDude0 on Mon 4th Dec 2006 18:49 UTC in reply to "RE[2]: Awful"
CrazyDude0
Member since:
2005-07-10

When you are debugging at least you know they are a function call.

How the hell do you know if + is a function call unless ofcourse you plan to make all operators overloaded?

Reply Parent Bookmark Score: 2

RE[4]: Awful
by h times nue equals e on Mon 4th Dec 2006 19:45 in reply to "RE[3]: Awful"
h times nue equals e Member since:
2006-01-21

Correct me if I'm wrong, but :

Standard C++ regulates, that the compiler can
only generate the copy constructor, the default constructor and the assignment operator, if they are not implemented. In any other case, including the operator+(), one has to implement the operator explicitly, like you would have to with functions.

If you have something a la

foo a;
bar b;

foobar c( a + b );

in your code, you have either to look for

foobar foo::operator+( bar const& rhs );

or

foobar operator+( foo const& lhs, bar const& rhs);

in your header files. Besides the inconvenience to look potentially for this two different notations, instead of one in case of a hypothetical plus() function, I can see little problems here.

Assuming one uses operator overloading only where it is justified (e.g. to translate arithmetic or gramatical operations like concatination into code), it is imho supperior to functions. I write numerical code for scientific applications, and at least I find

foobar d( a * b + c );

easier to read/maintain/understand than for example

foobar d( plus( prod( a , b ) , c );

Programmers, who abuse operator overloading should be treated with the proverbial clue bat, agreed. But operator overloading can, just like expression template metaprogramming, give you a very handy tool, that saves time and effort und is a joy to use.

Like every tool, it can be misused, though. but just because some developers choosed to obfuscuate the meaning of their programs by using operators, I don't see a reason to bash operator overloading.

Regards

EDIT: foobar c() -> foobar d() in the second and third example, sorry :-)

Edited 2006-12-04 19:55

Reply Parent Bookmark Score: 2

RE[5]: Awful
by Chicken Blood on Mon 4th Dec 2006 19:49 in reply to "RE[4]: Awful"
Chicken Blood Member since:
2005-12-21

Agreed. Any programming construct can be abused.

Operator overloading is one that can add clarity and elegance when used in the right context.

and no-one _forces_ you to use it when that context is not apparent.

Reply Parent Bookmark Score: 2

RE[5]: Awful
by CrazyDude0 on Mon 4th Dec 2006 20:24 in reply to "RE[4]: Awful"
CrazyDude0 Member since:
2005-07-10

First i didn't mean to write debugger, i meant when i am reading the code.

Operator overloading makes it harder for other people to understand your code.

The example you gave above could simply be:

x = calcMultiply(a, b);
x = CalcSum(x, c);
d(x)

What is wrong here, it is more clear and when you are reading the code, you immediately know that multiply is not simply an arithmatic multiplication.

I like to write code which the programmer can understand when they are reading it. Ambiguity is something that i hate and C++ has many constructs that are ambiguous.

Reply Parent Bookmark Score: 2

RE[4]: Awful
by Chicken Blood on Mon 4th Dec 2006 19:46 in reply to "RE[3]: Awful"
Chicken Blood Member since:
2005-12-21

The debugger should show the function 'operator+()' on the stack.

So what is the problem?

Reply Parent Bookmark Score: 3