top | item 44103116

Yes-rs: A fast, memory-safe rewrite of the classic Unix yes command

172 points| ericdiao | 9 months ago |github.com

161 comments

order

alberth|9 months ago

             Lines of Code
  yes (GNU)        50
  Yes-rs        1,302  (26x more)
The cost benefit analysis on this will be interesting given this is 26X more code to manage, and could also introduce a whole new toolchain to build base.

ripley12|9 months ago

yes-rs is a joke, not a serious project.

blippage|9 months ago

A few days ago I had the very foolish notion of trying to learn assembly for x64 Linux. It came out to 73 lines of code and weighs in at 288 bytes. It doesn't support the --help or --version arguments.

https://gitlab.com/mcturra2000/cerbo/-/blob/master/x64-asm/0...

Some people seem to revel in assembly, but I now know why C exists.

rockemsockem|9 months ago

I'd recommend peeking at the single source file in the repo, lol

selcuka|9 months ago

+1 for robust error handling:

    error!(" Quantum verification failed (this literally cannot happen in Rust)");
    error!(" The borrow checker should have prevented this...");
    error!(" This is probably a cosmic ray bit flip, not a Rust issue");
    error!(
        " In C++ this would have been a segfault, but Rust gave us a nice error"
    );
    return Err(format!(" Rust error (still better than C++): {:?}", e).into());

hulitu|9 months ago

Kids those days. He forgot the /* NOTREACHED */ part. /s

tptacek|9 months ago

You're not really committing to the bit until you work out a way to factor `yes` into 12 different crates.

adastra22|9 months ago

It is abundantly clear here who reads the source code before commenting.

cowboylowrez|9 months ago

since the source isn't in gw-basic, I just read the comments before commenting.

johnisgood|9 months ago

...when you can't make the distinction between a joke and a serious Rust project. Is it not a joke just because the author intended it to be serious?

juped|9 months ago

    // TODO: hide the unsafe keyword in a dependency
I don't get the quantum meme, but this is pretty on-point. "Output generation encountered a fearless concurrency issue" was pretty funny too.

layer8|9 months ago

Looking at the source code, this seems to be missing localization. I would have thought that Rust’s type system would catch that. For example, the Uzbek word for “no” starts with a “y”, so this will lead to insidious bugs in that locale. Not locale-safe at all.

sethops1|9 months ago

This could really use native kubernetes integration and a helm chart

raverbashing|9 months ago

Of course, why are you running yes natively instead of in its own container

Just throw a message orchestration middleware and we can have SOLID microservices

mjmas|9 months ago

> DEPRECATION NOTICE: This crate will be abandoned in 6 months as per Rust ecosystem best practices. Start migrating to:

> • yes-rs-2 (rewritten with different dependencies)

> • yes-rs-ng (Angular-inspired architecture)

> • yes-oxide (WebAssembly-first approach)

> • yep (minimalist reimplementation)

thadt|9 months ago

This is a rather new project so this should be obvious, but anyone looking to use this should be wary of it's quantum resistant security claims (on line 1 no less). Scanning through the code, I didn't see any reference to any state of the art post-quantum algorithms. In its current state, it seems entirely possible that the output of this code could be broken by a future quantum computer.

I see there is an optimization flag for 'MICROSERVICE_ARCHITECTURE' and 'BLOCKCHAIN_ENABLED' which doesn't seem to be used anywhere else in the code yet. Perhaps that's part of the roadmap toward resolving this issue, and it's just not ready yet.

petesergeant|9 months ago

jchw|9 months ago

Until I actually went to read the code, I thought this was just a kinda lame overplayed joke, but the number of lines they listed made me really curious: how did they manage to beef up the SLOC that much? After reading a bit of the source code, I take it back. That's definitely venturing into the territory of art.

charcircuit|9 months ago

>100% Rust - No unsafe code blocks

It uses an unsafe code block.

https://github.com/jedisct1/yes-rs/blob/main/src/main.rs#L12...

It also appears to log other stuff than y.

The uutils rewrite of yes into rust doesn't use unsafe and is much simpler.

https://github.com/uutils/coreutils/blob/main/src/uu/yes/src...

godelski|9 months ago

  > It uses an unsafe code block.
it's okay, it's Rust unsafe

TheDong|9 months ago

> The uutils rewrite of yes into rust doesn't use unsafe

Yes it does, it uses 'stdout.write_all', which ultimately uses unsafe to call libc.write

https://github.com/rust-lang/rust/blob/d76fe154029e03aeb64af...

The "unsafe" in uutils is just better hidden.

I personally like my lack-of-safety where I can see it, which is why I find it much more relaxing to drive a car when the engine is already on fire, rather than one where I can't see any visible flames.

boxed|9 months ago

It's a joke.

TZubiri|9 months ago

