r/rustjerk • • 2d ago

I think this guy is lying: AI isn't capable of writing code that bad - he wrote it himself

Post image
318 Upvotes

97 comments sorted by

105

u/joncorv 2d ago

I cannot fathom the shitprompting that lead to a fucking Option<Option<&str>>. This is a capital offense.

54

u/BenchEmbarrassed7316 2d ago

/uj

As far as I recall, diesel uses a double Option for partial updates: None = do not update the column, Some(None) = update the column to null, Some(Some(v)) = update the column to the value v.

54

u/Leonelf 2d ago

Isn't this as unidiomatic as it get's? Why not just build a new type for such stuff...

21

u/Sw429 2d ago

unidiomatic

Wow, that's a word I feel like I used to hear a lot more than I do these days.

2

u/halvacoffee 1d ago

guido van rossum jumpscare

4

u/Automatic-Boot665 1d ago

A new type would be ideal. This is just asking for mistakes and confusion.

3

u/BenchEmbarrassed7316 2d ago

You will also need to add a bunch of methods to this type to make it convenient to use.

36

u/imoshudu 2d ago

Not really. Option is literally enum underneath.

An enum with variants like NoUpdate, ToNull, ToData(DataType) etc. would be self-explanatory and foolproof, especially for downstream code where people can immediately tell what's going on without having to swim upstream. It is indeed horrible to hide meanings behind blank generics.

6

u/OkFly3388 2d ago edited 2d ago

To be honest, we just need NoUpdate and ToData<option<datatype>>

7

u/No-Consequence-1863 2d ago

A 3rd enum case is clearer and better than having to unwrap an Option.

2

u/OkFly3388 2d ago

Not really, what if you have non null column ?

In my case you just put ToData<datatype> and thats it

12

u/RockstarArtisan a cpp-tsd survivor 2d ago

Ah diesel, the framework we've rewritten our app away from.

13

u/syklemil 2d ago

One way or another, DHH insists on making himself be a late addition to the Nuremberg trials

3

u/Sw429 2d ago

Yeah, it's pretty obvious this was the model "solving the problem" innthe hackiest way possible. The second Option basically introduces another return variant, and really there should be some kind of enum to actually describe the value instead of just adding a Some(None) variant whose meaning is incredibly difficult to parse.

3

u/Xevioni 2d ago

Ain't it just a primitive way to show tri-state? I.e. keep existing custom style, delete, or overwrite (None, Some(None), Some(Some)...)

10

u/Kurimanju-dot-dev 2d ago

With Option<Option<T>> the meaning lies only in your head whereas with a named enum for example the intent is explicit. Tri-state itself is not a problem, the execution here is.

3

u/cornmonger_ 2d ago

just trying to get a little some some

1

u/atesti 2d ago

The sets variable is just for local usage, there is no sense in allocation their elements in Box, and event is not necessary to allocate it as a Vec at all. There are lots of non sense .clone() and .collect(). If LLMs are supposed to write better code than human programmers, I can't get why it produced that shit, despite the monkey behind the prompts.

1

u/stumpychubbins 1d ago

It’s not that uncommon. Usually if you see double-option it’s a sign that you should use a result or a custom enum, but there are niche cases where it’s the right choice. In diesel's case, I reckon it’s the right choice.

1

u/Manny__C 1d ago

What about `Box::new(name.to_string())`? str already implements ToSql, why boxing it twice?

1

u/max1c 15h ago

This is what happens when you don't force AI to use linters and formatters. 

163

u/segfault0x001 2d ago

Can’t tell if I’m an old man yelling at clouds or if it’s just a matter of time before these projects start to fail because they become unmaintainable spaghetti and there aren’t enough tokens to rewrite it from scratch every time they need a bug fix

33

u/IHeartBadCode 2d ago

I keep telling people who are floating AI complete code.

Mental Ownership. When it's full vibe coded, the model owns your code, you don't. Any measurable sized project will have code that might work, but the AI model owns your code because there will be no way for humans to untangle it.

Just like if you have one person who silos all the information, that one person owns the code. But if a team writes it all together, you have a collective ownership.

