LWN.net Logo

GCC 4.6.0 released

GCC 4.6.0 released

Posted Mar 29, 2011 1:05 UTC (Tue) by mtall12 (guest, #73924)
In reply to: GCC 4.6.0 released by cmccabe
Parent article: GCC 4.6.0 released

    Frankly, I think operator overloading is confusing and ugly. It's a Perl-style "let's save 5 seconds of typing now, but spend 50 minutes scratching our heads a few months later over what this code REALLY does."

Sorry, that's a non-argument. Using the same logic I could say that using the "traditional" function call of foo(a,b) is confusing and ugly, because I'll need to spend 50 minutes deciphering what foo() does.

Operator overloading is a very useful shorthand for function calls that can make the code far more readable and hence easier to maintain (translation: less bugs). This is especially true when writing scientific applications (though certainly not limited to them). With a decent matrix library (eg. Armadillo or ITPP), C++ allows things like:

    matrix A, B, C, D;
    A = (0.1*B + C) * D;
while in Java you have to resort to:
    A = B;
    A.scalar_multiply(0.1);
    A.add(C);
    A.matrix_multiply(D);
or
    A = matrix_multiply(add(scalar_multiply(0.1, B), C), D);
Now imagine the above style for a far more complicated expression.

Let's also not forget that through C++ templates one can implement expression optimization, where operations like (0.1*B + C) can be turned into one loop, thereby providing execution speeds generally not doable in Java (ie. without specialized functions).


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds