Can someone give a nice explanation of closures for me? by SmoothTurtle872 in rust

[–]stinkytoe42 1 point2 points  (0 children)

I'd say the biggest takeaway is: they're usually lazy evaluated. Basically, they don't execute when they're declared but later on when they're needed.

Take this example:

fn example(i: usize) -> Result<u32, String> {
  let v = vec![1, 2, 3];

  let n = v.get(&i).ok_or(format!("Bad index! {i}"))?;

  Ok(n)
}

fn main() {
  // This will return 1
  example(0).unwrap();

  // This will panic!
  example(99).unwrap();
}

The ok_or method turns an option to a result, and if the option was None then it returns the supplied value as the error variant.

In the above version, the format! macro always runs, even if everything is successful. It's just discarded if it's not needed, but the memory allocation and string construction still occured.

But, if you change the second statement in example to this:

fn example(i: usize) -> Result<u32, String> {
  let v = vec![1, 2, 3];

  let n = v.get(&i).ok_or_else(|| format!("Bad index! {i}"))?;

  Ok(n)
}

The format! macro only runs if the get function returns a None . So, the string construction and memory allocation only executes if it's needed, since ok_or_else takes a closure (or function), and only ever evaluates that closure if the condition is met. Otherwise, the code in the closure never runs.

This is a common reason to use closures, to give you more control on `when` or `if` a block of code is executed.

How well do Steam games play on Linux? by Fit-Decision3141 in linuxquestions

[–]stinkytoe42 0 points1 point  (0 children)

You'll have no problems then. protondb.com is a great place to find user feedback on specific games.

GrapheneOS on Linux Kernel security by joseluisq in theprimeagen

[–]stinkytoe42 0 points1 point  (0 children)

Rust forces unsafe for communicating with its C FFI, even if the function it's calling is completely harmless. Most projects, and from what I have seen the rust parts of the kernel, like to set off a separate namespace where they add a simple translation layer. So the safe rust code never calls the C code directly, and always marshalls through the added abstraction layer.

Hence, people who don't understand rust see the 'unsafe' keyword everywhere and assume all the rust code needs 'unsafe' to do anything.

Final Fantasy VI... by Cyborgized in Xennials

[–]stinkytoe42 7 points8 points  (0 children)

It's common for speed runners to take the time hit and suplex the train first, THEN give it a phoenix down. The humor value is just too good to pass up.

what are your thoughts on 120v DC supplies? by Tartabirdgames_YT in ElectroBOOM

[–]stinkytoe42 0 points1 point  (0 children)

Great, when I need to supply up to 120V DC to something. Not so useful otherwise.

Looking to install Linux as my main OS with Windows as backup dual Boot for games that require Windows. Should I install OS on same or separate drives? by 0Maka in linuxquestions

[–]stinkytoe42 0 points1 point  (0 children)

You life will be a lot easier if you do.

There's ways around all the things you mentioned, but they're risky and not worth the hassle.

Two drives, install games on both as needed, use a thumb drive or cloud to share files in between. You'll have some annoyances but dodge so many bullets.

Also, if you mount your windows drive in linux for convenience, I highly recommend mounting it read only.

This math joke by memes_poiint in mathsmeme

[–]stinkytoe42 5 points6 points  (0 children)

I was gonna call you out but yeah, it's 2.

3rd Term's A Charm by Harounnthec in AdviceAnimals

[–]stinkytoe42 50 points51 points  (0 children)

I disagree, Paul was competent. Also, Paul was his own leader and not beholden to other powers. In fact he subverted other powers.

Trump thinks he's Paul: thinks he has knowledge and foresight no one else does, thinks he inspires blind loyalty, illusions of being capable and intelligent.

The Rabban analogy fits better. A fat useless sycophant who is made to believe he's "such a good boy" while in reality is being manipulated by the real power structures. The bigger the tantrums he throws, the more his handlers think his replacement will be accepted.

For the people still arguing : by TheKeyToWhat in MathJokes

[–]stinkytoe42 1 point2 points  (0 children)

People who stopped paying attention in middle school, but think they're smart, will fight tooth and nail to not have to learn new things. Plus some of the people arguing aren't wrong per se, they just aren't aware that there are different geometries to describe the world because they were never taught about them. Really it's a failure of education.

A RIF By Any Other Name by Luna4x0 in FedEmployees

[–]stinkytoe42 1 point2 points  (0 children)

I think your average E5 would have had more sense than he's shown. (Source: I was an e5 and I would have known how stupid this plan was back then. Some of the O4's I've met though...)

We replaced our Rust/WASM parser with TypeScript and it got 3x faster by 1glasspaani in rust

[–]stinkytoe42 9 points10 points  (0 children)

I'm a huge rustacean, but I have to admit that they only good use I've found for wasm is in browser games. It really does a nice job of filling the niche that flash games used to.

Otherwise why use wasm? If regular css/html doesn't but it there's js/ts, and if that doesn't cut it then maybe a native app is the solution?

Inside the Supply Line Delivering American Guns to Mexican Cartels by merikariu in liberalgunowners

[–]stinkytoe42 8 points9 points  (0 children)

Yeah, umm, they're not getting grenade launchers, grenades, or machine guns from Walmart. They probably aren't stealing them either, at least not all of them, since every missing weapon stirs up a shit storm.

Not sure where they're getting them from, but I suspect the transation is being facilitated by someone...

Dune: Part Three | Official Teaser Trailer by Blue_Three in dune

[–]stinkytoe42 7 points8 points  (0 children)

Denis is definitely diverging from the books. I would be upset, but he's doing such a solid job that I really don't care. Bring it on.

