Thread: Programming!
View Single Post
  #65    
Old March 3rd, 2013 (09:30 PM).
twocows's Avatar
twocows twocows is offline
Pretentious Intellectual Jerk
Gold Tier
 
Join Date: Mar 2009
Location: Michigan
Age: 24
Gender: Male
Nature: Lax
Posts: 4,049
Quote originally posted by Archenoth:
Misleading spacing was indeed part of it. My point was that you can write code in obvious, and non-obvious ways. The same is true for code that utilizes overloaded operators.

Your code should be consistent and readable. Establish a way you use overloaded operators so that you don't really need context when looking at a given function; Make things obvious.

I won't quote your entire post, but you described your thoughts quite well and had some good points (Even if you were a bit condescending.). While I still don't share your opinion, I understand it better... So have a like.
I was frustrated at C and C++, not you. I can see how you might have misinterpreted.

Again, though, my biggest problem with operator overloading is that they can be easily abused by newcomers without realizing it, and abused in such a way that makes it really, really hard for people who have to maintain the code later. This is a problem that only exists if you let the programmer do it. It's a lot nicer in C, where the only operator overloading occurs in the specification; the programmer can't do it. Having poorly thought-out stuff at the language level is a problem, but it's nowhere near as big of a problem as letting tens of thousands of bad programmers go nuts with a dangerous feature. At least once you're experienced with C, you'll know what's what; with C++, every new source file is potentially a new list of operators you need to memorize.

And again, yes it's possible to use it in an acceptable way. The problem isn't that there is a right and wrong way to use the feature, the problem is that abusing it causes far more problems than abusing other typical language features. For instance, take #define macros. Yes, these can be abused and in a very ugly way, but at least the relationship is still 1-to-1; you can guarantee that unhelpfulmacroname is going to expand to the same thing every time. With operator overloading, that's not the case; you can come across an operator and, unless you've memorized the author's arbitrary list of "things I overloaded," have no idea if it's going to mean this, that, or some other thing.

Basically, the biggest problem with operator overloading is that it makes a language context-sensitive. This is usually bad. Unless there's some compelling reason why it shouldn't be, everything within a language should be understandable without examining the context. And opening it up for the programmer to do that means that not only is the language context-sensitive, but each individual source file might have its own unique context-sensitive stuff, which is just outright horrifying.
__________________
Doctors Without Borders: one of the few charity groups you can rely on to actually do real good in the world.

"The trouble with fighting for human freedom is that one spends most of one's time defending scoundrels. For it is against scoundrels that oppressive laws are first aimed, and oppression must be stopped at the beginning if it is to be stopped at all." - H. L. Mencken, unsourced

"There is a cult of ignorance in the United States, and there always has been. The strain of anti-intellectualism has been a constant thread winding its way through our political and cultural life, nurtured by the false notion that democracy means that 'my ignorance is just as good as your knowledge.'"- Isaac Asimov, Column in Newsweek (21 January 1980) [source]
Reply With Quote