Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Operator Overoverloading

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-02-22 6:56

Studying part of a large complex middleware for a management web application, and wondering why this:
InitechString str1, str2;
...
if(!(str1 != str2))
{
    ...
}


occurred almost as often as this:
InitechString str1, str2;
...
if(str1 == str2)
{
    ...
}


I dug a little deeper and found...


// CASE-SENSITIVE COMPARISON
//
int InitechString::operator==(const InitechString& r) const
{
    return !strcmp(m_ptr, r.m_ptr);
}
// CASE-NONSESTIVE COMPARISON
//
int InitechString::operator!=(const InitechString& r) const
{
    return !!strcmp(m_ptr, r.m_ptr);
}

Name: Anonymous 2013-02-22 7:08

But it... it doesn't... it isn't case-insensitive!

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-02-22 7:33

>>2
It's (at least) two WTFs in one.

Name: Anonymous 2013-02-22 7:37


Well.. it's weird. I would have written a new operator,
but in C++ you are limited to overload existing ones.

Is still much better that define a CaseSensitiveString class or something just for doing that,

Name: Anonymous 2013-02-22 7:56

>>3
Third WTF is that they use their own string class, which is probably retarded. I mean, they don't compare lengths, right? Which means that they don't store lengths, which means that their appending operator does strlen, strlen, realloc, and then probably strcat instead of memcpy because they are retarded like that.

But at least they deliver ENTERPRISE application written in C++, so it's full of PERFORMANCE.

The worst part is that while your guys are probably Indians and therefore expected do shit like that, I'm working with a codebase which has a similarly retarded string implementation, and that was written by entirely white retards. I mean, there goes a possible heuristic for avoiding code like that.

Name: Anonymous 2013-02-22 8:09

So whats the problem with:
if(lowercase(str1) == lowercase(str2))
{
...
}

?

Name: Anonymous 2013-02-22 8:17

>>6
First of all, it should be uppercase, because of the Turkish letter i.
Second, case-insensitive comparison could be faster because it doesn't need to allocate the entire copy of the string, it should only call upper() for individual characters.

Name: Anonymous 2013-02-22 11:29

>>7
Second, case-insensitive comparison could be faster, because shitload of MICROOPTIMISATIONS PENIS

Yes, you are right and so what? That will never be the bottleneck, unless you are processing natural languages or something. Learn to profile instead of micro optimize.

Name: Anonymous 2013-02-22 11:34

MIDDLEWARE

Name: Anonymous 2013-02-22 12:19

>>8
First of all, back to /r/programming.

Second, premature pessimization is disgusting, and especially disgusting when it's done for no reason at all, as if your only aim is to be pig-slow, even at the cost of decrease in abstraction and readability, as it is in this case.

Name: Anonymous 2013-02-22 12:32

Why are you using strcmp in C++ code?

Name: Anonymous 2013-02-22 13:01

>>10

Have you seen that they have their own shitty string class, which is more of a pessimization than anything else? I really couldn't give a fuck in such a framework about micro optimizations. I would have, if I had a micropenis, but I don't have it. Unfortunately for me, because now I cannot write ENTERPRISE ready code. Have fun micro-optimize your cancer.

Name: Anonymous 2013-02-22 13:03

>>12

:g/cancer/s//code/g

Name: Anonymous 2013-02-22 13:19

Name: Anonymous 2013-02-22 13:20

Name: Anonymous 2013-02-22 15:37

>>14,15
redacted

Name: Anonymous 2013-02-22 15:43

>>7
why are you worrying about the compiler's job?

Name: Anonymous 2013-02-22 21:14

>>3,4
The ultimate WTF is that the C++ allows you to define the operators == and != independently. Anyone who thinks one should not always be the complement of the other is insane.

Name: Anonymous 2013-02-22 21:18

>>18
NaN, faggot.

Name: Anonymous 2013-02-22 21:37

>>19
NaN is a hack to accommodate the way FP hardware works.  If you're overloading operations on a complex type you should just throw if you get a bad operand.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-02-23 0:44

>>5
It does have a length and a bunch of other stuff. They're not using it here though. I don't think the Indian stereotype applies, the bulk of it was written in the early 90s.

>>17
You think the compiler is smart enough to do deep analysis like that? It's not quite as much as expecting it to replace bubblesort with quicksort, but not far either.

>>18-20
The same could be made for <, >, <=, and >=, but then again it's those special cases that people would be bitching about if they didn't let you define all of them separately. (However, shorthand notation for defaulting != to the negation of ==, >= to > || ==, etc. would be welcomed.)

It's funny how no one complains about these features in Perl 6, which lets you change the precedence of overloaded operators. I can manage understanding code that uses nonstandard operator overloading and just barely remember the majority of the template system, but I don't think overloaded operators with varying precedence are within my ability to parse correctly.

Name: Anonymous 2013-02-23 1:28

>>21
The funny thing is that the good way in >>7 is what happens when str1.upper() == str2.upper() is evaluated lazily. But the lazy way isn't always the fastest way. But in any case, I wouldn't expect a seeples compiler to detect the equivalence. It would have to prove all sorts of invariants about the custom string class methods, and I don't see this happening easily. Although it could happen. It would need to statically follow loops, understand the return value of malloc, remember what values were put in what positions in malloced memory...it could be hard...and I would be up to the challenge...if I didn't decide to make a different language...instead.

Name: Anonymous 2013-02-23 3:02

>>22
you forgot the ^^ and XD, retard-kun.

Name: Anonymous 2013-02-23 3:18

