News for hackers. Stuff that matters.
Re:Linus vs C++, again by wvenable on Thursday June 10, 2010 @07:35PM (#1422169)
C++ is one of the few languages where in "foo->perform()" the -> and () can be something completely different than what you expect. There's almost nothing in that simple statement you can be completely sure of.
Re:Linus vs C++, again by NickPollard on Friday June 11, 2010 @05:25AM (#1423305)
They can be, but they shouldn't be. Operator overloading is useful when you want to do something that is semantically similar but implementationally different.

Even mathematics has different processes for the same operators on different types. If you see 'a * b' you should be able to assume that it's multiplying two variables, but if those two are real numbers it's different than if they're two matrices of real numbers, for example.

Implementing a Matrix class that overrides * to imlement matrix multiplication seems perfectly fine for me - It's just the same as implementing a Multiply(a, b) method. Just as someone who writes a Multiply method could in theory make it do anything, it is assumed by reading the word 'Multiply' that that is what it does. Just as someone who makes a Multiply() function that does something other than multiply is an idiot, so is someone who overrides operator * to do something other than multiply.

Re:Linus vs C++, again by wvenable on Friday June 11, 2010 @10:19PM (#1425421)
The STL overrides the bit shifting operators for output and the deference operator for accessing the current item in iterators.
Re:Linus vs C++, again by tptacek on Thursday June 10, 2010 @07:38PM (#1422179)
That's a true and valid argument but beware that any C++ advocate could knock it down by saying "then the kernel code standard should reject things like that".
Re:Linus vs C++, again by varjag on Friday June 11, 2010 @07:04AM (#1423453)
And when you reject things like that you end up with C anyway.
Re:Linus vs C++, again by sanderjd on Friday June 11, 2010 @07:33PM (#1425133)
Meh, this is a straw-man. Conventionally rejecting overridden -> and () operators is a very long reach from ending up back at C. Disallowing operator overriding in general (as opposed to specific operators), namespaces, and classes would be much closer, and it still wouldn't be all that close to C (reinterpret_cast, templates...) There is a goodly sized amount of gray area between the two. Or did you mean your "things like that" to be much broader than my interpretation?
Re:Linus vs C++, again by albertzeyer on Thursday June 10, 2010 @08:47PM (#1422325)
Similar thing with C macros.

(Note that my point here is that for sane/good code, you normally can be sure that it does what it looks like -- for C++ just the same way as for C.)