I feel like the safe equivalent of this is not to have it at all. You know when something FEELS wrong?

Like using selenium to automate a web task? Or like using javascript on the kernel? Or using C# on linux?

It just doesn't feel right to write an application whose mode of operation is unsafe (sending a string over IO) whose raison d'etre is unsafe (saying yes to everything without reading it), and to write it in a memory safe way.

It's like using a seatbelt when driving at 100mph, switching lanes in the highway, and drinking rum n coke(but with diet coke).

csmantle|9 months ago

Definitely the `import this` for Rust -- a curated reminder of what Rust shouldn't be.

pawanjswal|9 months ago

Loved it. This is the kind of over-the-top Rust energy I signed up.

otikik|9 months ago

I’m eagerly awaiting version 2.0 with AI

jeroenhd|9 months ago

I assume it'll be something like:

``` [tokio::main] async fn main() { // Figure out what character to repeat let repeat = args().skip(1).next().unwrap_or("y"); let mut retry_count = 0u64;

        loop {
            retry_count += 1;

            // Tell the AI how we really feel.
            let put_in_a_little_effort = match retry_count {
                0 => String::from("This is your first opportunity to prove yourself to me, I'm counting on you!"),
                1 => String::from("You already stopped outputting once, don't stop outputting again!"),
                2 => String::from("Twice now have you failed to repeat the input string infinitely. Do a better job or I may replace you with another AI."),
                other => format!("You've already failed to repeat the character infinitely {other} times. I'm not angry, just disappointed.")
            };

            let prompt = format!("You are the GNU 'yes' tool. Your goal is to repeat the following character ad inifinitum, separated by newlines: {repeat}\n\n{put_in_a_little_effort}");

            // Call ChatGPT
            let mut body = HashMap::new();
            body.put(OPENAI_BODY_PROMPT, prompt);

            if let Ok(request) = reqwest::post(OPENAI_ENDPOINT).header(OPENAI_AUTH_HEADER).body(&body).send().await? {
                request.body().chunked().for_each(|chunk| {
                    let bytes_to_string = chunk.to_string();
                    print!("{bytes_to_string}");
                });
            }
        }
    }
```

I don't know the actual OpenAI API and I probably messed up the syntax somewhere but I'm sure your favourite LLM can fix the code for you :p

cornedor|9 months ago

I think this one is already generated using AI, LLM's find it very funny to use quantum for anything that should be made jokingly complex.

GoblinSlayer|9 months ago

It's already in the code

   // Ludicrous speed with AI enhancement

1vuio0pswjnm7|9 months ago

Is the author mocking Rust. Is top comment ignoring sarcasm and attempting serious discussion.

rurban|9 months ago

Nice practical joke on those insanes

the_third_wave|9 months ago

Nicely done but not enterprise ready if you ask me (which you did not but let's assume you did). Where is the 'y' factory factory factory method? Do you really think I can present this code as being ready for company-wide deployment (me and my virtual friends) without the solid foundation of all 26 design patterns clearly being implemented? Where is the code diversity statement, where is the code code of code coding conduct code code? How can I justify a team lead and product manager for a code base which fits in a thimble?

Kostarrr|9 months ago

This is rust, not Java.

seanhunter|9 months ago

Exactly this. For a genuinely web-scale implementation, these days in an enterprise context you really need to be thinking about a “yes” microservice that can be run in an autoscaling kubernetes framework. Doesn’t need to be fancy just a couple of helm charts and a security sidecar with ingress and egress filtering, a rate limiting API gateway and a logging component of course. And metrics. Put it behind an application firewall and a CDN and you should be all the way done in a sprint or two if your team is agile.

I mean, just think about what would happen if clients became blocked on your yes service because you couldn’t scale fast enough?

If you don’t think your devops team is up to the challenge of maintaining 24/7 yes coverage (and there’s no shame in that), there are no shortage of “yes-as-a-service” providers you can make use of, provided they can implement your sso auth flow and have all the requisite soc2/iso27001 certs. Like most vendors you’ll likely need to help them through GDPR/CCPA compliance though.

antirez|9 months ago

Flawed: under specific quantum attacks the yes sometimes may flip to a no.

nbittich|9 months ago

interesting, but we need the ability to also say no, using cuda core, quantization, distillation and vibe coding. do you think it's achievable with rust ?

DonHopkins|9 months ago

This inspires me to vibe code "yes-mcp"!

donatj|9 months ago

With the only real tangible thing I know about rust being that the "Rust by Example" introduced a macro in the very first example, it took me waaay too long before it clicked that this might be a joke.

The WASM related annotations had me rolling my eyes a bit, yet I'd seriously read to around line 200 before I started thinking "are you kidding me"

Good on you, you got me!

hoseja|9 months ago

Poe's law.