by russellbeattie · 7y ago · 0 comments
But if you want to declare one is fundamentally or empirically better, then you need to get a grip. We can all like different things, it's allowed.
The one core thing I'd like to stress, however, is that TS is not JS. If you use TypeScript, you are not using JavaScript. They are cousins, sure, or maybe uncle and niece, but they are not the same.
I'm speechless. Do you believe type checking doesn't catch bugs? Because that's what it sounds like you're implying.
>But if you want to declare one is fundamentally or empirically better, then you need to get a grip. We can all like different things, it's allowed.
This is a ridiculous argument. People make such declarations because they believe them to be true. You're basically saying, "You're insane if you disagree with me that one is not fundamentally better than the other."
>The one core thing I'd like to stress, however, is that TS is not JS. If you use TypeScript, you are not using JavaScript. They are cousins, sure, or maybe uncle and niece, but they are not the same.
I don't see why this would stop anyone from using TypeScript. Why should we care?
(Also: When people say 'TypeScript is just JavaScript,' it's not because they're crazy. It is just saying something else. TypeScript is a strict superset of JavaScript that is compatible and compiles down trivially, which is in contrast to CoffeeScript for example, which was previously popular. Nobody was ever claiming that TypeScript triple equals JavaScript.)
...
You start off by implying that type-checking is ineffective ('[somehow think] this reduces bugs') then call for people to not engage in flame wars... what did you expect to happen?!
Reducing it to "pro type-safety vs pro-flexibility" doesn't tell the whole story. For me, it's "pro-consistency vs pro-inconsistency" or "pro-tooling-that-makes-sure-I-don't-screw-up-something-trivial vs pro-keeping-absolutely-everything-in-my-head-at-all-times." Of course, that's _also_ pretty superficial and unfair -- plenty of amazing work has and will be done without type safety -- but as a bonafide Kool-Aid-drinking TypeScript Cultist, I feel obligated to share that because it's made my life better.
function greetPerson(name) { ... }
Call it in a bunch of places like this: greetPerson(user.name)
Now change the signature: function greetPerson(userId) { ... }
What code do you need to update to fix the breakage you now caused?A dynamically typed language can't tell you without some serious static analysis, which to my knowledge doesn't exist. TypeScript can know this both when linting in your editor, and at compile time. Old signature:
function greetPerson(name: string)
New signature: function greetPerson(userId: number)
Just write tests, some might say. But you've got your test right there: The type is the test for this particular problem. Unit tests should test behaviour, not types. (Since unit tests should cover failure cases, duck-typed languages arguably require that you test calling your functions with a wide variety of bad inputs.)In practice, large programs will never have enough, or good enough, tests, because they have to be written separately from the code they're testing. Type systems allow us to describe our rules in the code.
Note that there are statically typed languages (OCaml and F# being notable examples) where the type inference is sufficiently good that you rarely need to write out the types of signatures, let alone variables or return values:
let greetPerson name = ...
greetPerson user.name
The fact that they can do this invalidates the usual "static typing require lots of unnecessary verbosity" argument, because it's not true.I could argue, but won't, that the accepted wisdom isn't correct, and large code base management is more about code discipline and reviews rather than whether your language requires types or not.