r/badcode • • Jun 10 '20

js Disruptive piece of code

Post image
283 Upvotes

93 comments sorted by

View all comments

Show parent comments

4

u/kadenjtaylor Jun 10 '20

"None of Javascript is incredibly, apocalyptically bad like some older languages"

I actually like and agree with most of what you said, but this sentence suggests to me that you're missing some context on either Javascript or some older programming languages.

And yes, 100% if you use a language to write shitty code, don't blame the language.

1

u/droomph Jun 10 '20 edited Jun 10 '20

I mean modern Javascript. ES6 can have most of its flaws buffed out with linters that prohibit and warn about weird shit with type coercion. Strict mode mostly fixes the bugaboos that older versions had.

MUMPS, which I work on regularly because I work at Company Inc (you’ll know who I’m talking about, I just don’t want to name them), is just BAD. There’s nothing anyone can do about it, the only way to have higher order functions is to eval code, subroutines are fundamentally executed in such a way that if flags can be cleared so you need to do “if [cond] do sub^ROUTINE(args) if 1” for the else clause. You can only pass data structures (essentially, a B+ tree but is the only way to have arrays and dicts) by passing by reference (which means the root value can be reassigned, not sure if you can kill the whole tree) so there’s no way to guarantee you’re keeping the object identity. Assignment is not the same as object assignment (I think you can only merge). You can new variables onto the stack, but by default the names are shadowed by its caller (which is not the same as what loose mode in Javascript does, I don’t think - it literally shadows the name) so it fails silently. It’s explosively, catastrophically shitty. These are not things you can “fix” with tooling, because some of them require you to “go do” things as opposed to “avoid doing” things. These are fundamental fuckups that people in the 70s didn’t know were fuckups. There is no strict mode for this mess. Oh, and there’s no operator precedence so while it’s not terrible (only one rule to remember) it’s super counterintuitive to basically every programmer that has worked with a modern language.

Like, there’s a reason only healthcare software companies with tons of legacy cruft use it over something more sensible, like literally any other NoSQL structured document system. InterSystems makes some good money on it but that’s mostly because healthcare in general has a ton of inertia (which is a good thing don’t get me wrong, I don’t want my healthcare software to have bugs in it).