Skip to content

Another language's API: null or === in Python, .strip(), None or len() in JavaScript, null in Go ​

Calls and packages that do not exist: one of the ways AI coding agents bloat software, from lessloc's pattern catalog. lessloc catches it as made-up-api.

What makes another language's API a bad practice? ​

The standard that calls it a bad practice: Sonar's quality profile for agent-written code targets "hallucinated APIs"; a call that does not exist fails the first time it runs.

What does lessloc do about another language's API? ​

lessloc catches it as made-up-api.

  • made-up-api (tier 1): Another language's API, such as null in Python, len() in JavaScript or None in Go, or an import that no manifest declares and the platform does not provide.

Examples ​

Caught as made-up-api:

python
def first(xs):
    if len(xs) === 0:
        return null
    return xs[0]

Written well:

python
def first(xs):
    return xs[0] if xs else None

Caught as made-up-api:

python
def test_load():
    doc = load("[a]\nb = 1\n")
    assert doc["a"] != null

Written well:

python
def test_load():
    doc = load("""\
[a]
smooth = true
""")
    assert doc["a"]["smooth"] is True

Caught as made-up-api:

js
export const clean = s => s.strip();

Written well:

js
export const clean = s => s.trim();

The other patterns in Calls and packages that do not exist:

Released under the Apache-2.0 license. · llms.txt