~blog

Allen's Dev Blog

Rob's bullshit

July 19, 2024 — Allen

rob's bullshit

bc -l <<< "$(cloc --vcs=git --include-lang=JavaScript --include-ext=js . | awk '$1 == "JavaScript"{print $5}') / $(git grep -wc 'if' './*.js' | awk -F: '{sum += $2} END {print sum}')"

Every 8 lines of code in ▒▒▒ is an if statement. Every 8 lines. I've never paid much mind to my use of if’s. It’s not like I ration them, but the sheer volume of them in ▒▒▒ caught my attention.

Imagine a cook, wandering around a kitchen and every 8 seconds he has to ask wtf he's supposed to be doing. "Should I cook this? Should I stir this? Should I flip this?" It wouldn’t be long before his boss pulls him aside. "It's not that questions are bad, but why do you need to ask so many? Don’t you know your job? Why don't you know what you're supposed to be doing?”

And they legitimately do need to ask—because there is no structure to our code. It’s like finding some old tupperware in the back of the lab fridge with a piece of masking tape that says fresh delicious cheese. Do you just pop it in your mouth, or do you ask some questions first? You ask questions because you don’t know what’s in there! It says "cheese", but how do you know? There is nothing to stop someone from putting literally anything else inside that container.

That’s our code. We don’t have well-defined objects; we have some old tupperware with masking tape that says “Chart” and they know that they can’t just assume what’s inside and so they have to ask. Every 8 lines.

Because they reject anything more complex than popsicle sticks and hot glue, they have no control over what anything is and so they’re left with no choice but to ask. Every 8 lines. In a properly engineered system, the structure would tell you so much. When you call Promise.resolve() do you need to ask if(Promise.resolve) first to see if it exists? No, because there is structure that defines what it is. But they have no structure, just if statements. 17 thousand of them, or 1 out of every 7.8 LOC.

I guess I'll just throw this on the pile of shit that I can't do anything about.

Tags: work

comments powered by Disqus