Video wird geladen...
Video konnte nicht geladen werden
Morning Bathrobe Rant: CRAP.
26,411 Aufrufe • vor 6 Monaten •via X (Twitter)
47 Kommentare

I think picking an acronym and then figuring out what it means is SHIT. And by SHIT, I mean Shoe-Horning In Terminology. 😉

👏

This man is living the dream. Talking shit and living some where with an incredible view

How do I tell it to cut the CRAP if I don’t know the acronym definition? I bet it will figure it out. I’ll try it on my project proposals

It will figure out the acronym. Also, have it write a crap tool specific to your application. Don’t run somebody else’s crap tool. You can use one of mine as a template if you like, just tell the AI to look at it and then write one for your application.

@RCallsign Still trying to wrap my brain around this recommendation. Why is it helpful to have CRAP tooling that’s application-specific? Language-specific is obvious, and I can see language + framework specific, but what do I get out of the next step to application-specific?

Crap depends upon two separate metrics. Coverage and Cyclomatic Complexity. CC is language dependent. Coverage is architecture dependent. In a simple monolith coverage is pretty simple to measure. But if you a system composed of N threads it gets trickier. N processes makes it even trickier. N services makes is even trickier than that.

@RCallsign Aha! That explains the disconnect. I’m thinking of coverage only in terms of source line coverage or branch coverage. Thanks! Is there somewhere you already explain how you work out your coverage analysis?

I generally use the standard coverage tools. I have also asked the agents to build custom coverage tools. Here's one of the secrets to using AIs. YOU don't have to figure out the details of how to do it. You just need to tell the AI what you want. You have to be smart about it, and have the insight to know when they are "lying" to you. But for the most part you can just say things like: "I've got three processes that communicate with each other, and I want to measure the overall test coverage that follows the thread of execution through each."

I have used cyclomatic complexity and test coverage with Claude Code . Claude Code’s comments on the tools: “Cyclomatic complexity — measures the number of independent paths through code. High complexity = harder to test, harder to reason about. Tools: radon (Python), lizard (multi-language). Test coverage — measures what percentage of code paths are exercised by tests. Tools: (Python), pytest-cov.”

CRAP index! Will give it a try. Maybe Claude Code will produce less crappy code. My 2 cents to force AI to refactor code. Set a max lines per file. If the file has too much lines, then AI has to refactor to pass the quality gate.

@SquidCorp_ink Instead of setting a max lines per file limit, I tell the agent to split any file that has more than N mutation points. The mutation tester I had the agent build has a scan mode that reports the number of mutation points, without actually mutating them.

Interesting approach. I was also considering a token approach. What if the limit was tokens? The agent already thinks in tokens, so a token budget per file is more natural than a line or mutation points count. Curious to have your opinion on that.

@SquidCorp_ink I've tried to ask the agents to measure their tokens. They seem unable to comply.

Yeah agents are bad with mathematics, but it could be done afterward, in a quality gate. /!\ this file has to many token! refactor.

That last part was crucial. Don’t set the agent on the warpath to reduce CRAP without setting up acceptance tests first! Removing a bunch of code is much easier for an AI to do to get better CRAP scores than actually refactoring 🙈

Yes, it's hard. Clickbait culture drives politicians to hyperbole. But some are worse than others. Some lie in their hyperbolic pejoratives more than others. Choose wisely -- not emotionally.

🤔

@unclebobmartin There was another political post he made, so maybe he replied to the wrong comment lol

@OmerGronich Yeah, I hit the button on the wrong post. Sorry about that.

I told my Hermes agent to cut the crap. It deleted my developer website and said “Done. Want me to hit the review site next?”

"CRAP" comes from "Change Risk Anti-Patterns" If the term came first, then it's a backronym. Here's a reference:

Definitely learned a thing or two from this one (so thank you bob!), but I’m curious… your tone (+ criticism of backronyms) sounds like maybe you think CRAP isn’t all that it’s cracked up to be. Or maybe cynicism about AI in general? Would love to know how ya really feel.

@unclebobmartin Curious offhand what you might say about one of my applications which for example seems to be pure and utter CRAP, but works fine for its intended case, any reason to be non-plussed about it or can I remain generally plussed for that specific application?

