Menu

2,119 nulls and 275 undefineds in one TypeScript codebase, and Postgres decided the ratio
📰

2,119 nulls and 275 undefineds in one TypeScript codebase, and Postgres decided the ratio

DEV Community: postgres·Daniel Pertu·8 days ago
#XbQqPxug
#devtopostgresql#devto#dev#null#undefined
Long article (1397 words) — no AI summary yet.
Reading 0:00
15s threshold

JavaScript has two ways to say nothing is here, and every TypeScript codebase quietly picks a policy about them, usually without anybody writing it down. I had never written mine down either. So instead of deciding what it should be, I counted what it is.

The subject is Nakodo : 520 non-test TypeScript files, 68,546 lines, a Next 16 app over Postgres.

How it was measured

Word-boundary regular expressions over the source, counting occurrences of each keyword, then the same over the type positions and the comparison forms separately. Tests are excluded throughout, because a test file is full of fixtures that would skew every ratio.

Two traps. The first is that null appears inside strings, SQL fragments and comments, so a bare grep -c null overcounts; I required a non-identifier character on both sides, which still counts the word in a comment and I have accepted that as noise rather than pretend to parse.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.