5 ms·
> There's a correlation between lines of code in a file and bug count. Does the typing outweigh this? This is where the famous 'compiler' steps in and catches
by eternalban 6y ago
> There's a correlation between lines of code in a file and bug count. Does the typing outweigh this?
This is where the famous 'compiler' steps in and catches your typos and errors with "types" at compile time.
> If you're writing good unit tests already
Compilers are not fragile. Unit tests are fragile. IMO, a significant factor contributing to relation between N (lines of code) and B (expected number of bugs) is human error. Humans write unit-tests. For a fun spin, consider the fact that "more unit-tests" means "more lines of code" and thus "more bugs", but now in your "test suite".
[p.s. fragility above refers to the inevitable drifts between the original test-subject (and associated test code) and subsequent changes to the codebase that require updates to the test codebase.]
- hajile 6y ago> This is where the famous 'compiler' steps in and catches your typos and errors with "types" at compile time. The worst bugs aren't types * Syntax errors -- caught by JS runtime * Math errors -- caught by unit tests * Logic errors -- caught by unit tests * Resource errors -- caught by profiling tools and unit tests * Interface errors -- caught by integration tests, documentation, profiling and/or types Of all the major types of programming errors, types only help with the least impactful one, the most obvious one, and the one for which there are other tools available. In the end, the dynamic vs static typing argument has likely been going on since before most HN user's were born (since at least the 50s). I suspect we aren't going to reach a definite conclusion today either.
- eternalban 6y ago> In the end, the dynamic vs static typing argument has likely been going on since before most HN user's were born (since at least the 50s). I suspect we aren't going to reach a definite conclusion today either. Sure thing, but wanted to insert a few facts informing your assertive OP regarding "lines of code" and "unit-tests". p.s. "worst bugs" The worst bugs in my 3 decades career have involved reliance on a broken test-base "verifying" widely shared code in an evolving codebase.
- Vinnl 6y ago> caught by JS runtime This is a major point: "caught by JS runtime" means you're only able to see it when you actually run your application and exercise that code path - or worse, that your user does so. Where the alternative is your editor literally indicating the error the moment you write it, the fix costing you so little time that you can fix them practically subconsciously.
- hajile 6y agoCatching syntax errors is the realm of linters, but if you don't have a linter, the parse phase will immediately tell you that you messed up.
- Vinnl 6y agoThat's interesting, cause you mentioned the JS runtime earlier. In any case, unless you'd argue that you never get a single runtime error, I'd encourage you to take a moment every time you encounter one whether that could have been caught by TypeScript. In my experience, that is the case more often than you might think.