SRL Archive - NOTA

Wizzup's ego


Brandon

2014-05-24 21:37:02

Wizzup's ego gets in the way a lot. According to Wizzup in IRC, C++ is weaker than C; it is evil; it is hard, it is bad. It is worse than Pascal and Go-Lang.

I disagree with him, he bans me from IRC.

What I said to him:

YOU find the language hard because YOU lack the skill in it. Doesn't make the LANGUAGE itself hard or bad or evil.


He says HARD is objective and not subjective. No it is subjective. We find something hard because we don't know it that well. Simple. We find math or guitar or physics or whatever it is, hard because we don't know it quite well or as well as we would like. Someone skilled in math will not say it is hard. It's a discipline and takes time and effort and practice to learn. Apparently, my guitar analogy went over his head and is irrelevant because it has nothing to do with languages.

He replies:

It is bloated.


No C++ is not bloated unless YOU make it bloated. The same code that is written in C to accomplish what can be done in C++ would be just as bloated and he doesn't understand that. C++ compile pure C code if you wish as well.

I tell him that a sort function in C++ will out perform a sort function in C quite easily. His response:

glibC


Let me prove that wrong right now. For the 1 millionth time.

Take for example a sort function in C:


bool IntComparator(void* a, void* b)
{
return *((int*)(a)) < *((int*)(b));
}

bool CharComparator(void* a, void* b)
{
return *((char*)(a)) < *((char*)(a));
}

bool FloatComparator(void* a, void* b)
{
return *((float*)(a)) < *((float*)(b));
}

//function for swapping every single byte of a specified type.
void ByteSwap(uint8_t* a, uint8_t* b, size_t size_ptr)
{
int i;
uint8_t t = 0;
for (i = 0; i < size_ptr; ++i)
{
t = a[i];
a[i] = b[i];
b[i] = t;
}
}

//Sort function taking comparators
void Sort(uint8_t* list, size_t length, size_t size_ptr, bool (*comparator)(void* a, void* b))
{
int size = length * size_ptr;
size_t i, j;

for (i = 0; i < size; i += size_ptr)
{
for (j = 0; j < size - i - size_ptr; j += size_ptr)
{
if (comparator(&list[j + size_ptr], &list[j]))
{
ByteSwap(&list[j + size_ptr], &list[j], size_ptr);
}
}
}
}

int main()
{
}

Notice all the comparator functions you have to write and one is required for EVERY single type you want to sort. Each of these if not inlined has an overhead of preserving the stack and dereferencing a bunch of pointers. Not to mention a function call every loop.

The assembly generated WITH gcc-4.8 -O2 optimisations and -masm=intel (and an empty main):

IntComparator(void*, void*):
mov eax, DWORD PTR [rsi]
cmp DWORD PTR [rdi], eax
setl al
ret
CharComparator(void*, void*):
xor eax, eax
ret
FloatComparator(void*, void*):
movss xmm0, DWORD PTR [rsi]
ucomiss xmm0, DWORD PTR [rdi]
seta al
ret
ByteSwap(unsigned char*, unsigned char*, unsigned int):
xor eax, eax
test edx, edx
je .L4
.L8:
movzx ecx, BYTE PTR [rdi+rax]
movzx r8d, BYTE PTR [rsi+rax]
mov BYTE PTR [rdi+rax], r8b
mov BYTE PTR [rsi+rax], cl
add rax, 1
cmp edx, eax
ja .L8
.L4:
rep; ret
Sort(unsigned char*, unsigned int, unsigned int, bool (*)(void*, void*)):
push r15
mov eax, esi
imul eax, edx
push r14
mov r14d, edx
push r13
push r12
push rbp
push rbx
sub rsp, 24
test eax, eax
mov DWORD PTR [rsp+12], eax
je .L10
sub eax, edx
mov rbx, rdi
mov r12, rcx
mov DWORD PTR [rsp+4], eax
mov DWORD PTR [rsp+8], edx
.L12:
xor r13d, r13d
.L18:
cmp r13d, DWORD PTR [rsp+4]
jae .L26
.L17:
mov r15d, r13d
add r13d, r14d
mov ecx, r13d
add r15, rbx
lea rbp, [rbx+rcx]
mov rsi, r15
mov rdi, rbp
call r12
test al, al
je .L18
test r14d, r14d
je .L18
xor eax, eax
.L16:
movzx esi, BYTE PTR [rbp+0+rax]
movzx edi, BYTE PTR [r15+rax]
mov BYTE PTR [rbp+0+rax], dil
mov BYTE PTR [r15+rax], sil
add rax, 1
cmp r14d, eax
ja .L16
cmp r13d, DWORD PTR [rsp+4]
jb .L17
.L26:
mov edx, DWORD PTR [rsp+8]
sub DWORD PTR [rsp+4], r14d
mov eax, edx
add eax, r14d
cmp DWORD PTR [rsp+12], edx
jbe .L10
mov DWORD PTR [rsp+8], eax
jmp .L12
.L10:
add rsp, 24
pop rbx
pop rbp
pop r12
pop r13
pop r14
pop r15
ret
main:
xor eax, eax
ret

Now consider the same sort function in C++:

