AIFeed

The Big List of Slop

Original text(via Lobsters)
Slop: code (or any writing) that is statistically likely but provides no value.

Of course, LLMs generate more slop than humans by design[citation needed], which is why we have so much more of it nowadays.

Since I still read the code1 (and I ain’t stopping now), I decided to collect the slop patterns I’ve seen in the wild, along with some remedies I’ve found useful.

And since this is the internet, I decided to RANK THEM. At least it’s not a tier list!

🤖🤖🤖 - How sloppy it is: from “maybe human” to “pure slop”.😐☣️💥 - How bad it is: 😐 meh, almost a nitpick / ☣️ hazardous / 💥 ticking time bomb.

So, without further ado, here’s my Big List of Slop. Starting with my favorite, the MacGyver Class.

Spongebob showing Patrick the mountain of garbage, but the mountain is made of Claude-s and ChatGPT-s
Spongebob showing Patrick the mountain of garbage, but the mountain is made of Claude-s and ChatGPT-s

Note: while the code in this post is obviously inspired by LLMs, no LLMs were used to generate anything - code or prose.

Table of Contents:

💥 MacGyver Class (🤖🤖⚪)

A modern take on NIH (Not Invented Here) meets a god class.

It takes both to the next level by cobbling common building blocks into weird low-level-ish primitives that don’t have a clear purpose and are practically impossible to get right or hammer into a reusable shape.


        class LockableSocket:
   socket: socket.Socket
   lock: threading.Lock
      

No matter what you are trying to do, the chances of someone needing ∧ correctly building something reusable with just a lock and a socket are virtually zero.

🤖🤖⚪ - It’s slop, but it’s usually disguised well enough to pass as real code if you aren’t looking for it.💥 - It will cause hard-to-catch bugs and can become enshrined forever in the codebase if someone else ends up using it.

Treatment: Sometimes, you’re in the business of building lockable-socket-shaped services, but if you are working with other people then it’s much more likely someone already built one. If not, maybe at least put it in a different PR?More often, these are symptoms of a design bug. Fix the design! Don’t document the lockable socket to convince me it’s the next big thing in microservice management.

😐 Validate, Don’t Parse (🤖🤖⚪)

The inverse of Parse, don’t validate. The code does some preparation work that is required for correctness, but doesn’t encode the result in the type system.

For example, say you make or read some list that needs to be sorted:


        def make_sorted_list():
    return [1,2,4]

data = make_sorted_list()
bisect(data, 3)
      

A classic slop move would be to add a check that the list is actually sorted:


        def make_sorted_list():
     return [1,2,4]

+def validate_list_is_sorted(input):
+    assert sorted(input) == input

 data = make_sorted_list()
+validate_list_is_sorted(data)
 bisect(data, 3)
      

🤖🤖⚪ - Classic slop - no value, but correct and would even catch rogue versions of make_sorted_list, which is probably why some TDD code looks like this.😐 - There are more lines to read and more tests to run, and some edge cases can still slip by (it just looks like they can’t).

Treatment: Depending on how expressive your language of choice is, either remove the check or use a type that guarantees the list is sorted:


        struct SortedVec<T>(Vec<T>);
fn make_sorted_list(...) -> SortedVec<u8> { ... }
fn bisect(data: SortedVec<u8>, needle: u8) -> usize { ... }
      

Other common forms: inserting an item into a dictionary and then checking the item is there, adding an item to a list and checking the list isn’t empty, doing string manipulation like trim and then validating the new string has a specific length, etc.

😐 Load-bearing Façade (🤖🤖⚪)

In the before times, there was an infamous design pattern, the Facade.Every action that has one or more steps can be Facade-d over:


        class Bar: ...
class Foo:
    bar: Bar

def make_bar() -> Bar: ...
def make_foo(bar: Bar) -> Foo: ...

# `get_foo` is a facade.
def get_foo() -> Foo:
    bar = make_bar()
    bar = bar.with_timeout(1)
    foo = make_foo(bar)
    foo.start()
    return foo
      

🤖🤖⚪ - Facades always were almost-slop, but recent advances in slop generation pushed the envelope here.

What happens when a refactor causes Foo to no longer need a Bar?


        class Foo:
-    bar: Bar
+    baz: Baz
      

make_bar is load bearing (🙄): it is used in tests, it’s still part of get_foo and with_timeout could have unexpected side effects. Etc, etc. “Best keep it.”


        def test_make_foo():
    bar = make_bar()
    assert make_foo(bar) is not None
      

😐 - Fluff code didn’t kill anyone, probably.

Treatment: Exfoliate. Facades are common, making them a prime reason for keeping old cables code around for show. Always check if the thing that claims to still need something is, itself, still needed.

☣️ Paranoia-Driven Tests (🤖🤖⚪)

Tests! Tests are awesome. But how do you decide what to test?

We can always add another test that checks for things that don’t happen… but are these tests adding any value?


        def sum(a, b): ...

def test_sum():
    with pytest.raises(ValueError, match="must be a number"):
        sum("1", None)
    assert sum(1, 2) != 5
      

Or even more extreme - what about testing the validation for things that don’t happen:


        def validate_stuff() -> str: ...

