Why C++ instead of C#?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

JohnWoe
Posts: 491
Joined: Sat Mar 02, 2013 11:31 pm

Re: Why C++ instead of C#?

Post by JohnWoe »

Exceptions are a mess in C++. Nobody ever use them. They are fundamentally broken in every language too.
Boost takes 100 EONS to compile.

There's a good language in C++ struggling to get out.

EDIT: For me JavaScript is fast enough.
I trained with my back-prop algorithm a 4x25x25x1 net in 8 seconds
It converges quite nicely to near 0 error.

Code: Select all

23:32:39.180 Training NN ( 4x25x25x1 ) jnn.js:428:13
23:32:39.188 ... ( 0 % ) : 1.00386610640071 : 1.00386610640071 jnn.js:436:17
23:32:39.296 ... ( 1 % ) : 3.101227619486797 : 0.8615190457140264 jnn.js:436:17
23:32:39.392 ... ( 2 % ) : 1.073655582054501 : 0.8615190457140264 jnn.js:436:17
23:32:39.487 ... ( 3 % ) : 1.9915425186694968 : 0.8615190457140264 jnn.js:436:17
23:32:39.589 ... ( 4 % ) : 0.7977246618020726 : 0.7930196203081319 jnn.js:436:17
23:32:39.725 ... ( 5 % ) : 0.7055718107528239 : 0.7055718107528239 jnn.js:436:17
23:32:39.848 ... ( 6 % ) : 0.6651494879321889 : 0.6516587749249204 jnn.js:436:17
23:32:39.969 ... ( 7 % ) : 0.6591001293411508 : 0.6108609697994423 jnn.js:436:17
23:32:40.068 ... ( 8 % ) : 0.6113746972076745 : 0.6097646267056693 jnn.js:436:17
23:32:40.165 ... ( 9 % ) : 0.6222517412564615 : 0.6096775335816693 jnn.js:436:17
23:32:40.263 ... ( 10 % ) : 0.6216697757859238 : 0.6096466908851874 jnn.js:436:17
23:32:40.358 ... ( 11 % ) : 0.6111499775869463 : 0.6096466908851874 jnn.js:436:17
23:32:40.453 ... ( 12 % ) : 0.6199521184631348 : 0.6096466908851874 jnn.js:436:17
23:32:40.550 ... ( 13 % ) : 0.6584591188609338 : 0.6095753754780876 jnn.js:436:17
23:32:40.646 ... ( 14 % ) : 0.6165068845043779 : 0.6095753754780876 jnn.js:436:17
23:32:40.741 ... ( 15 % ) : 0.615007188538311 : 0.6095753754780876 jnn.js:436:17
23:32:40.835 ... ( 16 % ) : 0.6148016149655436 : 0.6095753754780876 jnn.js:436:17
23:32:40.933 ... ( 17 % ) : 0.6124161045525622 : 0.6095753754780876 jnn.js:436:17
23:32:41.029 ... ( 18 % ) : 0.6180045562093283 : 0.6095753754780876 jnn.js:436:17
23:32:41.125 ... ( 19 % ) : 0.6112391725877436 : 0.609558163692611 jnn.js:436:17
23:32:41.220 ... ( 20 % ) : 0.6309047454801381 : 0.609558163692611 jnn.js:436:17
23:32:41.318 ... ( 21 % ) : 3.0089454486972427 : 0.3288504020938001 jnn.js:436:17
23:32:41.414 ... ( 22 % ) : 2.9927039058951745 : 0.3288504020938001 jnn.js:436:17
23:32:41.509 ... ( 23 % ) : 3.019129802559434 : 0.3288504020938001 jnn.js:436:17
23:32:41.614 ... ( 24 % ) : 0.4527041390079418 : 0.10738206121833412 jnn.js:436:17
23:32:41.711 ... ( 25 % ) : 0.4694492588720521 : 0.10738206121833412 jnn.js:436:17
23:32:41.807 ... ( 26 % ) : 0.46561438966098945 : 0.10738206121833412 jnn.js:436:17
23:32:41.905 ... ( 27 % ) : 1.182892964767319 : 0.10718081262479943 jnn.js:436:17
23:32:42.000 ... ( 28 % ) : 1.2295148386181578 : 0.10718081262479943 jnn.js:436:17
23:32:42.096 ... ( 29 % ) : 0.1553810084030034 : 0.10718081262479943 jnn.js:436:17
23:32:42.191 ... ( 30 % ) : 1.2651809892640509 : 0.10718081262479943 jnn.js:436:17
23:32:42.288 ... ( 31 % ) : 0.18965537622111278 : 0.07279916410664714 jnn.js:436:17
23:32:42.384 ... ( 32 % ) : 0.18540279255792846 : 0.07279916410664714 jnn.js:436:17
23:32:42.480 ... ( 33 % ) : 0.17105489765326257 : 0.07279916410664714 jnn.js:436:17
23:32:42.576 ... ( 34 % ) : 0.2046500886467257 : 0.07279916410664714 jnn.js:436:17
23:32:42.673 ... ( 35 % ) : 0.1643847719890916 : 0.07279916410664714 jnn.js:436:17
23:32:42.768 ... ( 36 % ) : 0.18478574356289312 : 0.07279916410664714 jnn.js:436:17
23:32:42.865 ... ( 37 % ) : 0.2068859714382803 : 0.07279916410664714 jnn.js:436:17
23:32:42.964 ... ( 38 % ) : 0.2722394030740077 : 0.07279916410664714 jnn.js:436:17
23:32:43.064 ... ( 39 % ) : 0.18138269661585743 : 0.07279916410664714 jnn.js:436:17
23:32:43.164 ... ( 40 % ) : 0.30972864705916775 : 0.07279916410664714 jnn.js:436:17
23:32:43.263 ... ( 41 % ) : 0.9564345943042107 : 0.03092440013611706 jnn.js:436:17
23:32:43.360 ... ( 42 % ) : 0.3705987248874962 : 0.03092440013611706 jnn.js:436:17
23:32:43.456 ... ( 43 % ) : 0.1097572804753235 : 0.03092440013611706 jnn.js:436:17
23:32:43.553 ... ( 44 % ) : 0.09199657456340292 : 0.03092440013611706 jnn.js:436:17
23:32:43.650 ... ( 45 % ) : 0.10489769717709167 : 0.03092440013611706 jnn.js:436:17
23:32:43.746 ... ( 46 % ) : 0.13845166039266027 : 0.03092440013611706 jnn.js:436:17
23:32:43.842 ... ( 47 % ) : 0.10090026564435363 : 0.03092440013611706 jnn.js:436:17
23:32:43.942 ... ( 48 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.039 ... ( 49 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.134 ... ( 50 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.231 ... ( 51 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.326 ... ( 52 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.421 ... ( 53 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.517 ... ( 54 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.613 ... ( 55 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.709 ... ( 56 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.805 ... ( 57 % ) : 0.027898617381378235 : 0.027898617381378235 jnn.js:436:17
23:32:44.905 ... ( 58 % ) : 1.330528066239233 : 0.009830589661493593 jnn.js:436:17
23:32:45.001 ... ( 59 % ) : 0.05372310824311482 : 0.009830589661493593 jnn.js:436:17
23:32:45.098 ... ( 60 % ) : 1.573289371799488 : 0.008990919786236892 jnn.js:436:17
23:32:45.196 ... ( 61 % ) : 0.8308490004906783 : 0.008990919786236892 jnn.js:436:17
23:32:45.295 ... ( 62 % ) : 2.13563168373505 : 0.008990919786236892 jnn.js:436:17
23:32:45.394 ... ( 63 % ) : 2.1193782135229107 : 0.008990919786236892 jnn.js:436:17
23:32:45.491 ... ( 64 % ) : 3.140606249857025 : 0.008990919786236892 jnn.js:436:17
23:32:45.587 ... ( 65 % ) : 1.3070484014648862 : 0.008990919786236892 jnn.js:436:17
23:32:45.683 ... ( 66 % ) : 1.0467940353385852 : 0.008990919786236892 jnn.js:436:17
23:32:45.779 ... ( 67 % ) : 1.9258619305041167 : 0.008990919786236892 jnn.js:436:17
23:32:45.879 ... ( 68 % ) : 2.1094229237456514 : 0.008990919786236892 jnn.js:436:17
23:32:45.976 ... ( 69 % ) : 1.2249124653424988 : 0.008990919786236892 jnn.js:436:17
23:32:46.073 ... ( 70 % ) : 2.1375928763577137 : 0.005749170525458429 jnn.js:436:17
23:32:46.172 ... ( 71 % ) : 2.3389380729857985 : 0.005749170525458429 jnn.js:436:17
23:32:46.267 ... ( 72 % ) : 0.9259557624742903 : 0.005749170525458429 jnn.js:436:17
23:32:46.363 ... ( 73 % ) : 0.9801021882672554 : 0.005749170525458429 jnn.js:436:17
23:32:46.461 ... ( 74 % ) : 3.1406062499638354 : 0.005749170525458429 jnn.js:436:17
23:32:46.560 ... ( 75 % ) : 0.23892857646953639 : 0.005749170525458429 jnn.js:436:17
23:32:46.659 ... ( 76 % ) : 2.13167568069085 : 0.005749170525458429 jnn.js:436:17
23:32:46.755 ... ( 77 % ) : 3.1339729364375644 : 0.005749170525458429 jnn.js:436:17
23:32:46.852 ... ( 78 % ) : 0.9239161050446034 : 0.005749170525458429 jnn.js:436:17
23:32:46.947 ... ( 79 % ) : 0.8733749597442257 : 0.005749170525458429 jnn.js:436:17
23:32:47.043 ... ( 80 % ) : 2.1360075570010193 : 0.005749170525458429 jnn.js:436:17
23:32:47.142 ... ( 81 % ) : 3.1301835795456987 : 0.005749170525458429 jnn.js:436:17
23:32:47.241 ... ( 82 % ) : 0.07071451626365097 : 0.002326143885886005 jnn.js:436:17
23:32:47.250 ======== jnn.js:409:13
23:32:47.251 Total:   8208 jnn.js:410:13
23:32:47.252 Success: 107 jnn.js:411:13
23:32:47.252 Fail:    8101 jnn.js:412:13
23:32:47.253 NPS:     1017 jnn.js:413:13
23:32:47.253 MRE:     0.0004957628296145834 jnn.js:414:13
23:32:47.254 ############### jnn.js:415:13
23:32:47.254 ### SUCCESS ### jnn.js:416:13
23:32:47.255 ############### jnn.js:417:13
23:32:47.256 NeuralNetwork learn: 8278ms - timer ended jnn.js:450:13
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Why C++ instead of C#?

Post by klx »

R. Tomasi wrote: Thu Sep 02, 2021 5:06 pm I second that. In my experience modern compilers are very very good at optimizing and the more you stick to recommended design patterns, the better it will understand your code and do it's job. Granted, on rare occasions you can do "ugly" code that performs better than "pretty" code, but usually that is then tied to one particular platform and one particular compiler.
Ok I just reviewed your engine (thanks for releasing the sources), and your sort method looks like this:

https://github.com/rtomasi75/pygmalion/ ... ics/sort.h

This exactly proves my point: Even in C++, the fastest possible code is not always pretty.
[Moderation warning] This signature violated the rule against commercial exhortations.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Why C++ instead of C#?

Post by R. Tomasi »

klx wrote: Tue Sep 14, 2021 3:49 pm
R. Tomasi wrote: Thu Sep 02, 2021 5:06 pm I second that. In my experience modern compilers are very very good at optimizing and the more you stick to recommended design patterns, the better it will understand your code and do it's job. Granted, on rare occasions you can do "ugly" code that performs better than "pretty" code, but usually that is then tied to one particular platform and one particular compiler.
Ok I just reviewed your engine (thanks for releasing the sources), and your sort method looks like this:

https://github.com/rtomasi75/pygmalion/ ... ics/sort.h

This exactly proves my point: Even in C++, the fastest possible code is not always pretty.
The "ugly" part is the SSE2/AVX2 specific code, the rest is pretty much straight-forward and readable code. So it does not prove anything about your point at all, it's just an example of what I said: you can have ugly code that performs better, but it's going to be for some special case.
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Why C++ instead of C#?

Post by klx »

R. Tomasi wrote: Tue Sep 14, 2021 4:05 pm The "ugly" part is the SSE2/AVX2 specific code, the rest is pretty much straight-forward and readable code. So it does not prove anything about your point at all, it's just an example of what I said: you can have ugly code that performs better, but it's going to be for some special case.
Well, that's circular reasoning.

And how on earth is this readable? With all due respect for what you did here (the sorting is pretty cool and something I'll try out myself), in my expert highly-sought-after opinion, this is about as far from readable as it gets. If this is readable, then I'd like for Mergi to explain why the two files below, which are largely identical, need to be ~1000 lines of verbose C++ code each. How does one even work with code like this?

https://github.com/rtomasi75/pygmalion/ ... sics/bsf.h
https://github.com/rtomasi75/pygmalion/ ... sics/bsr.h
[Moderation warning] This signature violated the rule against commercial exhortations.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Why C++ instead of C#?

Post by R. Tomasi »

klx wrote: Tue Sep 14, 2021 4:25 pm
R. Tomasi wrote: Tue Sep 14, 2021 4:05 pm The "ugly" part is the SSE2/AVX2 specific code, the rest is pretty much straight-forward and readable code. So it does not prove anything about your point at all, it's just an example of what I said: you can have ugly code that performs better, but it's going to be for some special case.
Well, that's circular reasoning.

And how on earth is this readable? With all due respect for what you did here (the sorting is pretty cool and something I'll try out myself), in my expert highly-sought-after opinion, this is about as far from readable as it gets. If this is readable, then I'd like for Mergi to explain why the two files below, which are largely identical, need to be ~1000 lines of verbose C++ code each. How does one even work with code like this?

https://github.com/rtomasi75/pygmalion/ ... sics/bsf.h
https://github.com/rtomasi75/pygmalion/ ... sics/bsr.h
With all due respect... you have spammed this board with such an amount of BS, that I consider any attempt to engage in fruitful conversation with you a waste of my time.
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Why C++ instead of C#?

Post by klx »

R. Tomasi wrote: Tue Sep 14, 2021 4:29 pm With all due respect... you have spammed this board with such an amount of BS, that I consider any attempt to engage in fruitful conversation with you a waste of my time.
Ok, fine. Mergi and I will discuss your code. Mergi?
[Moderation warning] This signature violated the rule against commercial exhortations.
tcusr
Posts: 323
Joined: Tue Aug 31, 2021 10:32 pm
Full name: tcusr

Re: Why C++ instead of C#?

Post by tcusr »

R. Tomasi wrote: Tue Sep 14, 2021 4:29 pm
klx wrote: Tue Sep 14, 2021 4:25 pm
R. Tomasi wrote: Tue Sep 14, 2021 4:05 pm The "ugly" part is the SSE2/AVX2 specific code, the rest is pretty much straight-forward and readable code. So it does not prove anything about your point at all, it's just an example of what I said: you can have ugly code that performs better, but it's going to be for some special case.
Well, that's circular reasoning.

And how on earth is this readable? With all due respect for what you did here (the sorting is pretty cool and something I'll try out myself), in my expert highly-sought-after opinion, this is about as far from readable as it gets. If this is readable, then I'd like for Mergi to explain why the two files below, which are largely identical, need to be ~1000 lines of verbose C++ code each. How does one even work with code like this?

https://github.com/rtomasi75/pygmalion/ ... sics/bsf.h
https://github.com/rtomasi75/pygmalion/ ... sics/bsr.h
With all due respect... you have spammed this board with such an amount of BS, that I consider any attempt to engage in fruitful conversation with you a waste of my time.
tbh he's not completely wrong, repeating code is not a good sign.
if you're interested in C++20 they added a <bit> header which provides those functions. (if compiled with -march=native and -O3 they compile to their respective assembly instruction)
https://en.cppreference.com/w/cpp/header/bit
Mergi
Posts: 127
Joined: Sat Aug 21, 2021 9:55 pm
Full name: Jen

Re: Why C++ instead of C#?

Post by Mergi »

klx wrote: Tue Sep 14, 2021 4:56 pm Ok, fine. Mergi and I will discuss your code. Mergi?
Sir, imma be honest, i don't understand much of the source code. I'm not a big fan of such verbose coding style, and there's too much deep if branching for me to follow. :shock: :D When code is more than 2 ifs deep, my brain turns off. :oops: I like small, compact functions just like uncle Bob does (great series of lectures on youtube btw). But that doesn't really say anything about C++.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Why C++ instead of C#?

Post by R. Tomasi »

tcusr wrote: Tue Sep 14, 2021 5:29 pm
R. Tomasi wrote: Tue Sep 14, 2021 4:29 pm
klx wrote: Tue Sep 14, 2021 4:25 pm
R. Tomasi wrote: Tue Sep 14, 2021 4:05 pm The "ugly" part is the SSE2/AVX2 specific code, the rest is pretty much straight-forward and readable code. So it does not prove anything about your point at all, it's just an example of what I said: you can have ugly code that performs better, but it's going to be for some special case.
Well, that's circular reasoning.

And how on earth is this readable? With all due respect for what you did here (the sorting is pretty cool and something I'll try out myself), in my expert highly-sought-after opinion, this is about as far from readable as it gets. If this is readable, then I'd like for Mergi to explain why the two files below, which are largely identical, need to be ~1000 lines of verbose C++ code each. How does one even work with code like this?

https://github.com/rtomasi75/pygmalion/ ... sics/bsf.h
https://github.com/rtomasi75/pygmalion/ ... sics/bsr.h
With all due respect... you have spammed this board with such an amount of BS, that I consider any attempt to engage in fruitful conversation with you a waste of my time.
tbh he's not completely wrong, repeating code is not a good sign.
if you're interested in C++20 they added a <bit> header which provides those functions. (if compiled with -march=native and -O3 they compile to their respective assembly instruction)
https://en.cppreference.com/w/cpp/header/bit
I deliberately do not want any dependency on C++20 in that project. But the real reason these classes are so convoluted (and I totally agree, that they are) is that they are tailored specifically to support the uint_t template, which abtracts many things away. I certainly had my reasons to do it the way I did and it helps a lot in keeping the actual engine code - which isn't limited to chess - clean and readable. Winning any kind of beauty contest was not a design goal here.
Mergi wrote: Tue Sep 14, 2021 5:33 pm
klx wrote: Tue Sep 14, 2021 4:56 pm Ok, fine. Mergi and I will discuss your code. Mergi?
Sir, imma be honest, i don't understand much of the source code. I'm not a big fan of such verbose coding style, and there's too much deep if branching for me to follow. :shock: :D When code is more than 2 ifs deep, my brain turns off. :oops: I like small, compact functions just like uncle Bob does (great series of lectures on youtube btw). But that doesn't really say anything about C++.
Your candor is appreciated and welcome. Mind you, the branches are constexpr branches, so the actual bits generated by the compiler do not branch so much. Indeed one could have achieved the same results using lots of template magic, but I somehow doubt that would have made it in any way more readable.

Edit: In any case, I welcome the discussion anout my source code, however I suggest we move that to the thread about the Pygmalion sources, in order to not hijack OPs thread - which still is about C# vs C++. Not sure my source code really proves any point when it comes to that topic... :mrgreen:
User avatar
lithander
Posts: 880
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Why C++ instead of C#?

Post by lithander »

Seems like all other threads eventually have an off-topic discussion about C# vs C++ but the only thread where this discussion would be on-topic derails into something else. :P

(btw, I'm still interested in comparing apples with apples regarding the speed of C# vs C++ but I'll make a dedicated thread about that in due time.)
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess