8 ms·
Although typing bugs are often the simpler type of bugs to fix.
by shhehebehdh 8y ago
Although typing bugs are often the simpler type of bugs to fix.
- Operyl 8y agoUntil they’re not. I’ve had some codebases where it took 3-4 hours to figure out that some really bizarre issue was really just a type bug. And I don’t consider myself a terrible debugger.
- shhehebehdh 8y agoObviously. Any distribution will have some exemplars toward the tail.
- smt88 8y agoThis is only true if the bug is caught by the runtime checker. Lots of type bugs aren't, especially in languages with type coercion.
- ajxs 8y agoThe bigger problem is that "Simple fix" !== "Simple ramifications". Runtime issues caused by missing very simple typing bugs can bring down critical systems in Node. I worked at a company where a payment batching system built ( not by me ) with a MongoDB database failed to work correctly because the aggregation query was checking a field was `null`, without checking if it was there in the first place... No one even noticed for several weeks until someone finally investigated the low volumes. That's a very kind example too, just because they're simple to debug when they pop up doesn't mean that they won't cause massive destruction in prod.
- root_axis 8y agoI don't think that's really true as a general rule. Passing a variable of an unexpected type or nullable could have completely unpredictable behavior depending on what assumptions the code makes about the incoming parameter. It could have no effect or a catastrophic one, there's really no way to know without reading actual code.
- baroffoos 8y agoNot at all. Typing bugs often leave code looking perfectly fine until you discover that one of the variables you expected to be y was actually x. And the only way to find out is to just print out everything
- jondubois 8y agoCan happen with TypeScript too. There is no runtime type checking so if you parsed a JSON object and cast some unknown property `const result = someRemoteObject.someUnknownPropertyWhichIsAString as number`, it doesn't guarantee that the result is actually a number. You still need to do actual schema validation just like with old school JavaScript.
- baroffoos 8y agoBetter languages solve this. In haskell you define a datatype for json before you parse it.
- jondubois 8y agoSo true and simpler to detect too. The kinds of bugs which TypeScript prevents are those which could have been caught by the simplest of integration tests using the simplest inputs. Every time I rename or change something in TypeScript, I have to change it in so many different places. In JavaScript, changes where much more localized.