8 ms·
I'm curious and would love to take a look. Any chance any of that code is available somewhere? My c++, little that I write, mostly looks like C and I'd love to
by Icathian 4y ago
I'm curious and would love to take a look. Any chance any of that code is available somewhere? My c++, little that I write, mostly looks like C and I'd love to learn something new.
- waynecochran 4y agoMost of its in a private GitHub repo but I think I can open a piece of it… here is part of it ... a header only library for computing closest pairs... https://github.com/wcochran/closest-pairs/blob/main/closest-pairs.h https://github.com/wcochran/closest-pairs/blob/main/closest-...
- mike_hock 4y agoWhy is Eigen/Dense included if you never refer to anything Eigen and just take it as a duck-typed template parameter?
- waynecochran 4y agoTrue.. good eye .. the operations on type P are very Eigen specific, but another type could easily provide those.
- bugfix-66 4y agoAfter giving your code a quick skim, I cannot see any mistakes in your vector indexing. However, your code is full of vector accesses without bounds checking: vec[i] instead of vec.at(i). That's just as "unsafe" as C, so I recommend not bragging about how far you've come. Your code is full of what is essentially unprotected C-style *(addr + i) = ... ... = *(addr + i) You've been writing C++ since the 1980's, but your code is full of raw pointer math, and yet... "No worries about memory safety"? I have a feeling you'll be reaching for Valgrind or address sanitizer someday soon, just like the C programmers.
- waynecochran 4y agoNot bragging at all.. it was just introspection on how different my code looks now… maybe I should find some older code that is fraught was dangerous constructs. In fact, early versions of this were segfaulting for the very reasons you mention.
- bugfix-66 4y agoThank you for being honest. This safe, "no worries" C++ was segfaulting. You've managed to make it correct today but it's still unsafe. Someday one of your coworkers is going to break it and this code will be trashing the heap. Mysterious memory corruption failures are your destiny. That said, Happy Halloween!
- WoodenChair 4y agoYour comments come across as pretty mean-spirited. Let me rewrite one line for you. You wrote: > Someday one of your coworkers is going to break it and this code will be trashing the heap. Mysterious memory corruption failures are your destiny. You could have written something like, "It's possible this code will break in the future and you won't even realize the cause, because it will appear as a mysterious memory corruption failure." See how I left out a word like "destiny" and took out the whole bit about coworkers? Yeah, much nicer and less personalized.
- bugfix-66 4y agoAnd then I said "Happy Halloween". The point was that being a C++ programmer is like being part of a horror movie. I say that as a person who uses C++ in my day job. It's a nightmare.
- waynecochran 4y agoI have a love/hate relationship with C++ ... probably like most C++ programers.
- Icathian 4y agoMuch appreciated, thank you!
- hyperhopper 4y agoMost Google C++ code is written like that, check out their repos on GitHub
- throwaway311022 4y ago
- brnt 4y agoA project that my team works on might give you an impression: https://github.com/arbor-sim/arbor https://github.com/arbor-sim/arbor
- waynecochran 4y agoThat is some hard core science simulation...