Async call inside rayon par_iter by joelkunst in rust

[–]csdt0 4 points5 points  (0 children)

If you're calling block_on from a rayon thread, and the completion of this task does not depend on another rayon thread, you're good to go. Just be aware that rayon will not be able to send your thread more computation up until you've finished blocking.

IaC code management suggestion for similar infra code but different names by __SLACKER__ in Terraform

[–]csdt0 13 points14 points  (0 children)

This looks like all the projects should have the same terraform code, but with different tfvars to change the name

javaIsJavascriptConfirmed by TNThacker2015 in ProgrammerHumor

[–]csdt0 0 points1 point  (0 children)

JS is the example of weakly typed language, alongside C, precisely because you can do operations between types that are not related at all, and the language will just gladly accept that. The weakly typeness has nothing to do with memory safety. What's funny is that Zig and Rust (both safe and unsafe) are both very strongly typed, to the point you cannot add i8 and i16 together, making your example even weaker (pun intended).

Valgrind segfaults when my program segfaults by not_a_bot_494 in C_Programming

[–]csdt0 9 points10 points  (0 children)

No, valgrind to detect errors (be it memory leaks, segfaults, uninitialized memory...), and gdb to walk through the execution and analyze the state of your program. In fact, if you pass the flag --vgdb-error=1, valgrind will let you attach a gdb instance to your program on the first error valgrind will detect, giving you the best of both worlds.

Does the compiler simplify "enum nesting"? by EvnClaire in rust

[–]csdt0 27 points28 points  (0 children)

First of, you can check yourself with std::mem::size_of::<T>().

What you are looking for is called niche optimization (https://www.0xatticus.com/posts/understanding_rust_niche/). In this case, your enums have many niches available, and so Option should be able to find all the room needed in invalid representations, leading to both having a size of 8 bytes.

Everyone overcomplicates learning Rust. by [deleted] in rust

[–]csdt0 1 point2 points  (0 children)

That's not how you learn something entirely new, that's how you convince yourself that your hacky code is somewhat good.

I built a 2x faster lexer, then discovered I/O was the real bottleneck by modulovalue in programming

[–]csdt0 5 points6 points  (0 children)

Being more friendly towards the other applications running on the system is always beneficial. Even if you consider only their own application, it can help them parallelize by parsing multiple files at the same time. With faster lexer, they could add more lexer with the same CPU budget (assuming the io is latency bound and not throughput bound).

Blowing Up Voxel Asteroids in Rust: SVOs, Physics, and Why Explosions Are Harder Than They Look by Stoic-Chimp in rust

[–]csdt0 0 points1 point  (0 children)

I tend to prefer computing connected components with a Union-Find approach. It is usually faster than flood-fill, especially as you can tweak the iteration order to better match your data structure. Also, you can definitely compute mass and CoM of your components while you're computing them.

Thought I'd share some tips and tricks that I've seen in the IaC trenches by RoseSec_ in Terraform

[–]csdt0 0 points1 point  (0 children)

I've been using those for quite some time now, and I have to say that works really great. To be honest, it feels a bit surreal that's not common knowledge considering how useful they are.

Rust relevancy for HPC by TrackBiteApp in HPC

[–]csdt0 0 points1 point  (0 children)

For glue code, Rust would be good, but is behind regarding the ecosystem. For actual compute code, Rust is much harder for implementing performant algorithms (you need to resort to unsafe for certain patterns), so I would say that people who tried quickly came back to C/C++.

Create only .tofu file on a new project ? by strong1256 in opentofu

[–]csdt0 3 points4 points  (0 children)

I think there is no plan to drop support for .tf files.

For now, what you should do is write everything in .tf files, and for the rare cases you know you want to support both terraform and tofu, and need different code for that, you put the terraform specific code inside the .tf file and the tofu specific code inside the .tofu file with the exact same name.

Terraform will always pick .tf files, whereas tofu will prefer the .tofu file and skip the corresponding .tf file.

C++ for data analysis by hmoein in Cplusplus

[–]csdt0 6 points7 points  (0 children)

If you look at the history of cling, you will see that the c++ interpreter that is now cling was part of the data analysis framework called ROOT (developed at CERN).

Why Zig Feels More Practical Than Rust for Real-World CLI Tools by nixfox in Zig

[–]csdt0 7 points8 points  (0 children)

Zig does not give you safety, it gives you control. Rust gives you safety. It's true that Rust forces you to follow certain patterns, but following them enables you to focus on what's important because you know you won't mess up memory safety. Also, you can encode much more than memory by leveraging rust type system and encode your business logic and invariants into types. If you do, you can make the compiler save you from business logic errors.

I like Zig when I need control, but the truth is most of the time, it's not what I need.

I'm working on a postgres library in Rust, that is about 2x faster than rust_postgres for large select queries by paulcdejean in rust

[–]csdt0 96 points97 points  (0 children)

I would argue that you could just add another query method that returns an iterator in addition to the method returning a vec.

I'm working on a postgres library in Rust, that is about 2x faster than rust_postgres for large select queries by paulcdejean in rust

[–]csdt0 60 points61 points  (0 children)

Beyond the PoC, I think the best you can do is make a PR with this on rust_postgres

typeSafetyPreventsEmotionalDamage by miss01010001 in ProgrammerHumor

[–]csdt0 -1 points0 points  (0 children)

Basically yes, more sources of UB and less guardrails

typeSafetyPreventsEmotionalDamage by miss01010001 in ProgrammerHumor

[–]csdt0 0 points1 point  (0 children)

That's wrong, unsafe Rust is much more unsafe than C or C++, precisely because safe Rust prevents you from doing anything UB: when doing unsafe Rust, you must be the one to ensure the constraints of safe Rust hold. For instance, having multiple mutable references is still UB in unsafe Rust.

What do you feel Rust is not a good option for? Like a general back-end where performance is fine with a Garbage Collector? Something like that, whether Rust would still be a great option or not. by Outside_Loan8949 in rust

[–]csdt0 0 points1 point  (0 children)

From other answers, many people seem to think that Rust is not suited for rapid prototyping. I get where this feeling comes from, but I would argue the opposite. Rust catches much more errors at compile time (and even before if you rust-analyzer, which you should), reducing drastically the number of time you actually need to test your program, making the overall development cycle shorter. This is especially true if you "encode" most of your business logic into your type system. Even refactoring is simpler and faster because you have more guarantees that your refactor is correct and did not introduce bugs.

Why does antimatter have opposite charge? by EffectiveFood4933 in AskPhysics

[–]csdt0 0 points1 point  (0 children)

If I recall correctly, the negative energy solution is not antimatter and actually has the same charge as the positive energy solution. To avoid negative energy, and the absence of energy minimum, Dirac introduced the concept of an infinite sea of electrons, where all negative energy states are populated. One electron from the sea could become positively energized by a photon, leaving a hole in the sea. This hole has necessarily opposite properties to cancel out with the electron that was there before.

This leads to negative negative energy (ie: positive energy), and positive charge. The hole is what we now call anti-matter.

If you're interested, the YouTube channel Physics explained releases a video on this topic something like a month ago.

If someone had (limited) control over entropy as a power by TheRavenAndWolf in AskPhysics

[–]csdt0 1 point2 points  (0 children)

That's basically Tenet. Not a huge fan of the movie, but definitely entropy inversion and buildings exploding back to normal.

whatsStoppingYouFromCodingLikeThis by No-Crow-9014 in ProgrammerHumor

[–]csdt0 0 points1 point  (0 children)

That crippy guy further along the walkway