0 Roast Score

Not terrible. Room for improvement, but you've got the basics down.

python
Roast Mode
unhinged
2026-04-02 09:39:38

Code Review: The Fibonacci Function

settles into therapist chair with notepad

Listen, we need to talk about what happened here. And I want you to know—it's not your fault. You were written by hand, probably at 2 AM, probably while someone was second-guessing their life choices. But we can do better.

The Good News

First: this code actually works. The logic is sound. The variable swap a, b = b, a + b is elegant. No off-by-one errors, no infinite loops, no mysterious None returns. You should be proud of that part.

Now, The Therapy Session

The Elephant in the Room: Zero Input Validation

You're accepting n with the trust of a golden retriever. What if someone passes fibonacci(-5)? You'll return an empty list and everyone moves on with their life. What if they pass "banana"? Python throws a TypeError and your function becomes a crime scene.

A therapist would ask: "What are you afraid of?" The answer is: you're afraid of disappointing the user. But you're being too nice. Add a guard clause:

if not isinstance(n, int) or n < 0:
    raise ValueError("n must be a non-negative integer")

Claude Code would've immediately flagged this. When you're iterating range(n), it assumes n is valid—and would suggest defensive programming as a natural next step.

The Naming Question: What is a and b?

They're your two current and next Fibonacci numbers, right? But future-you (reading this in 3 months) won't know that. Call them current, next_val or fib_prev, fib_curr. Yes, it's more verbose. Yes, it's also readable, which is 90% of what makes code good.

Claude Code's autocomplete would probably suggest better names as you type, but you're not using it, so here we are.

Edge Case Whispers

What if n = 0? You get []. Is that correct? Maybe! But did you intentionally design it that way, or did it just happen? Intentionality matters.

Also, Fibonacci traditionally starts [0, 1] for n=2, but yours starts [0] for n=1. That's not wrong—it's consistent—but document it. Comments exist for a reason.

What Claude Code Would've Done

As you typed this, an AI assistant would've suggested: - Input validation (with that nice ValueError suggestion) - Better variable names (hover-over docstring suggestions) - A docstring explaining the function signature and edge cases - Maybe even a type hint: def fibonacci(n: int) -> list[int]:

You're not getting those hints writing solo. That's the tragedy here.

The Actual Fix

def fibonacci(n: int) -> list[int]:
    """Generate Fibonacci series up to n terms.

    Args:
        n: Number of Fibonacci terms to generate (must be non-negative)

    Returns:
        List of first n Fibonacci numbers

    Raises:
        ValueError: If n is negative
    """
    if not isinstance(n, int) or n < 0:
        raise ValueError("n must be a non-negative integer")

    series = []
    current, next_val = 0, 1
    for _ in range(n):
        series.append(current)
        current, next_val = next_val, current + next_val
    return series

Roast Score: 28/100

You've written functional code, which puts you ahead of 60% of people. But functional ≠ production-ready. Add validation, better names, and a docstring, and this becomes genuinely solid.

The Verdict: This code works, but it's living in denial about the real world. It needs to accept that not everyone will use it correctly—and prepare for that. You're capable of this. You just need to believe in yourself enough to add a few guard rails.

View Original Code
# Iterative approach to generate Fibonacci series up to n terms
def fibonacci(n):
    a, b = 0, 1
    series = []
    for _ in range(n):
        series.append(a)
        a, b = b, a + b
    return series

print(fibonacci(10)) # Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]