Hacker News new | ask | show | jobs
by chmod775 60 days ago
Opus 4.7 seems to reach ChatGPT levels of verbosity in code and loves to overcomplicate the most simple things.

This is something it spit out just now (trimmed a 9 line comment though):

        let keepSize = 0;
        let overBudget = false;

        await this.items.orderBy('[priority+dateUpdated+size]')
            .reverse()
            .eachPrimaryKey((primaryKey, cursor) => {
                if (overBudget) {
                    evictKeys.push(primaryKey as string);
                    return;
                }

                const key = cursor.key as [number, number, number];
                const itemSize = key[2];
                const contribution = itemSize > 0 ? itemSize : 0;

                if (keepSize + contribution > maxSize) {
                    overBudget = true;
                    evictKeys.push(primaryKey as string);
                    return;
                }

                keepSize += contribution;
            });
Come on now... what? For a start that entire thing with its boolean flag, two branches, and two early returns could be replaced with:

        let totalSize = 0;

        await this.items.orderBy('[priority+dateUpdated+size]')
            .reverse()
            .eachPrimaryKey((primaryKey, cursor) => {
                const key = cursor.key as [number, number, number];
                const itemSize = key[2];
                const contribution = itemSize > 0 ? itemSize : 0;

                totalSize += contribution;

                if (totalSize > maxSize) {
                    evictKeys.push(primaryKey as string);
                }
            });
I'm back to 4.6 for now. Seems to require a lot less manual cleanup.