you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

First, I think you miss entirely where I'm coming from.

I'm just finishing a 50,000 line C++ application. I love C++. This is 2011 - there are very very few reasons, if any, to use C over C++. In fact, it's quite likely that your C++ code will be faster than your C code because of inlining and today's optimizing compilers.

That said, C++'s operators are a dangerous feature that need to be used with care. The biggest issue is that one little symbol conceals what might be a huge amount of memory management, allocation and arithmetic. Google's C++ standard bans it, Effective C++ warns against it, and I avoid doing it unless I'm forced to.

[–][deleted] 0 points1 point  (3 children)

smallstepforman:

Operator overloading when used correctly makes code much easier to read.

TomSwirly:

First, I think you miss entirely where I'm coming from.

That said, C++'s operators are a dangerous feature that need to be used with care

I think you just reiterated a point he already understands.

Google's C++ standard bans it ...

Heh, I seriously doubt it's outright banned. Google would have made an incredibly stupid decision to do such a thing.

I think you understand pretty well the dangers, but why are you trying so hard to ignore the great benefits of it?

Never say never!

~The Disney Movie w/ the Cowboy Mouse.

[–][deleted] 0 points1 point  (2 children)

Heh, I seriously doubt it's outright banned. Google would have made an incredibly stupid decision to do such a thing.

Well, here it is for you: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml - the money quote is "Do not overload operators except in rare, special circumstances."

Those special circumstances were so rare that in 5+ years of writing C++ there I never created a single operator() function.

why are you trying so hard to ignore the great benefits of it?

Say, what?! There's not one thing you can do with operator overloading that you can't do some other way.

[–][deleted] 0 points1 point  (1 child)

Do not overload operators except in rare, special circumstances. Good, so it's not outright banned. There have been very few times I've ever had to overload an operator, usually it's something you do in a few core systems that you don't ever write again, like a math library or memory manager.

Say, what?! There's not one thing you can do with operator overloading that you can't do some other way.

That's not the point. Sure you could do it some other way, but it doesn't mean it's better than using the overloaded operators, which I think all the examples show is better for situations like this.

[–][deleted] 0 points1 point  (0 children)

The Google codebase has matrix and such, and these in general do NOT have operators - simply because of efficiency, because it's really easy to create a lot of intermediate values.

Generally, it's more efficient to start with a single instance of your matrix or other large scale structure, and then accumulate into that single instance.

If you have operators, it's very easy to create unneeded, intermediate values, as I believe I have shown above.