7 ms·
Do you still use c++ or have you moved to rust?
by ilrwbwrkhv 2y ago
Do you still use c++ or have you moved to rust?
- Const-me 2y agoI mostly use C++ and C#, and I’m not a fan of Rust.
- victor106 2y agoI love C#. > I’m not a fan of Rust. I wonder why? Care to elaborate?
- neonsunset 2y agoA little more on topic, if you like SIMD and C#, dotnet/runtime now has an introductory guide to Vector128/256/512<T> API: https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/vectorization-guidelines.md https://github.com/dotnet/runtime/blob/main/docs/coding-guid... Now, the default syntax can still be a bit more wordy with byref arithmetics than ideal, but you can add a few extension methods to make it look it closer to Rust's pointer arithmetics: https://github.com/U8String/U8String/blob/main/Sources/U8String/CaseConverters/U8AsciiCaseConverter.cs#L153-L171 https://github.com/U8String/U8String/blob/main/Sources/U8Str... (unrelated note but .NET lowers this to vpternlogd if AVX512VL is available) You can find more examples of SIMD use in dotnet/runtime if that interests you: https://grep.app/search?q=Vector%28128%7C256%7C512%29%3C%5Cw%2B%3E®exp=true&filter[lang][0]=C%23&filter[repo][0]=dotnet/runtime https://grep.app/search?q=Vector%28128%7C256%7C512%29%3C%5Cw... Many paths are vectorized: to/from hexadecimal byte conversion, unicode encoding/decoding, various hash algorithms, counting and searching for elements, chunking text, there's a BLAS library now too and more.
- Const-me 2y ago> I wonder why? The whole point of Rust is memory safety and security, but I don’t care too much about either of them. I mostly work on offline desktop apps. When I do work on network exposed servers, I use C# which delivers even better safety and security for a reasonable performance overhead. In pursue of that memory safety, Rust sacrificed pretty much everything else. The language is incredibly hard to learn. The compiler is even slower than C++. It’s hard to do R&D in Rust because memory safety forces minor changes into large refactors. The recent push to async/await is controversial, to say the least. It’s impossible to implement any non-trivial data structures in safe Rust. In my line of work designing data structures is more important than writing executable code, because the gap between RAM bandwidth and processor performance have been growing for decades now. Also, interesting post and discussion: https://news.ycombinator.com/item?id=40172033 https://news.ycombinator.com/item?id=40172033
- jltsiren 2y agoI found Rust easy to learn after ~25 years of C/C++. It was definitely easier than learning to use Python properly. Maybe it was because I was often writing multi-threaded shared-memory code in C++, and that forces you to think in a very Rust-like way. Rust makes it difficult to implement data structures that rely on pointers. But in practice, you often want to minimize the use of actual pointers, even in data structures that use pointers on an abstract level. Pointers are large, following them is slow, and they encourage making many small allocations, which has a large space overhead. And if you define the interface in terms of pointers, you can't easily switch to an implementation where you can't point directly to any individual item stored in the structure.
- Const-me 2y ago> Maybe it was because I was often writing multi-threaded shared-memory code in C++ I’ve been writing C/C++ for living for about 25 years, also often writing multi-threaded shared-memory code in C++. However, seems I worked on very different projects, because I think in very Rust-incompatible way. Here’s an example. Quite often I need to compute long arrays of numbers, and the problem is parallel, like multiplication of large matrices. A good way to do that is slicing the output into blocks, and computing different blocks on different CPU cores, using OpenMP or some other thread pool. Different CPU cores need concurrent write access to the same vector, this is illegal in Rust. > But in practice, you often want to minimize the use of actual pointers In practice I often want actual pointers because graphs and trees are everywhere in computing. Many of them mutable, like DOM tree of this web page we’re visiting. Pointer chasing is generally slow compared to arithmetic instructions, but much faster than hash maps which can be used to implement the same thing. A hash map lookup is chasing at least 1 pointer usually multiple (depends on the implementation), and before that spends time computing the hash. > they encourage making many small allocations Pointer and allocations are orthogonal. It’s possible to design pointer-based data structure like tree or graph where the nodes are owned by containers, as opposed to other nodes.
- pcwalton 2y ago> Here’s an example. Quite often I need to compute long arrays of numbers, and the problem is parallel, like multiplication of large matrices. A good way to do that is slicing the output into blocks, and computing different blocks on different CPU cores, using OpenMP or some other thread pool. Different CPU cores need concurrent write access to the same vector, this is illegal in Rust. This is actually easier in Rust than in C++, because of par_iter_mut() [1] from Rayon. (In any case, usually if you want to do that sort of thing quickly then you'd use ndarray which can use BLAS.) > Pointer chasing is generally slow compared to arithmetic instructions, but much faster than hash maps which can be used to implement the same thing. A hash map lookup is chasing at least 1 pointer usually multiple (depends on the implementation), and before that spends time computing the hash. Usually in Rust you use indices into arrays instead, which can be folded into the addressing mode on most architectures. If you really want to use a hash map, there's slotmap which precomputes the hash. [1]: https://github.com/rust-lang-nursery/rust-cookbook/blob/master/src/concurrency/parallel/rayon-iter-mut.md https://github.com/rust-lang-nursery/rust-cookbook/blob/mast...
- akira2501 2y agoRust. Never mentioned. Shoehorned into every conversation anyways.
- IntelMiner 2y agoIt's the "btw I use Arch" of programming
- intelVISA 2y agoThe usurper must challenge the King.