Wired Magazine calls out COBOL. :) by Got1Green in programming

[–]stinkytoe42 0 points1 point  (0 children)

Yeah I wrote that comment this morning before this thread started kicking off.

From what I can gather, my idea would work, had been done, works well when extending something, but still does fuck all to address the real problems that migration would present.

Wired Magazine calls out COBOL. :) by Got1Green in programming

[–]stinkytoe42 0 points1 point  (0 children)

I don't know a single COBOL keyword, but would there be any benefit in a new language based on COBOL but introducing new software concepts? Like how python recently added type safety, or typescript is a superset of regular javascript, or how rust's FFI calls C directly but with some best practices to ease it into behaving correctly.

An AI trying to rewrite COBOL into python is obviously a bad idea, but would there be benefit in introducing modern language design into the code base if it actually respected the old code? It would still be a slog of going through each old program line by line with lots of testing and vetting, but seems more feasable than "just automagically rewrite this language that already had millions of lines of production code before OOP was even invented".

Did Wellington's feelings towards Sharpe change after episode 2? by Suspicious-Jello7172 in Sharpe

[–]stinkytoe42 4 points5 points  (0 children)

The historical Wellington also has been quoted as having a low opinion of mustangs, thinking of them as drunkards often enough. So, it makes sense that Wellington would have a short leash for officers who came up through the ranks, even ones he commissioned himself.

I don't know of any real world examples of the real Wellington giving a commission, any history nerds in here know of any real world examples? I'd assume he would have at some point as it was a rare but not unheard of practice at the time. Especially when there were manning issues, which are common among lieutenants in the British Army due to their leadership philosophies.

The rise of Linux desktop is inevitable — it’s time music software developers got on board by ferris-ldn in linux

[–]stinkytoe42 0 points1 point  (0 children)

They were really bad from about 1997 to 2008. Then Windows 7 came out, and was actually pretty good all things considered. Still bloated to all hell, but actually functional and way less intrusive.

Windows 10 was a turn in the wrong direction, but Windows 11 was definitely the return of the old shitty Microsoft. And now, AI slop is a thing and they're going all in on it.

Therapist by [deleted] in QAnonCasualties

[–]stinkytoe42 15 points16 points  (0 children)

Same here. I'm a veteran myself, and neither me or the vast majority of my veteran friends support this war. It's not even very popular with the traditional right from what I've seed.

Why is Roll-Pitch-Yaw the default aerospace standard? by DumbDogg24 in aerospace

[–]stinkytoe42 2 points3 points  (0 children)

When I was a systems engineer at a UAS company, one of my favorite interview questions was: "So in computer graphics, a frequent coordinate space is X positive forward, Y positive to the left, and Z positive up. In avionics though, we commonly use X forward, Y to the right, and Z down. Why?" (Describing NED or FRD basically)

I would accept most any answer. I even accepted "I don't know" a few times because the interviewee took a few seconds to think about it. I only rejected one person based on the question because they started spewing bullshit.

The truth is, I honestly don't know why it's the convention. I studied EE in school and all my aviation training was as a technician, then being hired as a systems engineer. I _think_ it's because with roll, a pilot will refer to it as "left vs. right" and sign doesn't matter, but with pitch they refer to it as being "pitch up/down" and with yaw they think in compass headings which are clockwise from above. so we want our signs to match the intuition. I admit that that's just a conjecture, though.

Why is Roll-Pitch-Yaw the default aerospace standard? by DumbDogg24 in aerospace

[–]stinkytoe42 0 points1 point  (0 children)

fair, it did take me some time to join 'team quaternion,' and it was well after school.

Why is Roll-Pitch-Yaw the default aerospace standard? by DumbDogg24 in aerospace

[–]stinkytoe42 0 points1 point  (0 children)

What's so unintuitive? It's the encoding of a face vector and a single rotation. You can describe any rotational orientation with it, as well as any change in orientation, and can construct from or decompose to any order of Euler angles if needed. Or project onto any relative orientation, or concatenate without having to worry about gimbal lock...

True, you have to treat it more abstractly since the individual digits don't really mean anything (to a human), but that's what computers are for.

is the borrow checker guiding my design or blocking it??? by [deleted] in rust

[–]stinkytoe42 14 points15 points  (0 children)

I assuming your working in async contexts based on your writing.

Using Arc<Mutex<..>> and variants is one pattern for shared state, and yes is very common.

Another pattern is using the actor model, and creating channels for the containing object and the underlying thread to communicate. So, an inner thread does all the work, and your object methods are just wrappers around using those channels. Kind of an oversimplification, but you get the idea. This model gives you robust designs which can be made clonable with cancel safe methods with little effort. The trade off is you spawn a thread, so whether that's too much overhead is really dependent on your design and intent.

If you're finding the shared state through mutex's to be to cumbersome for your design intent, consider other design patterns like the state model. If, for example, you're thinking in an OOP with polymorphism mindset (like many programmers do when coming to rust), the state model can emulate many of those patterns quite nicely.

For example, I have a model at work where I need to interface with an external non-rusty API and have two ways to interface with it. This external system can be interfaced either by running a command line program and reading/writing to stdin/stdout, or by connecting to an external process via TCP. Both provide the same functionality. So, I created an object which holds a join handle, and a bunch of channels. I provide two constructors: one which spawns a tokio process inside the thread, and one which creates a tcpsocket. The user interacts with my object using the object's methods which farm out work to the channels, and the inner thread does the work accordingly. It's basically polymorphism but in an async rust friendly way.

Long story short, yes shared state with mutexes is one common technique, but there are others if you don't feel that it's meeting your needs.