The AIs are much more tolerant of bad code than we are. But that doesn't mean their tolerance is infinite. I have seen AIs "lose it" over bad code. They thrash around, making this change and that change, unable to get a feature working because every change they make breaks something else. Having said that, my thresholds for crap are generally higher for an AI than for humans (myself). For code that I must maintain, I drive crap to 4 or below. I've had pretty good luck with agents even when the crap is only driven below 6. I am loathe to try 8, just on general principles.

How does one control the quality of the tests?

Crap, Mutation testing, and Scrap. The latter is a tool I recently built that measures the quality of the tests. It looks for setup duplication, long test chains, etc. It is very specific to clojure and speclj. But if you point an agent at it, you can get the agent to make a tool for your language and environment. Expect to fiddle with it.

Awesome. Thanks

But .. how the AI "measure" the CRAP? You can tell the test coverage but you let the AI to glance over the code and eyeball the complexity? Is there a tool for that?

There are several tools, but I suggest that you ask the AI to build one for you. You can point it to one of the tools you find on the web ( or and then tell it to build you a tool like that, but specific to your application and environment.

Oh, thank you. What a coincidence, I am working on the Java project.

Keep going uncle Bob, I'm almost there.

Are there any cases where you would want to contract many functions back into one function? If yes, what metrics would govern those decisions?

There have been times, while I was writing the code, that I have done that. It has to do with coupling and entanglement. Sometimes the union of two highly coupled functions is the simpler option. I have, from time to time, asked the agents to analyze the coupling between modules and unify those functions that could benefit. This works. The agents are pretty good at describing why they choose candidates and how they are going to unify them. Still, I'd rather this was better automated. Measuring this is a bit tricky. It has to do with the number of function arguments and tramp data that passes through a function into another. I'll be working on this in the weeks to come. In the meantime, since those situations are relatively rare, splitting remains the best option along with occasional agent driven unification.

The tests that it writes - are just … mindless, sometimes i feel like i’m wasting my tokens

That's why we also use mutation testing. Mutation testing drives the tests to be so thorough that any change to the source code will cause a test to fail. Then, even if in your view the tests are mindless, they are thorough, and when the agents break something you'll know about it immediately. And, of course, the meaningful tests are the acceptance tests that you keep control of.

Thanks, uncle Bob 🙏 - I will invest more into acceptance testing and extend my workflow with an Acceptance Test Agent

curious to hear the rant about LLMs benchmarks

Thank you for your guidance, Uncle Bob! TDD is key when working with AI. Has anyone had success applying TDD to UI/UX tasks with AI, when product and design teams are usually in the loop?

What about cognitive complexity? Seems much nicer and models digest that better imo

I think cyclomatic complexity and cognitive complexity are strongly related. Moreover the cognition of an AI is much greater than that of a human. The AI can keep more than 7+-2 simultaneous things in its "mind". So what is cognitively complex for us, is relatively easier to understand for them. Thus i've had good results with limiting CRAP to 6 -- even though for a human I'd set it to 4.

Ehhh I'd get it to do a crap audit first get it to pick out problem areas then maybe slowly lower it bit by bit .. I have trust issues 🤣

Exactly. PHP WASM

So Bob, I get where you're coming from here, but cyclomatic complexity is necessary. At least some. The whole reason we care about the issue in the first place is because too much means your code is impossible to reason about. And, as a developer you care about that because being able to reason about your code is important. But in real life, especially when people follow the Uncle Bob school of engineering (and I've seen this in production), you actually end up with the opposite problem. Having functions that are so spread out with little or no cyclomatic complexity (assuming a conventional logic tree style app in a conventional programming language), what you end up with is a bloated function space, and code that's so sparse... you still can't reason about it. And then you end up in this place, where right back where you started. With an app that can't be reasoned about. What's the solution there?

It’s absolutely CRAP! isn’t it?

Are you saying that I should throw my clean code book in the trash? I don’t even need to read code anymore, let alone write it?

No. You need to understand what makes code clean so you can drive the agents to make _their_ code clean. And you need to do that in a way that does not force you to become the bottleneck in the system by reading all the code. So, should you know the principles of clean code? Yes. Otherwise you could not drive the agents to write it.