def test_validate_stuff():
    assert "boogieman" not in validate_stuff()
      

🤖🤖⚪ - LLMs popularized this genre, but Mock.assert_not_called was shipped in Python 3.5 (2014), so it’s hard to say who is the Trope Maker in this case.

☣️ - See Change-Detector Tests Considered Harmful.

Treatment: Each test must produce shareholder value. You are the shareholder. Delete tests that don’t produce value.

☣️ Insanity-Driven Tests (🤖🤖🤖)

Turning the paranoia to 11, we can also test each and every line of a function:


        def do_request():
    ...
    request_took_metric.observe(took_ms)
    logger.info("Request done.")

def test_request():
    do_request()
    assert request_took_metric.get_value() > 0
    assert logger.called_with(level=INFO, message="Request done.")
      

You would think that no sane human or bot would write this, but consider:

  • This was in the dataset.
  • I personally have seen this in old code.
  • There’s a built-in assertLogs in unittest.
  • I have seen much, much worse.

This is an endgame variety of the Change-Detector Tests. They take TDD and pretend it’s the Cold War and the Soviets are sabotaging the codebase.

Treatment: Same as the previous point - delete and move on.

💥 Sneaky Dict Side Dish (🤖⚪⚪)

A subtle and sinister variation on the tried-and-tested Dict Soup:


        # Party like it’s 2005.
def foo(): return {"foo": 1}
def foo_with_db(): return {"foo": 1, "db": ...}
      

🤖⚪⚪ - This went out of fashion years ago, but has made a comeback in the form of a side channel for anything that’s too painful to add to the “real” API:


        # Party like it’s 2025.
def foo_with_extra_stuff(idx: int, stuff: dict):
     return Foo(idx, db, stuff=stuff)

def process_bar(bar: Bar) -> (int, dict):
    ...
    return 1, {"task_took_ms": now() - t0, "missed": ...}
      

💥 - It’s a bad one, and there’s a good reason it went out of fashion. Avoid at all costs. You will regret pushing this one to prod.

Treatment: Do or do not - if something is important, it should be typed and documented and be given attention and effort, but if it isn’t, it should be removed.

☣️ Thesaurus-Oriented Naming (🤖🤖⚪)

Let’s say you look for

a word for two things connected at the middle

A thesaurus, or a creative individual, might suggest a Coupler, or a Junction, or a Nexus, or a Conduit.They can link, couple, entwine, intersect, unite, and attach.


        def connect(source, dest) -> Connection: ...
      

is probably the only correct answer: there’s no need to open the thesaurus.

What if we need something that really, really, really has to have that specific connotation of “middle”?


        def connect_mid(source, dest) -> MiddleConnection: ...
      

But honestly? Unless there’s a non-middle connection as well, just call it Connection. Less is more.

☣️ - It hurts humans reading your code the most, preventing them from grasping it and perpetuating LLM-only edits to the code.

😐 Pinching Keystrokes (🤖⚪⚪)

Like the C developers of old, more recent vintages of LLMs were also RL-ed to use fewer tokens.


        // Ahh, the good old days (?).
int *x, *p, *q, **dd;
      

There’s also some pretext for shortening long things like package names, which is how we got to this:


        import numpy as np # good, honorable, classy

import json as j # evil, lazy, rowdy
      

Treatment: Unless it is a common abbreviation that’s well documented, always use the full name. Always.

☣️ Parsing XML with Regexes (🤖🤖⚪)

You can’t parse XML with a regex. But that didn’t stop generations of {beginners,LLMs} from trying.

Sometimes it’s just plucking a value from a JSON string:


        data = '{"name": "Bob"}'
name = re.search(r'"name"\s*:\s*"([^"]*)"', data).group(1)
      

Sometimes it’s a more sneaky version like ad hoc string escaping with replace:


        replace(
    var.some_url,
    var.some_str_template,
    urlencode(
        replace(replace(replace(var.some_value, "\\", "\\\\"), "\"", "\\\""), "\n", "\\n")
    )
)
      

☣️ - It might even cover all the cases in a specific scenario, but it’s a bug waiting to be triggered!

Treatment: Avoid, but like in the MacGyver Class, these are usually signs that something went wrong somewhere else, and fixing the root issue will probably help more than importing-the-right-library.

☣️ Disposable Reusable {Closure,Struct,Interface} (🤖🤖⚪)

Do you have a box of cables you don’t want to let go of? LLMs have a similar tendency towards any and all constructs - they’ll name them, document them, test them - but only use them once.


        let make_i32 = |v| { v as i32 };
return optional_string.map(|s| make_i32(&s))
      

        process := func(x int) {
    s.actuallyDoSomething(x)
}

for _, item := range items {
    process(item)
}
      

🤖🤖⚪ - Good code might also do this when it makes sense in context, but it should be used sparingly.☣️ - It’s a good way to spaghettify code and make it less understandable.

See also: disposable classes that have two fields and are only used in one place, and interfaces with one function that are only used by one module.

Also, I’m thinking of updating this list as we invent (discover?) more interesting and strange forms of slop. So send your slop my way at [email protected]!Gotta catch them all.

  • Why am I still reading code? Mostly, for the love of the game. ↩︎

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