>>23
elevated to spaz-kun status xD

Name: Anonymous 2013-02-23 3:55

This is a bit of a serious post in a silly board, but when I see stuff like this I think to myself that I can do decently well in a career in programming.

If people like this have jobs, why can't I? As difficult as it is to judge your own abilities, I've always thought of myself as good as programming.

I don't know a lot of tricks that is common among programmers, but math and logic have always come easy to me. Still, I question whether I can jump into a career. Whether it would be better than continuing my path in Engineering.

It's a very difficult choice for me to make. I love programming, but I understand people get burnt out from it and want to move on quickly.

Name: Anonymous 2013-02-23 4:05

>>25
Whether or not you would enjoy a career in programming is dependant on too many factors that have nothing to do with your ability to program, nor your passion for it. I for one have no qualms with scrubbing a toilet as long as it's a toilet that I want to see clean.

Name: Anonymous 2013-02-23 5:23

>>21

but I don't think overloaded operators with varying precedence are within my ability to parse correctly.

You should try haskell. You will become a human parsing machine. And have a fine understanding of the difference between infixr 5 <=| and infix 2 =*. And love pointless code.

Actually varying precedence are fine as long as you can find the precedence easily in the documentation or through the repl.

Name: Anonymous 2013-02-23 5:35

>>25

Have you ever written PHP? If you love this, nothing will stop you. If you hate it, then move on to something else. The quality code of subhumans, who write PHP, is the average code quality of most projects.

Some QUALITY code:


The usleep() for Windows above doesn't take into account that the value of $stop can be lower than $start. It also contains unnecessary casts and $temp variable. Here is a better function:

function usleepWindows($usec)
{
    $start = gettimeofday();

    do
    {
        $stop = gettimeofday();
        $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
            + $stop['usec'] - $start['usec'];
    }
    while ($timePassed < $usec);
}

http://www.php.net/manual/en/function.usleep.php

This is the standard. This is the norm.

Name: Anonymous 2013-02-23 8:49

>>5
Third WTF is that they use their own string class, which is probably retarded.
It's C++, man. Every newbie invents his own string class and uses it all around his projects.

Name: Anonymous 2013-02-23 16:32

It's C++, man. Every newbie invents his own string class and uses it all around his projects.
No, from where I work it seem that C++ community is somehow becoming somewhat organized and less retarded. I don't know how or why it happens, but, you know, the Channel9 talk where the guys said that cool people pass smart pointers by const reference, it trickles down somehow, for example. Like, people who are in the know feel free to ridicule people who do it wrong, and all bystanders watch and learn and perpetuate our harsh truths.

Name: Anonymous 2013-02-23 16:42

>>30

C++ is emerging. All kind of cool stuff is coming from there. Boost, ZeroMQ, OpenCV and of cource the STL. It is pretty organized and there are more interesting implementations of the compiler besides the gcc suite.

Name: Anonymous 2013-02-23 18:10

It is pretty organized
IHBT

Name: Anonymous 2013-02-23 18:12

C++ is a joke. C is infinitely better in all ways.

Name: Anonymous 2013-02-24 0:26

Name: Anonymous 2013-02-24 2:19

this was an interesting read.

http://www.250bpm.com/blog:7

Name: Anonymous 2013-02-24 2:32

>>34

none of those people have reached c satori ;_;

Name: Anonymous 2013-02-24 3:05

>>35
May I ask a stupid question? Why did he use a double linked linked list in his C example, instead of an array of structures or (if he was so fond of pointers) an ordinary linked list?

Name: Anonymous 2013-02-24 3:20

>>37
'cause GNU

Name: Anonymous 2013-02-24 3:39

why dont c plus plus support include overloading like #include <eeyoeeyoeeyostreemeeyoeeyoeeyoyoyo>?

Name: Anonymous 2013-02-24 4:05

>>39
It's on the list for MSVC 2014

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-02-24 6:31

>>34
That's a problem with the programmer/education, not the language.

template class dllist<typename T> {
 struct dllist<T> *prev;
 struct dllist<T> *next;
};

class person : public dllist<person> {
 int age;
 int weight;
};

Name: Anonymous 2013-02-24 6:36

>>34
That blog post was shot down pretty hard in the comments.

Name: Anonymous 2013-02-24 7:27

>>41
That gets what's desired in this case, and it's concise, but you no longer have the ability to have a person without the linked list node embedded in. That's what disappointed me about their use of C in the blog, and the in the comments.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-02-24 7:38

>>42
What comments?

Name: Anonymous 2013-02-24 7:59

>>41
I dislike C++: it is too verbose, complicated and obfuscated:

Symta:
<Age:|Weight:>

C/C++:

template class dllist<typename T> {
 struct dllist<T> *prev;
 struct dllist<T> *next;
};

class person : public dllist<person> {
 int age;
 int weight;
};

Name: Anonymous 2013-02-24 8:03

>>44
The comments for the blog post.

Name: Anonymous 2013-02-24 8:11

>>45
is it an associative array? python, php, js etc dinamic crap can create it in a similar way

Name: Anonymous 2013-02-24 8:37

>>47
No. It's lambda.

Name: Anonymous 2013-02-24 10:58

>>45
I LOVE YOU, NIKITA

PLEASE DOCUMENT SYMTA

Name: Anonymous 2013-02-24 12:43

>>49
Talk is cheap. Show me the code. -- Linus Torvalds

Name: Anonymous 2013-02-24 13:10

Whores are cheap. Show me your anus. -- Terry Pratchett

Don't change these.
Name: Email:
Entire Thread Thread List