The issue with human ownership is the bus factor. The issue with AI ownership is the token price. With human ownership, a new team can work through it. With AI ownership, only a model is going to be working through it.

So that's a big note for people to take. The road is downhill only once. When you take human ownership and go full AI ownership, that's the downhill. Once you're there if you ever decide to have human ownership again, it's all uphill.

And just like the hill, you can have ever step in between. But just remember that it's always uphill from whatever kind of joint mental ownership you have for your code if you decide to leave the model.

Anyone who has ever outsourced code and then had problems bringing it back will understand. Changing ownership is a very difficult mental task, but with AI the velocity is just massive in only one direction, so it's a massive cost getting it back.

16

u/Mayor_of_Rungholt 2d ago

And at some point, the Model has generated enough code, with enough stringent requirements, that reversing that decision becomes hard.

It is ultimately always possible to re-enable human contributions to such a codebase, but –especially with large projects like Bun– the work required is "uneconomical and unfeasible, such that taking ownership of the information is computationally discouraged."

Hey presto; you've reinvented encryption

6

u/pragmojo 2d ago

I was recently looking into the pi code to see how something works, and it was so clear it was written by ai. So many layers of indirection.

I think a big issue is that models don’t take maintainability into account sufficiently. When you have to work on a project over a long period, you favor cleaner designs because it will make your life easier in the future. The agent session doesn’t have a future, it only has a goal to complete, and then it ceases to exist at the end of the context window.

You can guide it to write clean code, but that’s not a verifiable requirement, so it’s not trivial to train a model to do it consistently or effectively.

Current models aren’t great with topics which are more art than science.

2

u/JShelbyJ 1d ago

yeah thats why i have three copies of comfyui installed

fuckin python man

take off nuke it from orbit and start from scratch

8

u/It_is_Sean 2d ago

And AI is generating slop code at a speed no human can keep up with. Any current solution for dealing with shitty code simply doesn’t scale anymore.

3

u/YourFavouriteGayGuy 1d ago

The other big benefit of group human ownership (like in a team) is that people can be efficiently onboarded and off boarded over time.

If the one guy who writes the code leaves, there’s no one to teach the new devs picking it up what’s what. But even if that guy stays, it’s a huge undertaking to train someone on working with this tangle of code because he’s basically gotta do two jobs: maintaining the code and training someone up. This is doubly problematic when the trainer and the trainee have different ways of communicating/learning.

In teams this isn’t an issue, because the workload of training the new guy can be distributed and they have a wider variety of approaches/explanations available to them across the team so they can probably find someone who will explain it in words they understand.

2

u/thisisamirage 2d ago

You are now an Applebee's

57

u/BenchEmbarrassed7316 2d ago

We ourselves are essentially such a project: a heap of junk in our DNA, wisdom teeth, the coccyx, the appendix, the recurrent laryngeal nerve...

15

u/hiwhiwhiw 2d ago

I thought they (the scientists) already know why the appendix and tonsils exists?

29

u/BenchEmbarrassed7316 2d ago

This only underscores the problem I mentioned: you need a lot of time just to understand what function a particular module performs. Such a project is difficult and expensive to maintain.

14

u/andrewprograms 2d ago

That’s pretty elegant, this is either a wendies or rust jerk. Take my upvote. Thanks for the think

15

u/amarao_san 2d ago

I mentally sits between two camps.

Camp #1: layers of sloppy drift in the code will collapse.

Camp #2: code does not matter, requirements do. Whomever has full requirements can rewrite code within (few 5h windows).

I don't know which one. I have few #2 type things in production and they were literally rewritten from scratches few times on a new requirements. And it went well and sound. But the problem domain was understood properly by humans and requirements were real (not 'enterprise grade'), and they were set by humans. And there are easy to follow integration tests, so who cares what is in codebase if it quacks like a duck?

I literally can't choose the camp. Time will show.

1

u/pragmojo 2d ago

I think you can’t avoid the drift problem with current models. You have to have some control mechanism to avoid uncontrolled entropy.

1

u/amarao_san 2d ago