template<typename T, bool low_to_high>
void Sort(T* x, size_t size)
{
for (size_t i = 0; i < size - 1; ++i)
{
for (size_t j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
T temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

int main()
{
}

Assembly generated using g++-4.8 -O2 optimisations and -masm=intel (and an empty main):

main:
xor eax, eax
ret


OH? Wth? Unfair you say? Fine.. lets use the function and give C a small advantage (C++ compiler optimises out the unused functions unlike C's):


int main()
{
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Sort<int, true>(&arr[0], 10);

printf("%d", arr[0]);
}

Assembly generated with g++-4.8 -O2 optimisations and -masm=intel:

.LC0:
.string "%d"
main:
sub rsp, 56
mov r8d, 9
mov DWORD PTR [rsp], 1
mov DWORD PTR [rsp+4], 2
mov DWORD PTR [rsp+8], 3
mov DWORD PTR [rsp+12], 4
mov DWORD PTR [rsp+16], 5
mov DWORD PTR [rsp+20], 6
mov DWORD PTR [rsp+24], 7
mov DWORD PTR [rsp+28], 8
mov DWORD PTR [rsp+32], 9
mov DWORD PTR [rsp+36], 10
.L2:
mov rdx, rsp
xor eax, eax
jmp .L6
.L4:
add eax, 1
mov esi, DWORD PTR [rdx]
mov ecx, eax
lea rcx, [rsp+rcx*4]
mov edi, DWORD PTR [rcx]
cmp esi, edi
jle .L3
mov DWORD PTR [rdx], edi
mov DWORD PTR [rcx], esi
.L3:
add rdx, 4
.L6:
cmp eax, r8d
jne .L4
sub eax, 1
mov r8d, eax
jne .L2
mov edx, DWORD PTR [rsp]
mov esi, OFFSET FLAT:.LC0
mov edi, 1
xor eax, eax
call __printf_chk
xor eax, eax
add rsp, 56
ret


Guess what? The C++ version has no overhead compared to the C version AND it requires no comparator functions. In fact, since the sort function is generated at compile time in C++, that inner branch for tenary operator is optimised out (the operator used for determining whether to sort in ascending or descending order within the if statement). Doing this in C requires that you write a whole other comparator function to sort in ascending and descending order. Again, LESS code, LESS bloat, faster calculations, inlined and its generic. I'd easily rub it in Wizzup's face but I'm not that kind of person. I'll leave the high ego alone.

Lets take a look at the power of templates.. Something that can NEVER be done in C:


template<std::int64_t number>
struct is_perfect_square
{
private:
static inline constexpr bool is_perfect(std::size_t sq = 0)
{
return (sq * sq == number) || ((sq * sq < number) && is_perfect(sq + 1));
}

public:
enum {value = is_perfect()};
};

template<std::int64_t number>
struct is_perfect_cube
{
private:
static inline constexpr bool is_perfect(std::size_t cb = 0)
{
return (cb * cb * cb == number) || ((cb * cb * cb < number) && is_perfect(cb + 1));
}

public:
enum {value = is_perfect()};
};

template<std::int64_t number, std::int64_t exp>
struct is_perfect_n
{
private:
static inline constexpr std::int64_t cpow(std::int64_t base, std::int64_t exponent)
{
return exponent ? base * cpow(base, exponent - 1) : 1;
}

static inline constexpr bool is_perfect(std::size_t n = 0)
{
return (cpow(n, exp) == number) || ((cpow(n, exp) < number) && is_perfect(n + 1));
}

public:
enum {value = is_perfect()};
};

template<std::int64_t T>
struct is_prime
{
private:
static constexpr std::int64_t compute(std::int64_t Num, std::int64_t I = 2)
{
return I * I > Num ? true : Num % I ? compute(Num, I + 1) : false;
}

public:
enum {value = compute(T)};
};

template<std::int64_t number>
struct Factorial
{
private:
static constexpr std::int64_t compute(std::int64_t num)
{
return num ? num * compute(num - 1) : 1;
}

public:
enum {value = compute(number)};
};

template<std::int64_t T, std::int64_t U>
struct concatenate_integral
{
template<std::int64_t Limit, std::int64_t Num = 1, bool Cond = false>
struct calc_power
{
const static std::int64_t value = calc_power<Limit, Num * 0xA, (Num > Limit)>::value;
};

template<std::int64_t Limit, std::int64_t Num>
struct calc_power<Limit, Num, true>
{
const static std::int64_t value = Num / 0xA;
};

enum {value = T * calc_power<U>::value + U};
};

template<std::int64_t T, std::int64_t U>
struct GCF
{
private:
static constexpr std::int64_t compute(std::int64_t X, std::int64_t Y)
{
return Y ? compute(Y, X % Y) : X;
}

public:
enum {value = compute(T, U)};
};

template<std::int64_t T, std::int64_t U>
struct LCM
{
enum {value = T * U / GCF<T, U>::value};
};


What is that? Oh yeah that's right.. COMPILE-TIME math.. What does this mean? The code above has ZERO overhead. ALL the results can be calculated at COMPILE-TIME. This can NEVER be done in C. This sort of optimisation is what the Eigen Math library is based off of. If done in C, the above will have the RUN-TIME overhead of a function call AND the calculations. Transposing matrices, any sort of intense calculations can have a lot of its overheads removed at compile-time in C++.


Wizzup seems to disagree. I call it a lack of skill. He takes an offence to anyone calling out his skills. So I said he's emotionally unstabled for taking offence to me calling out his skill and comparing his argument to the Linus Torvald's. I don't care about this alpha male crap. Can keep spewing this crap and myths about any language and how much he knows. Facts live on.

What makes a language hard?

Lack of skill and practice and time for practice. Some languages take more TIME to learn than others but does that make another language BAD, evil, hard? No. Certain concepts will take more time to learn because it may not exist in another language or it is just difficult for that specific individual. None of this make the LANGUAGE bad, hard or evil.

What makes it hard is the lack of effort, practice and ultimately skill in said language. Wizzup does NOT seem to understand this. It is hard and bad and evil because he said so and he knows all. This is the same argument Linus Torvald had. Except he had more valid points than Wizzup.

He said I'm assaulting him, I'm hurtful, I'm obnoxious, I'm aggressive. No I'm simply stating facts. The LANGUAGE isn't hard.

If you want to say STL is bloated, that's fine but you don't have to use STL; but you lose out on quite a bit unless you roll your own (which by the way you have to do in C anyway). Anything you can do in C, you can do in C++ and more. C++ isn't just object-oriented, it is a multi-paradigm, procedural, function, object-oriented and generic language. C is just procedural and structured.

I'm going to say this once. There is a reason games use C++ and not C. Speed of templates, allocators, and aggressive optimisations by the compiler as well as LESS code. Not to mention the time it takes to write said code.

Now I'm not bashing C because I write C and Assembly all day every day for a living along with Objective-C and Java; I am however saying that it is in no way "SUPERIOR" to any other language out there. Neither is pascal, neither is go-lang.

If you find any language hard, you don't lack the intelligence, you lack practice and time to learn said language.

Right now, I don't care if Wizzup takes offence to this or bans me. I'm already banned from IRC. This egotistical, "I know all" attitude is sickening. I might finally understand what some others that left villavu was talking about.

To say Java is harder than C# is stupid because it isn't. One takes more time and effort than the other but neither is harder than the other. How hard a language is, is simply opinion!

Ban me from IRC and villavu to show off your ego, I don't care. I don't play RS, I code to help other.

Clarity

2014-05-24 22:14:24

I have no useful programming ideas to contribute but this topic makes me go :(
Hope things get resolved!

[XoL]

2014-05-24 22:24:09

Me too :(

Brandon

2014-05-24 22:34:34

Meh. I'm not "mad" at him at all. I'm just hate "alpha male", "I'm better than you", "I know all" attitudes.

The assembly and everything else above says otherwise. Banning me from IRC was uncalled for just because he didn't like what I said. The assembly is there and it doesn't lie.

Still. I like all of you guys. I'll just do my thing as usual and simply stay away from him.

It's okay if you guys cannot contribute. Some scripts would be nice though :)

Flight

2014-05-24 22:42:57

After reading the first part of this thread (I stopped when the code began) I can see you make a good point of logic Brandon. Keeping in mind I also have no knowledge of either of the two languages but I understand where you're coming from for saying this and I agree with you, it wouldn't be fair to classify a language based on if one only has so much knowledge in it. No disrespect to Wizzup, at all, but if this is really what happened then I do agree with you, Brandon.

Ian

2014-05-24 22:43:49

From: Brandon

It's okay if you guys cannot contribute. Some scripts would be nice though :)


Hopefully a Jewellery Crafter in the near future. It's very stable and crafts all F2P jewellery, but I'm using this so hopefully that will be ready for the updater soon. The new tesseract plugin is working well :)

Kasi

2014-05-24 22:43:53

I don't think @Wizzup?; will ban you, if he does, his reputation will surely fall, as well as his ego.

I've known Brandon for a long time and I find it to be pretty unbelievable that the "SRL-Leader" is using such insults at a fellow user (Who might have looked up to you). Brandon is not hurtful, obnoxious or aggressive. Anyone who insults based on opinions towards none-aggressive entities such as a programming language shows one thing; poor attitude.

Regardless of whatever opinion you have of a language I doubt insults are going to change that. Nor does flexing your power based on your own ego. I'm sorry but you do not ban people based on how big of an ego you have.

@Brandon; Not really liking this situation but if people don't want to learn, don't teach them / educate them. I also don't think you should let one user's brief problematic attitude push you to leave Villavu.

TLDR; Insults are bad, abusing power based on ego is bad, debating is good.

Turpinator

2014-05-25 01:11:36

[video=youtube;l2hqzEKbaIQ]http://www.youtube.com/watch?v=l2hqzEKbaIQ[/video]

Nebula

2014-05-25 03:00:32

wtf did i just read?

phaggot programming nerds arguing over which language is better or something i think. who writes ~150 lines of code and a huge wall of text about a language that over 99.99% of the population doesnt care about just so you can prove a point to the .01% who still probably doesnt care about your opinion and is an admin so he can just ban you if you argue with him. Oh c++ is better than java? get banned son GG don't ever talk shyt about java

+reps to anyone who knows what this even means :


.L8:
movzx ecx, BYTE PTR [rdi+rax]
movzx r8d, BYTE PTR [rsi+rax]
mov BYTE PTR [rdi+rax], r8b
mov BYTE PTR [rsi+rax], cl
add rax, 1
cmp edx, eax
ja .L8

Brandon

2014-05-25 03:08:01

From: Nebula
wtf did i just read?

phaggot programming nerds arguing over which language is better or something i think. who writes ~150 lines of code and a huge wall of text about a language that over 99.99% of the population doesnt care about just so you can prove a point to the .01% who still probably doesnt care about your opinion and is an admin so he can just ban you if you argue with him. Oh c++ is better than java? get banned son GG don't ever talk shyt about java

+reps to anyone who knows what this even means




You amaze me sometimes. I'm openly straight. Not gay/homosexual thanks. No one ever said anything is better than Java. I said NEITHER is better than the other and NEITHER is bad. Secondly.. 99% of the population what? I think you might want to take a look at google codejam statistics and the facebook hackers cup competitions:

http://www.go-hero.net/jam/14/languages

Guess which languages is the most used? But this is NOTA so you can say whatever you like and I don't blame you if you do. Again, no one cares and yes it is to prove a point that the admin has no idea what they are talking about but shoves their ego in the way. But if you don't care, why exactly did you click the thread link? Because curiosity got you and you cared ever so slightly to read it to know that straight nerd programmers are arguing.


And yes I understand that weird nerdy code called assembly. I am going to +1 you though because I laughed out loud while reading it. Especially the pluses part.

Nebula

2014-05-25 03:08:33

in my opinion , c++ seems like the clear winner here. it wouldn't make sense for c to be better than c++, how can something double plus be worse than something with no plusses? thats like saying zero is greater than a really big positive number. can you even math/logic/common sense wizup?

Wizzup?

2014-05-25 06:04:38

Wow. Really? *Sigh*. This is such a waste of all our time.

First of all, here's a log of the entire conversation: http://wizzup.org/ggzz.txt
Why did you not provide everyone with this? That saves everyone from a lot of
your slander and intentional misrepresentations / defamations. It's very
childish to take things out of context, phrase them differently only to
"win" your case. The truth is that you're in fact hurting everyone by
providing everyone with false information.


The discussion very quickly turns into a mostly one sided flame fest, where I
try to tell ggzz that his flaming doesn't add anything to the discussion and his
arguments have little relevance. He doesn't like this and continues for the next
50 minutes that follow.

I can stand a lot of online abuse, but this was just silly. I'm not going to
argue on technical grounds - as I also state in the log, because ggzz is acting
really offensive and presents a one sided view, and then continues to present a
very narrow part of the argument where he thinks he can "win", thus trying to
declare the whole argument a "win".

Truth be told, I really don't care that you think that you're right and than I
am wrong. I already lost all hope on having a meaningful discussing with you.

Did you even see how you're starting your post?

"Wizzup's ego gets in the way a lot".

What kind of way to have any meaningful discussion is that? You immediately
enforce your own view on the reader, in a very forceful and offensive way. Force
may work for you in a narrow part of your life, but it's not going to work here.

What I care about is pointing out how overly aggressive you really are, trying
so very hard to pull the entire argument, case, "win", etc in your favour.
You're not even remotely trying to have a discussion, you're just trying to
win an argument. After I temporarily removed you from the channel, we have a
nice discussion with about five or six people about the same topic, with no
problems.

Your post on the forums only reinforces my view that you're zealous about this
and don't stop to listen to others, but continue to push your view and also
continually keep attacking them. You're reflecting many of the things that
really concern yourself on me.

Really, I'm sure quite a few people are shocked by the way you present your
"case", you continue to rage on, again completely miss the points I made
previously, and you're very much stuck in your own view and don't even attempt
to look at what others are saying.

Take a step back, and have a more unbiased look of the discussion.

I don't have such a huge ego, I don't have emotional problems, I am not
emotionally unstable, I can program C++ quite well, I have no problems admitting
that I am wrong and I am not in denial. To "counter" just a few things you
accused me of in your rage. I have in fact grown a lot emotionally and
empathically in the last years. But you are really not the person to tell me who
I am and what I am like. That's way out of line, hurtful, and in this case, just
plain wrong.

I invite everyone to look at the full log and draw their own conclusions if
they want. I won't be telling you what to think, you can draw your own
conclusions.

I gracefully decline to discuss this with you any further.
The way you discuss is tiresome, painful and non-constructive.

I try to be nice to as many people as I can, I try to be very helpful to them
and I've found that your kind of behaviour is terrible for communities in
general. As for my "ego", from the way you discuss you probably make my ego
look very tiny… :


It's okay if you guys cannot contribute.
I'd easily rub it in Wizzup's face but I'm not that kind of person. I'll leave the high ego alone.

P1nky

2014-05-25 06:14:51

Just let him back into the IRC, and never discuss/argue about this in the future. Les' keep it professional now Mates.

Wizzup?

2014-05-25 06:19:20

From: Kasi
I don't think @Wizzup?; will ban you, if he does, his reputation will surely fall, as well as his ego.

I've known Brandon for a long time and I find it to be pretty unbelievable that the "SRL-Leader" is using such insults at a fellow user (Who might have looked up to you). Brandon is not hurtful, obnoxious or aggressive. Anyone who insults based on opinions towards none-aggressive entities such as a programming language shows one thing; poor attitude.

Regardless of whatever opinion you have of a language I doubt insults are going to change that. Nor does flexing your power based on your own ego. I'm sorry but you do not ban people based on how big of an ego you have.

@Brandon; Not really liking this situation but if people don't want to learn, don't teach them / educate them. I also don't think you should let one user's brief problematic attitude push you to leave Villavu.

TLDR; Insults are bad, abusing power based on ego is bad, debating is good.


Find the log of the conversation in the previous post, and draw your own
conclusions. You're drawing your conclusions purely based on a very one
sided argument presented by Brandon/ggzz. If you want to have a meaningful
discussion and opinion, I suggest you have a look at both sides. In the
very final sentence I call him obnoxious, because that is really what
he was in the last 40+ minutes of the discussion.

masterBB

2014-05-25 06:20:21

Just picking out the highlights:
02:02 < Olly`> JUST SHUT UP AND ADD FindColorsArray(cols, tols: TIntegerArray);

02:05 <@Wizzup> What is the point you are trying to make here?
02:05 < Olly`> fight
02:05 <@Wizzup> I just don't get it
02:05 < ggzz> you're trying to say its a bad langauge.. you just don't know it well
02:05 <@Dgby714> .k Olly` no
02:05 -!- Olly` was kicked from #Simba by Sexy [no]
02:05 < ggzz> simple

02:11 < ggzz> Go lang is useless
02:11 <@Wizzup> - ggzz, 2014

02:17 < ggzz> C, this, Pascal taht, C++ evil
02:17 < Olly`> yea fuck linux!

02:43 < ggzz> he's in denial
02:43 < Olly`> the standoff is real
02:44 < Olly`> who will win? stay tuned in

02:49 <@Wizzup> This is really pathetic.
02:49 <@Wizzup> Olly`: Can you start shouting how Simba bugs need fixing intead?
02:49 <@Wizzup> That's better for all of us, I think

03:01 -!- ggzz was kicked from #Simba by Wizzup [ggzz]
03:01 < Olly`> lol

On a more serious note. Both of you guys are impossible to have discussion with. But wizzup, I do think you sometimes get a bit aggresive during these discusions. Oh well, this is useless. Why can't we all have our own preferences. C++ is a great language if you need a lot of power/controll, especially on windows the development is really nice. C and objective C are not used on any of the profesional projects I've worked with so far. Pascal, Go, java, C# etc etc are all great languages if someone wants a program and they want it this month ;)

CynicRus

2014-05-25 06:45:23

Just from reading the code templates in C + + can be broken eyes and brain.-)

Rich

2014-05-25 07:22:29

I'm not going to read the log because I don't really care. My opinion? Everyone should just get over it and move on. There was a disagreement, big deal?

Hoodz

2014-05-25 08:40:17

From: Rich
I'm not going to read the log because I don't really care. My opinion? Everyone should just get over it and move on. There was a disagreement, big deal?

My words

Gu3st...

2014-05-25 08:44:20

Thank you, @Wizzup?; for bringing the entire conversation to the topic. I was kind of expecting you to do so as well, so I skipped the entire first post and will first draw my own conclusions from the IRC conversation before reading the opening post.

A short summary of the whole IRC convo:
02:14 < ggzz> because you complain all day long "omg.. c++ so hard.. "
02:14 <@Wizzup> Yes, it's hard. Doesn't mean I cannot handle it
02:14 < ggzz> if you knew it well, it won't be hard
02:14 <@Wizzup> You keep making it personal


Brandon tries unsuccessfully to propose that C++ is not a bad language even though it is overly complex and hard to master, he wants Wizzup? to look at C++ using that proposition and he tries to force Wizzup? to do so using personal attacks. Wizzup?, on the other hand, is giving no flying fucks about getting angry over such a discussion and so he keeps his calm which in turn makes Brandon frustrated.
Discussion escalates and Brandon misinterprets Wissup?'s calm as him being uninformed about the whole topic of the discussion.

@Brandon; You need to be more clear when discussing with Wizzup?. Wizzup is a very literal person and you have to be clear at where you stand and what it is you're trying to discuss. If you want (for example) to discuss whenever C++ is a bad language, despite the complexity and how hard it is to master, then just say so. Tell him "Look at C++ without looking at it's complexity and how hard it is to master; is it still an evil language?". I assure you, if you keep your calm and ask him maturely, then you'll most likely receive a calm and mature reply.
It seems like the question you asked Wizzup? initially was wrong. You asked whether it was a bad language (subjectivity) and assumed the answer to be based on objectivity.

@Wizzup?; You shouldn't have banned him for such a tiny discussion, but then again, he put himself in that position so I don't blame you.

And now onto the opening post in this topic: Here we see Brandon objectively show how C++ is good and what great things you can create with it. This doesn't compare to the question asked on IRC, as that was a question of subjectivity.
Looking at Wizzup?'s post in this thread, he seems to, yet again, be calm and mature about this discussion, but answers the personal attacks on IRC with some personal attacks of his own. The difference between the personal attacks on the IRC and the ones in this thread is that the first one were simply flaming, whereas the response in this thread is merely a counter-attack in order to prevent flaming in the future.


So, to specify: When discussing, be clear.
Can we close this thread now?

Kasi

2014-05-25 11:47:49

From: Wizzup?
Find the log of the conversation in the previous post, and draw your own
conclusions. You're drawing your conclusions purely based on a very one
sided argument presented by Brandon/ggzz. If you want to have a meaningful
discussion and opinion, I suggest you have a look at both sides. In the
very final sentence I call him obnoxious, because that is really what
he was in the last 40+ minutes of the discussion.


I have just read the entire log. There were errors on both sides, However my original post still stands. No need for insults.

Brandon

2014-05-25 11:51:49

From: Zyt3x

Looking at Wizzup?'s post in this thread, he seems to, yet again, be calm and mature about this discussion



I don't call this calm:

@wizzup> Like, the fucking definition of personal.
@wizzup> This is really pathetic.
@wizzup> And see how fucking stupid that is to say
< ggzz> YOU find it hard. YOU find it bad. YOU find problems with it
< ggzz> that's fine by me. Spend your time sleeping. YOu haven't brought anything to the table anyway other than opinions on why
it is bad and bloated.
@wizzup> You're fucking obnoxious as a person. And you think you're good at discussions. Let me tell you, you fucking suck at
it. And that is a personal attack, and I'm leaving it at that.
< ggzz> you're egotistical
* Wizzup facepalms
< ggzz> you should do that harder
-!- ggzz was kicked from #Simba by Wizzup [ggzz]




Wizzup I didn't purposely leave out the log. I'm not "pro" at IRC or MIRC like you are. It's not like I use IRC every single day all day long. No, I've recently started coming on. Secondly, EVERYTHING I did say that YOU found offensive, I kept in the first post. As far as I could remember. You call me offensive? Take a look in the mirror. Read the conversation again.

Just like I said in my Original Post: Your argument is exactly like Linus's. YOU lack the skill. You're emotionally unstable.

There is NOTHING more that I have said to you or attacked you with according to YOUR logs. If calling out your skill hurts your ego, don't argue.

I've lost many arguments with DGBY. I've argued with Benland100 quite sensibly on IRC and guess who lost? ME! It has NOTHING to do with winning the argument. I've lost every argument I ever had with Benland100. If you think I'm kidding, see the Windows vs. Linux argument and the VIM vs Notepad++ argument and the many others privacy vs spying. Each and every one lost (as if anyone was trying to win).

You have the logs because you were there. If it was about winning, I wouldn't lose in that case because like you, I'd be in denial and deny ever losing. You know why Benland is good at arguing? Because he has facts. He has logic, he has what you don't have. PROOF. He has skill. To say the language is hard and be so difficult about accepting that you lack is not my problem. I'm stating that you are wrong right now and in my post. I had nothing to hide when I posted this thread.

I've quoted everything that you called offensive below in red. If you want to talk about keeping it calm and respectful, let's see through the entire conversation who starts cursing at who. I'm sorry but I don't have a filthy mouth.

Secondly, the first thing you try to do is establish your ego by stating that you teach and have insane experience. Please.. I teach as well. The assembly and links were given to you. Many times in the chat I gave you links. You know what you gave me? NOTHING. Lol.

Everything in red is what you found offensive. Everything NOT in red is what I said leading up to.

< ggzz> you're trying to say its a bad langauge.. you just don't know it well
< ggzz> its the user that is bad
< ggzz> or developer
< ggzz> Wizzup.. don't live in the past.. C89. Seriously?
@wizzup> What's wrong with portability?
< ggzz> ^THis argument is the same crap Java devs pull
< ggzz> There is nothing non-portable about C99
< ggzz> C++ is too complex and has way too many ways to achieve the same thing. Complex for who?
@wizzup> Everyone who thinks they understand C++ really don't
< ggzz> It might be MORE clear for YOU wizzup
< ggzz> doesn't make C++ bad because it isn't clear for YOU

* Wizzup has been teaching C and other languages to students for years
@wizzup> but I'm sure you have much more teaching experience
* ggzz has been teaching Assembly, C and C++ for years

< ggzz> what's your point

@wizzup> My point is that C++ is overly complex and sucks donkey balls.
@wizzup> And you tell me that I don't understand how complex it really is
< ggzz> and my point is that it is your opinion because you don't understand it

< ggzz> but you are proving my point.. It isn't a bad language because YOU don't know it
< ggzz> it is bad because you suck at using it
< ggzz> because you complain all day long "omg.. c++ so hard.. "

< ggzz> No. You're sounding like Linus
< ggzz> it is complexed due to your skill

< ggzz> yes it is dgby, you are right there. But just because pascal is easier, does that make C++ bad?

* Wizzup gives up on ggzz - He doesn't listen to what I say and keep repeating personal attacks

< ggzz> I'm offensive how?
< ggzz> I simply state that the complexity of the language depends on your skill
< ggzz> you take offense when anyone calls you out


< ggzz> You say a language is bad because another is easier
< ggzz> Your skill IS lacking if you consider it so horrendous and "hard"

< ggzz> You think I depise linus? No.. I despise his silly argument

@wizzup> I don't give a flying fuck about Linus.

< ggzz> If you work on guitar for years, playing it won't be hard
< ggzz> if you just start, it's hard as hell
< ggzz> subjective
< ggzz> Wizzup. Because the language is hard for "many" or "whoever" does NOT mean it is a BAD language'

@wizzup> The actual 'bad' part of C++ is the bloat of features that don't mix well, the overly complex features that it has, etc.
< ggzz> Oh please.. bloat?
@wizzup> yes. bloat.


< ggzz> lol you're the one that siad C is less bloat
< ggzz> but can't back it up
< ggzz> tell me how it is less bloat
@wizzup> C++ generates more complex code, links in more crap, uses more ram by design
@wizzup> either you compare/swap pointers with a cmp function, or you generate lots of code


< ggzz> gotta love all those comparator functions, those beautiful swapping of every single byte
* Wizzup points ggzz and glibc
@wizzup> You're jumping around with baseless and meaningless arguments/points that do not relate to the actual discussion
< ggzz> sure.. no one knows anything to almighty god wizzup


< ggzz> If you call "Your argument is like Linus'" an attack then you have some serious emotional issues

@wizzup> I am fine emotionally, thanks, very stable too, I just had a lot of discussions with people and I've identified you as
overly agressive and as someone who stops thinking when in an argument
< ggzz> right.. I stop thinking when I tell you your skill in C++ is bad


< ggzz> very sensitive
< ggzz> hates when anyone tells you you're bad

Thanatos

2014-05-25 11:58:43

Brandon, I believe what Wizzup found offensive was the tone that seems to be placed behind what you've stated. Whether you meant to be offensive or not it does come off as being so. However, I do acknowledge that this whole situation could be handled better on both sides. It seems to be turning into a flame fest.

Frement

2014-05-25 12:08:41

I read the logs yesterday, and now reading all the new posts, I don't even know what to say. Get a room or get along.

Dgby714

2014-05-25 12:16:12

Woo, I was mentioned =)

Anyways, Don't really have anything to add except that the examples in the first post are skewed.

Brandon

2014-05-25 12:25:45

From: Dgby714
Woo, I was mentioned =)

Anyways, Don't really have anything to add except that the examples in the first post are skewed.



The code? How so? It is the exact equivalent C code of that of the C++ example. It is the argument we were having in IRC when I gave him the stackoverflow link which was "irrelevant".

The examples isn't in any way skewed. They are compiled with the same flags and same compiler. Both on the same 64-bit system with the same optimisations. They are equivalent. In fact, the C++ example actually uses the sort and still has less code that the C example which doesn't. You can stick this in any compiler and see for yourself what is generated. The example is to prove that it depends on how you use the language. The language itself isn't bloat in any way. A language is just a tool. It is one of many examples of where C++ is better than C.

As for the templates, it was done to show the power of them over C. It was done to show that the fallacy of "templates are bloated" is just that; a fallacy. It depends on its usage and the developer. As stated, anything that can be done in C can be done in C++.


Lets give C an even larger advantage shall we?


int main()
{
int arr[] = {1, 2, 3, 4, 8, 2, 1, 8, 9, 10};
float arr2[] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 2.0f, 1.0f, 9.0f, 10.0f, 2.0f};
double arr3[] = {1.0d, 2.0d, 3.0d, 4.0d, 5.0d, 2.0d, 1.0d, 9.0d, 10.0d, 11.0f};

Sort<int, true>(&arr[0], 10);
Sort<float, true>(&arr2[0], 10);
Sort<double, true>(&arr3[0], 10);

for (int i = 0; i < 10; ++i)
printf("%d", arr[i]);

for (int i = 0; i < 10; ++i)
printf("%f", arr2[i]);

for (int i = 0; i < 10; ++i)
printf("%f", arr3[i]);
}


.LC8:
.string "%d"
main:
push rbp
mov edx, 1
push rbx
sub rsp, 72
movsd xmm1, QWORD PTR .LC1[rip]
lea rbx, [rsp+4]
lea rbp, [rsp+16]
movsd xmm2, QWORD PTR .LC5[rip]
mov DWORD PTR [rsp], 1
movsd xmm3, QWORD PTR .LC6[rip]
mov DWORD PTR [rsp+4], 2
movsd xmm4, QWORD PTR .LC7[rip]
mov DWORD PTR [rsp+8], 8
movsd QWORD PTR [rsp+32], xmm1
mov DWORD PTR [rsp+12], 7
mov DWORD PTR [rsp+16], 0x3f800000
movsd QWORD PTR [rsp+40], xmm2
mov DWORD PTR [rsp+20], 0x40000000
mov DWORD PTR [rsp+24], 0x41000000
movsd QWORD PTR [rsp+48], xmm3
mov DWORD PTR [rsp+28], 0x40e00000
movsd QWORD PTR [rsp+56], xmm4
.L3:
xor eax, eax
mov esi, OFFSET FLAT:.LC8
mov edi, 1
call __printf_chk
cmp rbx, rbp
je .L2
mov edx, DWORD PTR [rbx]
add rbx, 4
jmp .L3
.L2:
lea rbx, [rsp+20]
lea rbp, [rsp+32]
movss xmm0, DWORD PTR .LC0[rip]
.L5:
unpcklps xmm0, xmm0
mov esi, OFFSET FLAT:.LC8
mov edi, 1
mov eax, 1
cvtps2pd xmm0, xmm0
call __printf_chk
cmp rbx, rbp
je .L4
movss xmm0, DWORD PTR [rbx]
add rbx, 4
jmp .L5
.L4:
lea rbx, [rsp+40]
lea rbp, [rsp+64]
movsd xmm0, QWORD PTR .LC1[rip]
.L7:
mov esi, OFFSET FLAT:.LC8
mov edi, 1
mov eax, 1
call __printf_chk
cmp rbx, rbp
je .L6
movsd xmm0, QWORD PTR [rbx]
add rbx, 8
jmp .L7
.L6:
add rsp, 72
xor eax, eax
pop rbx
pop rbp
ret
.LC0:
.long 1065353216
.LC1:
.long 0
.long 1072693248
.LC5:
.long 0
.long 1073741824
.LC6:
.long 0
.long 1075838976
.LC7:
.long 0
.long 1075576832

Know what? C++ assembly is STILL smaller than that of the C example. Dump it yourself if you don't believe me.

If anything is skewed, point it out.

Dgby714

2014-05-25 12:41:49

From: Brandon
The code? How so? It is the exact equivalent C code of that of the C++ example. It is the argument we were having in IRC when I gave him the stackoverflow link which was "irrelevant".

The examples isn't in any way skewed. They are compiled with the same flags and same compiler. Both on the same 64-bit system with the same optimisations. They are equivalent. In fact, the C++ example actually uses the sort and still has less code that the C example which doesn't. You can stick this in any compiler and see for yourself what is generated. The example is to prove that it depends on how you use the language. The language itself isn't bloat in any way. A language is just a tool. It is one of many examples of where C++ is better than C.

As for the templates, it was done to show the power of them over C. It was done to show that the fallacy of "templates are bloated" is just that; a fallacy. It depends on its usage and the developer. As stated, anything that can be done in C can be done in C++.


You're arguing the same thing for C++ that I would for C, anyone who writes C would not have written the methods like that.

Brandon

2014-05-25 12:48:18

From: Dgby714
You're arguing the same thing for C++ that I would for C, anyone who writes C would not have written the methods like that.



Anyone doing a fair comparison would write the exact equivalent of the other code and that is what that is. Nothing more, nothing less.
The C example is the exact equivalent of what would be done in C++. In fact, qsort is implemented the exact same way. With every byte swapped. With the same parameters if I may add.


void qsort (void* base, size_t num, size_t size,
int (*compar)(const void*,const void*));



base - Pointer to the first object of the array to be sorted, converted to a void*.
num - Number of elements in the array pointed by base.
size - Size in bytes of each element in the array.
compar - Pointer to a function that compares two elements.

This function is called repeatedly by qsort to compare two elements. It shall follow the following prototype:
int compar (const void* p1, const void* p2);


Are you saying that you can do better than the C standard library? Are you implying that the library did it wrong then?

We are comparing a C++ bubble sort to a C bubble sort with the exact code in tact. No alterations.

Show me how you'd write it. I will compile it and display the results. I'd like to see the difference. I will display it with a main and without.

Read the closing arguments: http://www.tilander.org/aurora2/Comparing_standard_sort_and_qsort/index.html

Is Scott Meyers wrong then? It is a well known fact that C++ std::sort out performs C qsort and may alike. I own the book.

Dgby714

2014-05-25 12:51:26

From: Brandon
Anyone with doing a fair comparison would write the exact equivalent.


There is no equivalent to a C++ template in C, so you just invalidated your own test…

Personally the closest I think C can get to a C++ template would be multiple methods that all do the same thing with different types.. Not 1 method with a callback…


Also, I was under the impression we were comparing C and C++, not the two's qsort method…

Brandon

2014-05-25 13:00:25

From: Dgby714
There is no equivalent to a C++ template in C, so you just invalidated your own test…

Personally the closest I think C can get to a C++ template would be multiple methods that all do the same thing with different types.. Not 1 method with a callback…


And that is where we introduce the bloat that you do not have in C++. This is simply the worst possible idea you could come up with. Having a separate sort function for EVERY single type is unheard of. It is insane to do. A comparator function is far less code, and less bloat. It is better on cache than a new sort function for float, double, int, int64, etc.. We have already seen how bad gcc is at optimising the above compared to g++.

Even in the case that you write a separate one for every type the C++ sort is still superior to the C one. The assembly is there.

C doesn't have templates and that was exactly the point I was arguing with Wizzup. It cannot do what C++ can but the other way around is true. I was stating the power of the generic/templated method compared to the C sort.


It is the equivalent code and skewing it any other way alters the results. If you'd like to write a separate sort and introduce code duplication and bloat (which I was arguing against), sure you can do that but no C programmer would do that without knowing for sure it has a benefit and doesn't over complicate things.

If you have a better equivalent that isn't going to be over 100 lines for a sort function then sure, display it. But to say my example is skewed because it isn't how you'd write it isn't right. It is EXACTLY how qsort works.

See my last post which I edited before you replied.

Dgby714

2014-05-25 13:03:55

From: Brandon
And that is where we introduce the bloat that you do not have in C++. This is simply the worst possible idea you could come up with. Having a separate sort function for EVERY single type is unheard of. It is insane to do. A comparator function is far less code, and less bloat. It is better on cache than a new sort function for float, double, int, int64, etc..

Even in the case that you write a separate one for every type the C++ sort is still superior to the C one. The assembly is there.

C doesn't have templates and that was exactly the point I was arguing with Wizzup. It cannot do what C++ can but the other way around is true. I was stating the power of the generic/templated method compared to the C sort.


It is the equivalent code and skewing it any other way alters the results. If you'd like to write a separate sort and introduce code duplication and bloat (which I was arguing against), sure you can do that but no C programmer would do that without knowing for sure it has a benefit and doesn't over complicate things.

If you have a better equivalent that isn't going to be over 100 lines for a sort function then sure, display it. But to say my example is skewed because it isn't how you'd write it isn't right. It is EXACTLY how qsort works.

See my last post which I edited before you replied.


See my last post which I edited before you replied….

Brandon

2014-05-25 13:10:12

From: Dgby714
See my last post which I edited before you replied….


Sure I saw it. We were comparing C and C++ on IRC and Golang and Pascal and Rust which was mentioned. Though C and C++ being the main argument.

However, the argument that C++ is pure bloat (introduced by Wizzup himself) brought up the infamous example of the sorting methods and many others. It was to show that C++ itself is NOT a bloat language. It is how you use the language and the features that you use.

When doing benchmarks one of the very first algorithms used is a sort. Second is file reading and writing (IO). I have taken the first step towards that.

Templates CAN be bloated no doubt but that is simply bad usage and that was my point. I have shown exceptional usage of a template in a place where it is used the MOST. In a sort function. In a comparator case. In a speed case. I have shown C's equivalents exactly as is.

What have I received so far? Nothing except "look at glibC" which I did do in fact in order to write such a sort function. If I did it wrong, again.. point it out. Show me a far better equivalent with far better, cleaner, faster assembly than mine.

Again, you sure can write multiple of the exact same sort function for floats, ints, doubles, int64, long double, etc.. but we were arguing bloat, speed and duplication and in both cases C loses there.

Kasi

2014-05-25 13:10:35

Correct me if I'm wrong but if you are comparing two languages why are you writing the two quicksorts to be similar, shouldn't you be writing them to the best of each individual language's capabilities? Or am I missing the point?

Dgby714

2014-05-25 13:18:44

From: Kasi
Correct me if I'm wrong but if you are comparing two languages why are you writing the two quicksorts to be similar, shouldn't you be writing them to the best of each individual language's capabilities? Or am I missing the point?


^^^ This is what I'm thinking….

samerdl

2014-05-25 13:21:44

My first reaction to this:


:D

Let's not let things escalate any further, both sides have some points and both should have behaved better and given more respect to each other, you know both of you are representing this community's leadership… This type of discussion should of been done in a private channel or in a private pm.

No idea what the code is, i dont know C nor do i care!. Treat people the same you want to be treated!.

Brandon

2014-05-25 13:22:34

From: Kasi
Correct me if I'm wrong but if you are comparing two languages why are you writing the two quicksorts to be similar, shouldn't you be writing them to the best of each individual language's capabilities? Or am I missing the point?


That is correct. There isn't any "faster" implementation of a generic bubble sort in C because templates do not exist. Without diving into assembly it is very difficult to achieve the most optimal example in C. You end up with duplication and bloat which Wizzup states does not exist in C compared to C++.

Take for example what Dgby just asked me to do (and is now asking why am I not writing the most optimal example; which I actually did):


void SortByte(uint8_t* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
uint8_t temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortShort(uint16_t* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
uint16_t temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortInt(uint32_t* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
uint32_t temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortFloat(float* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
float temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortDouble(double* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
double temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortInt64(uint64_t* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
uint64_t temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}


What do we have here? A copy of a sort function for every single type we should need to sort. Not to mention that it doesn't sort structs unless you write a separate one for each struct in existence. Now is this faster than the C++ equivalent? No. WHY?

Why is it not faster? Because:


if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])


The tenary operator (question mark operator) is done at run time every loop here. It introduces an extra branch. You may think of it as an extra if statement within an if-statement.

However in C++, this is optimised out because it is done at compile time and not run-time. Now lets say that I some how remove the "ascending/descending" comparison just to give C a fighting chance. It is now the exact same speed as the C++ equivalent which happened to already optimise it out.

Now imagine the assembly storm that the above code is going to generate (a new function and call for every type that needs to be sorted). Do you think this is faster than the comparison sort method? Do you think this doesn't bloat or is useless duplication compared to what I originally wrote?


For this exact reason, C's qsort is implemented with a byte swap and a comparator along with the size parameter: http://www.cplusplus.com/reference/cstdlib/qsort/

^Don't be mistaken by the name of the link. That is a C function. Not a C++ one.

Clarity

2014-05-25 13:23:16

I know nothing about the languages discussed, who is objectively right, who is objectively wrong, maybe everybody is right, everybody is wrong, etc.
But I would like to offer that this looks like it's a stalemate, nobody is going to change their opinion of whether they are right, which language is superior, who is being egotistical, etc.

The same points/ideas are being repeated post-to-post.

So, like Rich said, this is escalating into a waste-of-time flame war for everyone. Especially when people start to take sides.

Lock and discuss in PM if people want to?

I know I haven't been here as long as everyone but I feel like this kind of topic doesn't look awesome for our community. We obviously want to encourage debate and discussion but not in this manner.

My 2 cents.

E: Ninja'd by samerdl

Dgby714

2014-05-25 13:31:15

From: Brandon
That is correct. There isn't any "faster" implementation of a generic bubble sort in C because templates do not exist. Without diving into assembly it is very difficult to achieve the most optimal example in C. You end up with duplication and bloat which Wizzup states does not exist in C compared to C++.

Take for example what Dgby just asked me to do (and is now asking why am I not writing the most optimal example; which I actually did):


void SortByte(uint8_t* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
uint8_t temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortShort(uint16_t* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
uint16_t temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortInt(uint32_t* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
uint32_t temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortFloat(float* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
float temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortDouble(double* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
double temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

void SortInt64(uint64_t* x, size_t size, bool low_to_high)
{
size_t i, j;

for (i = 0; i < size - 1; ++i)
{
for (j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
uint64_t temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}


What do we have here? A copy of a sort function for every single type we should need to sort. Not to mention that it doesn't sort structs unless you write a separate one for each struct in existence. Now is this faster than the C++ equivalent? No. WHY?

Why is it not faster? Because:


if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])


The tenary operator (question mark operator) is done at run time every loop here. It introduces an extra branch. You may think of it as an extra if statement within an if-statement.

However in C++, this is optimised out because it is done at compile time and not run-time. Now lets say that I some how remove the "ascending/descending" comparison just to give C an advantage. It is now the exact same speed as the C++ equivalent which happened to already optimise it out.

Now imagine the assembly storm that the above code is going to generate (a new function and call for every type that needs to be sorted). Do you think this is faster than the comparison sort method? Do you think this doesn't bloat or is useless duplication compared to what I originally wrote?


For this exact reason, C's qsort is implemented with a byte swap and a comparator along with the size parameter: http://www.cplusplus.com/reference/cstdlib/qsort/

^Don't be mistaken by the name of the link. That is a C function. Not a C++ one.


You could write diffrent methods for both ascending and descending…

And LOL, assembly storm with that C code?

Have you tried looking at the assembly of a C++ template that actualy is used with more than 1 type?
It does basically the same exact thing….

Also, afaict, the C++ compiler optimises your example to not even sorting…

Brandon

2014-05-25 13:34:09

From: Dgby714
You could write diffrent methods for both ascending and descending…

And LOL, assembly storm with that C code?

Have you tried looking at the assembly of a C++ template that actualy is used with more than 1 type?
It does basically the same exact thing….



No. It actually does NOT do the exact same thing. In fact, in the C version you have a new sort function generated for EVERY type created. In C++ the float values are converted to their hexadecimal equivalent at compile time and so only ONE sort function is instantiated. THAT is the biggest advantage C++ has here.

The key words are "BASICALLY". It is NOT the same thing. "Basically" what? Did YOU look at the assembly of the two?

You could write diffrent methods for both ascending and descending…


You cannot possibly dive any worse into the argument about bloat and duplication which again (C doesn't have according to Wizzup). I'm going to leave it at that. You should honestly think about WHY the C standard library did what it did.

Dgby714

2014-05-25 13:37:43

From: Brandon
No. It actually does NOT do the exact same thing. In fact, in the C version you have a new sort function generated for EVERY type created. In C++ the float values are converted to their hexadecimal equivalent at compile time and so only ONE sort function is instantiated. THAT is the biggest advantage C++ has here.

The key words are "BASICALLY". It is NOT the same thing. "Basically" what? Did YOU look at the assembly of the two?

You cannot possibly dive any worse into the argument about bloat and duplication. I'm going to leave it at that. You should honestly think about WHY the C standard library did what it did.


Yes, I did look at the asm, I get two sort methods with C++, one for floats and one for int…

Brandon

2014-05-25 13:40:42

From: Dgby714
Yes, I did look at the asm, I get two sort methods with C++, one for floats and one for int…



NO you do not. I'm not sure if you're trying to take sides or completely throw away the entire argument or downplay anything I said and proved.. I specifically explained in the last post that the float values are converted to their HEX equivalent at compile-time. Do you know any assembler or compiler that compares HEX as floats? It is very unfortunate that the C equivalent does NOT happen without directly involving assembly. You're basically telling me right now that you know better than Scott Meyers and every other C++ AND C developer that has done this exact comparison before.

Again, C++ destroys C here. There is and never was any argument on my part about that. You guys seem to think different than what the assembly actually shows.



#include <stdint.h>
#include <stdio.h>

template<typename T, bool low_to_high>
void Sort(T* x, unsigned size)
{
for (unsigned i = 0; i < size - 1; ++i)
{
for (unsigned j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
T temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

int main()
{
int arr[] = {1, 2, 8, 7};
float arr2[] = {1.0f, 2.0f, 8.0f, 7.0f};
double arr3[] = {1.0d, 2.0d, 8.0d, 7.0d};

Sort<int, true>(&arr[0], 2);
Sort<float, true>(&arr2[0], 2);
Sort<double, true>(&arr3[0], 2);

for (int i = 0; i < 4; ++i)
printf("%d", arr[i]);

for (int i = 0; i < 4; ++i)
printf("%d", arr2[i]);

for (int i = 0; i < 4; ++i)
printf("%d", arr3[i]);
}



.LC8:
.string "%d"
main:
push rbp
mov edx, 1
push rbx
sub rsp, 72
movsd xmm1, QWORD PTR .LC1[rip]
lea rbx, [rsp+4]
lea rbp, [rsp+16]
movsd xmm2, QWORD PTR .LC5[rip]
mov DWORD PTR [rsp], 1
movsd xmm3, QWORD PTR .LC6[rip]
mov DWORD PTR [rsp+4], 2
movsd xmm4, QWORD PTR .LC7[rip]
mov DWORD PTR [rsp+8], 8
movsd QWORD PTR [rsp+32], xmm1
mov DWORD PTR [rsp+12], 7
mov DWORD PTR [rsp+16], 0x3f800000
movsd QWORD PTR [rsp+40], xmm2
mov DWORD PTR [rsp+20], 0x40000000
mov DWORD PTR [rsp+24], 0x41000000
movsd QWORD PTR [rsp+48], xmm3
mov DWORD PTR [rsp+28], 0x40e00000
movsd QWORD PTR [rsp+56], xmm4
.L3:
xor eax, eax
mov esi, OFFSET FLAT:.LC8
mov edi, 1
call __printf_chk
cmp rbx, rbp
je .L2
mov edx, DWORD PTR [rbx]
add rbx, 4
jmp .L3
.L2:
lea rbx, [rsp+20]
lea rbp, [rsp+32]
movss xmm0, DWORD PTR .LC0[rip]
.L5:
unpcklps xmm0, xmm0
mov esi, OFFSET FLAT:.LC8
mov edi, 1
mov eax, 1
cvtps2pd xmm0, xmm0
call __printf_chk
cmp rbx, rbp
je .L4
movss xmm0, DWORD PTR [rbx]
add rbx, 4
jmp .L5
.L4:
lea rbx, [rsp+40]
lea rbp, [rsp+64]
movsd xmm0, QWORD PTR .LC1[rip]
.L7:
mov esi, OFFSET FLAT:.LC8
mov edi, 1
mov eax, 1
call __printf_chk
cmp rbx, rbp
je .L6
movsd xmm0, QWORD PTR [rbx]
add rbx, 8
jmp .L7
.L6:
add rsp, 72
xor eax, eax
pop rbx
pop rbp
ret
.LC0:
.long 1065353216
.LC1:
.long 0
.long 1072693248
.LC5:
.long 0
.long 1073741824
.LC6:
.long 0
.long 1075838976
.LC7:
.long 0
.long 1075576832

Dgby714

2014-05-25 13:42:13

From: Brandon
NO you do not. I'm not sure if you're trying to take sides or completely throw away the entire argument:


#include <stdint.h>
#include <stdio.h>

template<typename T, bool low_to_high>
void Sort(T* x, unsigned size)
{
for (unsigned i = 0; i < size - 1; ++i)
{
for (unsigned j = 0; j < size - i - 1; ++j)
{
if (low_to_high ? x[j] > x[j + 1] : x[j] < x[j + 1])
{
T temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
}

int main()
{
int arr[] = {1, 2, 8, 7};
float arr2[] = {1.0f, 2.0f, 8.0f, 7.0f};
double arr3[] = {1.0d, 2.0d, 8.0d, 7.0d};

Sort<int, true>(&arr[0], 2);
Sort<float, true>(&arr2[0], 2);
Sort<double, true>(&arr3[0], 2);

for (int i = 0; i < 4; ++i)
printf("%d", arr[i]);

for (int i = 0; i < 4; ++i)
printf("%d", arr2[i]);

for (int i = 0; i < 4; ++i)
printf("%d", arr3[i]);
}



.LC8:
.string "%d"
main:
push rbp
mov edx, 1
push rbx
sub rsp, 72
movsd xmm1, QWORD PTR .LC1[rip]
lea rbx, [rsp+4]
lea rbp, [rsp+16]
movsd xmm2, QWORD PTR .LC5[rip]
mov DWORD PTR [rsp], 1
movsd xmm3, QWORD PTR .LC6[rip]
mov DWORD PTR [rsp+4], 2
movsd xmm4, QWORD PTR .LC7[rip]
mov DWORD PTR [rsp+8], 8
movsd QWORD PTR [rsp+32], xmm1
mov DWORD PTR [rsp+12], 7
mov DWORD PTR [rsp+16], 0x3f800000
movsd QWORD PTR [rsp+40], xmm2
mov DWORD PTR [rsp+20], 0x40000000
mov DWORD PTR [rsp+24], 0x41000000
movsd QWORD PTR [rsp+48], xmm3
mov DWORD PTR [rsp+28], 0x40e00000
movsd QWORD PTR [rsp+56], xmm4
.L3:
xor eax, eax
mov esi, OFFSET FLAT:.LC8
mov edi, 1
call __printf_chk
cmp rbx, rbp
je .L2
mov edx, DWORD PTR [rbx]
add rbx, 4
jmp .L3
.L2:
lea rbx, [rsp+20]
lea rbp, [rsp+32]
movss xmm0, DWORD PTR .LC0[rip]
.L5:
unpcklps xmm0, xmm0
mov esi, OFFSET FLAT:.LC8
mov edi, 1
mov eax, 1
cvtps2pd xmm0, xmm0
call __printf_chk
cmp rbx, rbp
je .L4
movss xmm0, DWORD PTR [rbx]
add rbx, 4
jmp .L5
.L4:
lea rbx, [rsp+40]
lea rbp, [rsp+64]
movsd xmm0, QWORD PTR .LC1[rip]
.L7:
mov esi, OFFSET FLAT:.LC8
mov edi, 1
mov eax, 1
call __printf_chk
cmp rbx, rbp
je .L6
movsd xmm0, QWORD PTR [rbx]
add rbx, 8
jmp .L7
.L6:
add rsp, 72
xor eax, eax
pop rbx
pop rbp
ret
.LC0:
.long 1065353216
.LC1:
.long 0
.long 1072693248
.LC5:
.long 0
.long 1073741824
.LC6:
.long 0
.long 1075838976
.LC7:
.long 0
.long 1075576832


I don't even care anymore… This argument is going nowhere…

Brandon

2014-05-25 13:47:46

From: Dgby714
Like I just said, the C++ compiler optimises that to not even sorting, you cant sort a constant array in C++, try making a random array…. I don't even care anymore… This argument is going nowhere…



You know quite well that array is NOT constant. Do you see the const keyword there? No. In fact, you CAN sort the array. You can try an std::swap on two of the indices if you don't believe me. If only you'd take the time to run it and stop arguing myths. If you are going to say that it cannot be sorted, then are you implying that the compiler does it at compile-time then? Because I can assure you the output is sorted in both C and C++ and it is NOT compile-time. Print the array before calling sort. Call sort and then print the array. You'll see it is sorted.

To prove it is NOT constant as you claim:

http://ideone.com/vz9KPz

So far, between us, I'm the only one doing ANYTHING to prove Wizzup's myths wrong. Don't drink the kool-aid. I was sure he knew more about Assembly, C and C++ before jumping into this argument. Especially on a bubble sort.

Dgby714

2014-05-25 13:52:03

From: Brandon
You know quite well that array is NOT constant. Do you see the const keyword there? No. In fact, you CAN sort the array. You can try an std::swap on two of the indices if you don't believe me. If only you'd take the time to run it and stop arguing myths.

http://ideone.com/vz9KPz

So far I'm the only one doing ANYTHING to prove Wizzup's myths wrong.


I didn't mean constant in the sense of a constant variable….

I mean what is the point in sorting an already sorted array. I'm looking at the asm you're providing because my compiles come with completely different results…

And, I'm out, store time, need a drink =)

Rich

2014-05-25 13:52:19


Brandon

2014-05-25 13:55:58

From: Dgby714
I didn't mean constant in the sense of a constant variable….

I mean what is the point in sorting an already sorted array. I'm looking at the asm you're providing because my compiles come with completely different results…

And, I'm out, store time, need a drink =)



Well take a look again because the array I provided is NOT sorted already. {1, 2, 8, 7};


I have said all I have to say and you're right it is going no where when you guys won't accept what is right in front of you. Everything you guys say has to be right. It just has to be superior in any way.


@Anyone, feel free to delete it all. My proof is done.

Dgby714

2014-05-25 14:07:40

From: Brandon
Well take a look again because the array I provided is NOT sorted already. {1, 2, 8, 7};


I have said all I have to say and you're right it is going no where when you guys won't accept what is right in front of you. Everything you guys say has to be right. It just has to be superior in any way.


@Anyone, feel free to delete it all. My proof is done.


hmm I see, I didn't notice the two numbers swapped… Sorry o masterful one…

Sk1nyNerd

2014-05-25 14:28:40


Kasi

2014-05-25 14:34:38

From: Sk1nyNerd


Just here for the comments but you post. Good job pal.

Sk1nyNerd

2014-05-25 14:39:38

From: Kasi
Just here for the comments but you post. Good job pal.


your level of humor and understanding of mood lightening satire must be non-existant.

slacky

2014-05-25 15:02:08

Freaking pointless discussion.

- Nothing to see here, move along..

Sjoe

2014-05-25 15:17:05

Tsm tsm .

rj

2014-05-25 15:22:47

From: Sjoe
Tsm tsm .


Sjoe is just glas his Taiwan Semiconductor Mfg. Co. Ltd. (ADR) stock went up .10% today

Kasi

2014-05-25 15:40:27

From: Sk1nyNerd
your level of humor and understanding of mood lightening satire must be non-existant.


Isn't humor, its just the thing you posted is contradictory. Notice I didn't quote anyone else who posted something / tried to mood lighten.

Wizzup?

2014-05-25 16:24:54

I see no reason to keep the thread open any longer. Closed. If people really want to re-open the thread for a technical discussion, feel free to start a new thread.