Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

Morning Bathrobe Rant: CRAP.

26,411 Aufrufe • vor 6 Monaten •via X (Twitter)

47 Kommentare

Profilbild von Bored Devops ☠️🛠⚙️
Bored Devops ☠️🛠⚙️vor 6 Monaten

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

Profilbild von Bored Devops ☠️🛠⚙️
Bored Devops ☠️🛠⚙️vor 6 Monaten

👏

Profilbild von Kenneth Eversole
Kenneth Eversolevor 6 Monaten

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

Profilbild von RC
RCvor 6 Monaten

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

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Zach Frey
Zach Freyvor 6 Monaten

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

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Zach Frey
Zach Freyvor 6 Monaten

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

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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

Profilbild von Richard Askew
Richard Askewvor 6 Monaten

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

Profilbild von SweatSpots 🏃🏼‍♂️
SweatSpots 🏃🏼‍♂️vor 6 Monaten

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.

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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

Profilbild von SweatSpots 🏃🏼‍♂️
SweatSpots 🏃🏼‍♂️vor 6 Monaten

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.

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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

Profilbild von SweatSpots 🏃🏼‍♂️
SweatSpots 🏃🏼‍♂️vor 6 Monaten

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

Profilbild von Omer Gronich
Omer Gronichvor 6 Monaten

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 🙈

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Omer Gronich
Omer Gronichvor 6 Monaten

🤔

Profilbild von Marcel Albrecht
Marcel Albrechtvor 6 Monaten

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

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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

Profilbild von Tony Simons
Tony Simonsvor 6 Monaten

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

Profilbild von Jim Humelsine
Jim Humelsinevor 6 Monaten

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

Profilbild von Mordechai Hammer
Mordechai Hammervor 6 Monaten

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.

Profilbild von David Lin-Clark
David Lin-Clarkvor 6 Monaten

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

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Pascal
Pascalvor 6 Monaten

How does one control the quality of the tests?

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Pascal
Pascalvor 6 Monaten

Awesome. Thanks

Profilbild von Andrej Szontagh
Andrej Szontaghvor 6 Monaten

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?

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Andrej Szontagh
Andrej Szontaghvor 6 Monaten

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

Profilbild von Dwayne
Dwaynevor 6 Monaten

Keep going uncle Bob, I'm almost there.

Profilbild von Mvrck
Mvrckvor 6 Monaten

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

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Dimi
Dimivor 6 Monaten

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

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Dimi
Dimivor 6 Monaten

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

Profilbild von 0byte
0bytevor 6 Monaten

curious to hear the rant about LLMs benchmarks

Profilbild von Andre Burnt
Andre Burntvor 6 Monaten

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?

Profilbild von Martin Wickman
Martin Wickmanvor 6 Monaten

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

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Profilbild von Jesse Jr Lim (林振燊)
Jesse Jr Lim (林振燊)vor 6 Monaten

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 🤣

Profilbild von Andrew Rulnick
Andrew Rulnickvor 6 Monaten

Exactly. PHP WASM

Profilbild von Lynn Cole
Lynn Colevor 6 Monaten

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?

Profilbild von Swapnil Khambayat
Swapnil Khambayatvor 6 Monaten

It’s absolutely CRAP! isn’t it?

Profilbild von timtikitaka
timtikitakavor 6 Monaten

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?

Profilbild von Uncle Bob Martin
Uncle Bob Martinvor 6 Monaten

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.

Ähnliche Videos