3 ms·
One issue I've seen with LLM's is adding superfluous code in the name of "safety" and confidently generating a bunch of stuff that was useful in years gone by,
by mnahkies 5mo ago
One issue I've seen with LLM's is adding superfluous code in the name of "safety" and confidently generating a bunch of stuff that was useful in years gone by, but now handled correctly by the standard lib. I'm of the opinion that less is more when it comes to code, and find the trend this is introducing quite frustrating.
How do you avoid this pitfall?
- appplication 5mo agoGosh this couldn’t be more true, which IMO is the real reason LLM workflows are not strictly faster if you care about quality. Otherwise you end up with a codebase where only 60% of it is necessary. Standard testing patterns also tend not to be great at catching this particular flavor of LLM-ism.
- tomjakubowski 5mo agoI wonder this too. I prompted Opus 4.7 to generate some Python threading code for me. The code to run the sub-thread looked like this: def run(): with contextlib.suppress(SystemExit): do_thread_thing() threading.Thread(target=run, daemon=True).start() Suppressing SystemExit was surprising, and made me curious. I followed up and asked the model: what's the purpose of that? The model's response: "Honestly? Cargo-culting on my part. You should remove it."
- cassianoleal 5mo agoI had some shell scripts littered with `|| true`, which was obviously obscuring real errors everywhere. When I challenged the model, it gave me the same "cargo-culting" answer.
- bewuethr 4mo agoThe `|| true` is often done because people use `errexit` as part of "Bash strict mode"[1], which comes with so many caveats[2] that I usually avoid it. Claude, however, loves it. [1]: http://redsymbol.net/articles/unofficial-bash-strict-mode/ http://redsymbol.net/articles/unofficial-bash-strict-mode/ [2]: https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail
- cassianoleal 4mo agoI use "strict mode" in almost every script I write. IMO these caveats shouldn't be a reason not to use it, but should instead be used as a manual of what to avoid when using it. This is just programming. Everything is a tradeoff. `|| true` is a horrible practice because even though it may help in cases where a specific failure mode is acceptable, it obscures unexpected failures and could prove catastrophic. The solution is not to drop the protections but rather to handle the expected failure and let the sript crash otherwise. This is, again, programming. You don't usually `catch Exception` in Python for similar reasons. There may be legitimate uses for that, but IME they are a rare exception and realistically only used when I actually don't care about what happens when I run it. The other infuriating thing I found is that when I call out the model for its use of `|| true`, it tends to replace them with `|| echo "error foobar"` - which is at least not completely silent but the same problems exist.
- kingforaday 4mo agoFrom your statement and the parent comment, just learned that "cargo cult" is a thing, but cargo-culting as a compound is something AI has made up? [1]. As I was educating myself, I found Richard Feynman's Commencement Speech at Caltech in '74 [2] that might have coined this for our industry? If you would rather listen than read [3]. Posting this for others curious on the term. 1. https://trends.google.com/trends/explore?q=Cargo-culting&hl=en-U https://trends.google.com/trends/explore?q=Cargo-culting&hl=... 2. https://calteches.library.caltech.edu/51/2/CargoCult.htm https://calteches.library.caltech.edu/51/2/CargoCult.htm 3. https://www.youtube.com/watch?v=yvfAtIJbatg https://www.youtube.com/watch?v=yvfAtIJbatg
- cassianoleal 4mo agoThanks for this! I confess I've heard of cargo culting for a long time but never thought too much of it. Seemed like an idiom like any other. The talk is fascinating, and describes attitudes I see all the time in the industry and at work, and they bother me. Now I know they are also cargo culting. That will hopefully help me steer people away from those practices.
- mrgoldenbrown 4mo agoFWIW anthropologists have debunked the overly simple and somewhat patronizing idea of cargo cults that Feynman presented. Reality was much more complicated and less amenable to his style storytelling.
- pianopatrick 5mo agoThinking off the top of my head - couldn't you have an AI scan that looked for such things? Just send every file in the code base to AI one at a time. Have a prompt like "See if there is ABC pattern that can now be handled by XYZ standard library function in this file. Reply YES or NO. {{file contents}}" Seems you would not need that many tokens to do so and you might find such cases.
- krupan 4mo agoAI does stupid thing, but maybe we can fix it with AI
- insin 5mo agoWatching it like a hawk and stopping/redirecting, or immediately reviewing and doing the same is the only way, really.