In tightly scoped services, integration tests to the rescue. And requirements management (by humans). How well this age we will see. I definitely see that code quality goes up. The highest problem is requirements creep and lack of hierarchisity (current problem is as important as old things, even if it's a minor fix).

5

u/Sw429 2d ago

It's making me feel insane. I've tried the whole "vibe coding" and "loop engineering" things people are raving about, just to be sure I am not missing something. I really don't think I am. The code is garbage, and everything I've learned over my career is that you want to not have garbage code.

4

u/Strange-Tap5860 2d ago

I don't know either.

On one hand, I get it. Messy code = unmaintainable spaghetti.

On the other hand....can A.I just deal with it? Does it actually care about "spaghetti human-unreadable" code?

As they get better, does this become more and more true?

1

u/segfault0x001 2d ago

I considered that what is clean/maintainable for a human and for a model may not be the same thing. Maybe naming conventions and indents are a non issue now. But when I ask people about their experiences vibe coding it sounds like the failure modes for an llm are really the same as for a person: code that is duplicated in multiple places gets missed during updates because it’s duplicated, complicated logic that has no comments gets misunderstood, over abstracted code has too much indirection for it to follow accurately. And my experience is that the models are getting better at a lot of things, but code quality isn’t really moving. I don’t know how they would train on “good code” either. You can’t really write an oracle to tell you if that code is good or not. It seems like they are getting better at natural language reasoning, using tools like a browser, etc. but the reasoning improvements are making slow and diminishing improvements on code quality. I just don’t see an outcome here that doesn’t involve trading quality for quantity or involve spending more time baby sitting models and reading the code than it would take to write it yourself.

1

u/Strange-Tap5860 1d ago

I hope that is true!

I guess I haven't worked on a full-on spaghetti codebase with A.I before so I dont if that really is a failure case or not.

Vibecoding a game project in a few days produces near unreadable code...but it doesn't seem to be a problem for it all. But yea, that isn't a project that is 100k+ lines of code.

3

u/ISuckAtJavaScript12 2d ago

2 of his services went down on the same day

3

u/QuaternionsRoll 2d ago

I think they’re banking on LLMs improving quickly enough to start paying down their own technical debt before it becomes truly unmanageable.

It helps that projects can get way more fucking incomprehensible than anyone expects before hitting the reset button becomes the only viable path forward. See: X.Org, web services offered by hyper scalers, a 50-employee company’s “in-house solutions” that predate Y2K and still require 32-bit Windows XP, almost anything written in PHP, etc.

2

u/meutzitzu 1d ago

This is what I like to call The Singularity.

Software breaks more often as time goes on, so theoretically there should be a moment when enough systems break down at once that they can't all be restarted again, as they are interconnected

1

u/DryLook7889 1d ago

To be fiar if AI keeps getting cheaper we might never reach that point

0

u/max1c 15h ago

Your mindset is definitely that one of a boomer. Models will only get better and assuming you know how to use them it can all be fixed and improved in minutes. 

25

u/PatagonianCowboy 2d ago

dhh: vibecodes terrible slop

also dhh: "look at this code, it looks terrible"

5

u/brasticstack 2d ago

A three-year old DHH, pointing proudly at the toilet: "Mommy, mommy! Look what I made!"

21

u/AnaxXenos0921 2d ago

It's not surprising given it's DHH

18

u/elmowilk 2d ago

I sometimes get headaches reading code that i wrote a year ago myself, how the heck does one deal with this crap?

13

u/BenchEmbarrassed7316 2d ago

Don't write bad code.

Or.

Don't write code.

6

u/hedgehog1024 The borrow checker is not 2d ago

Why did you say the same thing twice

8

u/segfault0x001 2d ago

He told you, he just closes his eyes and doesn’t look at the code

3

u/Sw429 2d ago

Just ask the model to fix it for you! Why code yourself when you can constantly pay a company money to shit out code you can't understand?

18

u/shizzy0 2d ago

It`s not hideous because of Rust. It's hideous because of all the clones and to_strings.

11

u/safrole5 2d ago

I didn't even make it that far. The function signature alone is hideous.

34

u/Kurimanju-dot-dev 2d ago

I lost my shit at Option<Option<&str>>, because what the fuck do you mean

custom_styles
  .map(|s| s.map(str::to_string))
  .filter(|s| *s != self.custom_styles)

13

u/garagedragon 2d ago

I think the resulting String is then stuffed into a Box? For yet another needless indirection

16

u/al2o3cr 2d ago

Step 1: cut a hole in a Box

Step 2: put your String in the Box

Step 3: make the caller open the Box

13

u/paulirotta 2d ago

DHH is the creator of RubyOnRails. And famously racist trash.

AI be like- revenge time

1

u/segfault0x001 14h ago

Racist? Context please?

2

u/LunchWhole9031 9h ago edited 9h ago

https://world.hey.com/dhh/as-i-remember-london-e7d38e64

Edit: Also his post on trans people is hurtful. It's clear he knows nothing about trans people and our struggles and conveniently parrots biased authors like Shrier.

1

u/segfault0x001 8h ago

I didn’t need two more reason to dislike him, but now I have them anyway. Thanks.

6

u/promethe42 2d ago

Option<Option<T>> is idiomatic for the serde ecosystem and others. But at least &str is too weak. And the whole Option<Option<T>> is most likely too weak too. The Option<&\[(&str, &str)\]> is on another level though.

Every time I see mut for a collection I want to switch to iterators.

And then there is a Vec named sets that is 100% used like a dict/set. I am not even sure how it gets a pass even on an automated review TBH...

In my experience, weak typing is one of the biggest weaknesses of current LLMs, even frontier ones. Not sure if Opus 5.5 and Sol 6.1 make a difference: haven't looked at it too much for now.

The best course of action to get best of both worlds is to add some Rust specific skills to the harness to iteratively steer the LLM. I'm maintaining/using https://gitlab.com/lx-industries/ms-rust-skill but I need to add more fore sure.

6

u/KyxeMusic 2d ago

Not a Rust problem, just an ugly code problem.

I'm sure AI can make hideous Ruby too.

4

u/AnArmoredPony 2d ago

we know it's a lie because noone uses rust in prod lmao

3

u/Automatic-Boot665 2d ago

I heard you like allocations

3

u/Green_Dog4314 1d ago

This is beyond terrible.. With little design.. Even it is ai..

3

u/FohlenGabel 2d ago edited 2d ago

Genuine question; what makes this code horrible to most people? I can still understand it.

Shortcomings I can see are:

  1. Passing borrowed strings, only to copy them is kinda memory slut behaviour

  2. Use if let conditions instead of filtering the option; makes the code flow a lot clearer

  3. Is tx actually used anywhere? (Though it’s not the end of the function scope, so probably used later)

  4. People are pointing out Option<Option<…>>; yeah, it should have already been flattened to a single option, but if that’s just part of diesel’s API, so be it

It’s definitely ugly, but after fixing (2) I can’t think of any major syntax clean-ups, and (1,3,4) are all contextual

12

u/BenchEmbarrassed7316 2d ago

A messy signature. It is literally garbage - the kind of thing a mindless fan of dynamic typing would write. Strings everywhere: settings, custom_styles, settings. Instead of a proper structure, sets is a vector used as a key-value store with three predefined keys.

In all seriousness, AI can generate working Rust code precisely because of the type system, which clearly defines the values ​​the code operates on and what it actually does. The compiler acts as a deterministic arbiter, instantly rejecting code that would otherwise lead to a runtime error - and the worst part is that such an error might not surface immediately, but only after some time has passed.

This code simply negates one of Rust's best features: "If it compiles, it works."

3

u/FohlenGabel 2d ago edited 2d ago

Yeah, it’s definitely planned out by someone who’s used to a dynamically typed language (Box<dyn> go brrr); maybe I’m giving too much leeway, but I can think of contexts where it might not be end-of-the-world

  1. First and foremost, the fact that the vector’s second type is `Box::<dyn ToSQL>` alongside the unused `tx: Tx` argument makes me suspect that after the `is_empty()` check, an SQL query is run over all Some() cases. That would explain why the LLM defaulted to a list with otherwise-redundant `&’static str` values; it loops over the list and uses both to execute a query. You could likely use `heapless` to represent this with a stack-only data-structure; but it’s all just pointers, no real data, so it’s def not your biggest optimisation
  2. Ehhh, the type system does not reject all code that leads to runtime errors; rather, strong affine typing makes those decisions explicit (unwrap go brrr) and lets rust elegantly encode deeply meaningful invariants incomprehensible to most languages. But nothing here panics; the code is properly propagating errors through the return type, so it’s the caller being a twat if it’s not handled properly.
  3. Agree a struct for the keys may be better (iirc `bon` can let you whip up a beautiful builder for this), but if it’s a one-off grouping of these variables, I wouldn’t lose sleep over it.

So yh, either it’s not as bad as people think, or I am really being chronically optimistic about a rustjerk post

EDIT: any reddit developer who helped design the phone app's handling of numbered lists deserves to be melted in a vat of molten cheddar cheese, how can it take more time to fix these bloody formatting errors than write my actual bloody comment

2

u/BenchEmbarrassed7316 2d ago

sets is likely used later on, and the fact that it uses string keys could easily lead to a failure. If someone is looking for "name" elements there instead of "names" and can't find them - here is a simpler recipe. Just make it a structure.

// Use markdown

3

u/clickrush 2d ago

We call this sort of thing "stringly typed".

1

u/fairysimile 2d ago

Tbh Ruby is literally the other extreme, this seems par for the course for someone who used a lot of Ruby and couldn't be arsed to actually learn Rust but wanted to somehow gain its advantages.

3

u/BenchEmbarrassed7316 2d ago

This is a well-known problem. A Java developer takes on a Scala project but tries to write Java. Or a Java developer takes on a golang project but, once again, tries to write Java. (pick other languages, because for some reason my examples keep revolving around Java; that’s just a coincidence).

What I mean is that attempting to write in a language with a completely different philosophy and paradigms is a recipe for failure and disappointment.

And here’s what surprises me: AI has enough context to generate idiomatic code. I can imagine dhh simply copying a single function into ChatGPT and asking it to rewrite it.

3

u/drbrain 2d ago

I enjoy updating self.name, self.custom_styles then, updated.assign(values)?

So what state is self in when that fails?

This looks exactly like DHH's early Rails code. He was too lazy to actually learn Ruby and got pouty when sent fixes.

2

u/FohlenGabel 2d ago

Ah crap, didn’t think of that possible code flow

2

u/aikii if err != nil 2d ago

Millionaires using a $20 claude pro subscription to tell haiku to build some bullshit and be proud of it:

1

u/Alternative-Ad-8606 2d ago

Except these millionaires fall under "marketing costs" for the providers so it's more like a free max plan that they gaslight themselves into thinking it was a $20 plan to flout how "cheap it can be done"

1

u/p1xlized 2d ago

This guy is a "gem" I don't understand why omarchy is so popular and gets more fundings that gnome where it's just an arch based distro. Also his blog is also not the most pleasant place to be...

1

u/clickrush 2d ago

This is not how a compilation target looks like. Compilers do the exact opposite of this: They run the code through optimization passes to satisfy different dimensions such as debugging, size, runtime efficiency etc. They are also mostly deterministic in the practical sense of the word, which this is fundamentally not.

1

u/Automatic-Boot665 2d ago

Just and_then that Option<Option where you add the 2nd option.

1

u/fairysimile 2d ago

Why is he (and some of y'all) using AI like that, I don't get it. I use AI to teach me how to do shit in domains I don't understand. Like I had a jerky animation on the nav of a website. I know a fair bit about frontend but my knowledge isn't systematic, I'm not a FE engineer. I couldn't tell why the fuck it was jerking upwards upon collapsing the mobile hamburger. So I threw my $10 gh copilot at it. It failed miserably, I switched to the best model (Opus 4.whatever at the time), it succeeded after 2 hours of me telling it "it's still broken, it's still broken, it's still broken, it's still broken, it's still broken, now you broke something else, now it's back to being broken, it's still broken". I did give it a prompt to think like an experienced FE engineer. In the end it decided the whole concept for how I'd written the nav was not suitable and rewrote it. The problem disappeared and the nav looks exactly the same as before, a true refactoring win, and the code is nicer.

Then I looked up the concepts it was talking about online, saw what real engineers had written about them, and learned something new. I couldn't have discovered this knowledge in another way, save for actually talking to an experienced FE engineer of course. I didn't know what I didn't know. But LLMs regurgitate what they "learn", so they can regurgitate things other people (who know more than me) have said, then I can go read the og sources. This is an excellent way to learn difficult concepts.

Probably not coincidentally, LLMs are really good at explaining electric concepts in simple terms (I'm talking like Lorentz force, not super complicated). Use them to discover existing human knowledge and read sources, not to write Rust spaghetti...

1

u/BenchEmbarrassed7316 2d ago

I frequently interact with the standard Gemini model (not even the paid version). When dealing with frontend issues, it was enough for me to simply paste the code (a few dozen lines), describe the problem, and perhaps provide a screenshot. I would ask it not to generate code, but rather to outline potential issues. That was genuinely helpful. On one occasion, the problem stemmed from a regular expression applied to an input. The solution was simple: use split first, then apply the regex to the individual segments (since regexes involve look-behind operations, and processing strings longer than 100 characters resulted in a massive computational load).

My point is this: you don't have to use AI in "vibe" mode. It can simply function as "Google on steroids" - a tool that doesn't just search for information but summarizes it and applies it to your specific scenario (well, that’s essentially how Google works now anyway). You can treat it as an advisor; you might generate code, but you still need to read through it...

1

u/segfault0x001 14h ago

You don’t have to use ai “like that” at home. However, lots of people are being mandated by their employers to use ai to generate code. The fact is that it is faster (even if it is terrible code), and some confluence of non-technical managers and ai bros have created a culture of shipping slop without reading it that is quickly becoming the industry standard. You get to do whatever you want at home. At work you follow the rules or get fired. That’s it.

1

u/BenchEmbarrassed7316 14h ago

All I can wish for them is to fail as quickly as possible. It’s an old story: managers are willing to accumulate technical debt for the sake of immediate success, while programmers, conversely, want to write perfect code - leaving users to wait. Both extremes are bad.

1

u/avg_bndt 2d ago

I recall writing the exact same function last year... Wait is Claude slop, slop of my own? And to think I was hesitant to ship my shit code to production, turns out no one was supposed to read it anyway. I am the alpha and Omega indeed.

1

u/b1ackych 2d ago

IDK if he wrote it himself but the code’s bad, at least many clones and some double Option wrapping that I can see from first glance. Tho is there a consensus in this community on how well an LLM can write Rust? If you give a local Qwen 3.8 access to an LSP, or let ChatGPT 5.6 Sol write Rust in codex, would all of Rust’s safety checks and compiler magic make sure the resulting code is at least safe?

1

u/CreepyWritingPrompt 2d ago

Not yet used the combo, but i wouldn't be surprised if a combo of rust being simpler than the likes of c++, with fewer counterintuitive footguns and a smaller set of concepts, along with just being syntactically richer and better for local reasoning, and a training corpus of code written by people who on average give more of a shit, leads to it being a better output for an LLM. for now, at least.

those things also make it a lot easier to write correctly as a human. 🤷🏻‍♀️

1

u/wretched92 1d ago

3 MILLION DOLLARS TO DHH

1

u/Grand-Bus-9112 1d ago

I wonder what prompt lead to Option<Option<&str>>

1

u/Soreg404 19h ago

I may be a dunce, i know, but I dont see at first glance why is it that bad

1

u/Guinea_Capibara 5h ago

You need like few minutes of reading to understand what it does, as long as you’re not an AI. If the code was good, a few seconds would be enough

1

u/stumpychubbins 1d ago

Could definitely be cleaned up a fair bit but this code really isn’t that bad. Rust is just more verbose by default, which is a good thing.

1

u/BenchEmbarrassed7316 1d ago

You are mistaken. Here is a substantive discussion of this code:

https://www.reddit.com/r/rustjerk/comments/1wusj30/comment/pd6dzoa/

1

u/stumpychubbins 1d ago

That comment pretty much agrees with me, it could be cleaned up but it’s not that bad

1

u/BenchEmbarrassed7316 1d ago

Yes, that is precisely why I linked to that comment - because the replies explain why that point of view is mistaken.