正在加载视频...

视频加载失败

Morning Bathrobe Rant: CRAP.

26,411 次观看 • 6 个月前 •via X (Twitter)

47 条评论

Bored Devops ☠️🛠⚙️ 的头像
Bored Devops ☠️🛠⚙️6 个月前

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

Bored Devops ☠️🛠⚙️ 的头像
Bored Devops ☠️🛠⚙️6 个月前

👏

Kenneth Eversole 的头像
Kenneth Eversole6 个月前

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

RC 的头像
RC6 个月前

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

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Zach Frey 的头像
Zach Frey6 个月前

@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?

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Zach Frey 的头像
Zach Frey6 个月前

@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?

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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."

Richard Askew 的头像
Richard Askew6 个月前

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.”

SweatSpots 🏃🏼‍♂️ 的头像
SweatSpots 🏃🏼‍♂️6 个月前

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.

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

@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.

SweatSpots 🏃🏼‍♂️ 的头像
SweatSpots 🏃🏼‍♂️6 个月前

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.

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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

SweatSpots 🏃🏼‍♂️ 的头像
SweatSpots 🏃🏼‍♂️6 个月前

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

Omer Gronich 的头像
Omer Gronich6 个月前

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 🙈

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Omer Gronich 的头像
Omer Gronich6 个月前

🤔

Marcel Albrecht 的头像
Marcel Albrecht6 个月前

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

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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

Tony Simons 的头像
Tony Simons6 个月前

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?”

Jim Humelsine 的头像
Jim Humelsine6 个月前

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

Mordechai Hammer 的头像
Mordechai Hammer6 个月前

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.

David Lin-Clark 的头像
David Lin-Clark6 个月前

@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?

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Pascal 的头像
Pascal6 个月前

How does one control the quality of the tests?

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Pascal 的头像
Pascal6 个月前

Awesome. Thanks

Andrej Szontagh 的头像
Andrej Szontagh6 个月前

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?

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Andrej Szontagh 的头像
Andrej Szontagh6 个月前

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

Dwayne 的头像
Dwayne6 个月前

Keep going uncle Bob, I'm almost there.

Mvrck 的头像
Mvrck6 个月前

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

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Dimi 的头像
Dimi6 个月前

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

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Dimi 的头像
Dimi6 个月前

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

0byte 的头像
0byte6 个月前

curious to hear the rant about LLMs benchmarks

Andre Burnt 的头像
Andre Burnt6 个月前

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?

Martin Wickman 的头像
Martin Wickman6 个月前

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

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

Jesse Jr Lim (林振燊) 的头像
Jesse Jr Lim (林振燊)6 个月前

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 🤣

Andrew Rulnick 的头像
Andrew Rulnick6 个月前

Exactly. PHP WASM

Lynn Cole 的头像
Lynn Cole6 个月前

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?

Swapnil Khambayat 的头像
Swapnil Khambayat6 个月前

It’s absolutely CRAP! isn’t it?

timtikitaka 的头像
timtikitaka6 个月前

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?

Uncle Bob Martin 的头像
Uncle Bob Martin6 个月前

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.

相关视频