6 ms·
The deeper problem is that JS is not strongly typed. Typescript gives you static type checks but the runtime is still weakly typed and will still do all sorts o
by flavio81 9y ago
The deeper problem is that JS is not strongly typed. Typescript gives you static type checks but the runtime is still weakly typed and will still do all sorts of weird type conversions.
- monsieurbanana 9y agoTheoretically, to what extend could the weird type conversions be prevented with the use of a strict linter? My intuition would be all, but I haven't thought much about it.
- flavio81 9y agoOnce code reaches a certain complexity level (and mind you, the threshold is rather low), you'll need dynamic generation of code and data (or else, write 10x the amount of lines of code). For this to happen in a safe way, you really, really, do need the runtime to be strictly typed.
- 0xffff2 9y agoAre you making this claim about JavaScript or as a general statement? I've probably written less than 1000 lines of JS ever (and that only for hobby projects), but I would strongly disagree with this statement as applied to C++, Java, etc.
- thehardsphere 9y agoI'm sorry, I'm confused by the way you expressed that. The argument was you need strict typing for large projects. C++ and Java have strict typing. What exactly is the basis of your strong disagreement?
- flavio81 9y agoMy comment is applied to any language with weak typing. Example: Javascript, PHP, and (sadly) C, particularly when using pointers to void. However, in C it's okay since there are big performance gains when you have full control of the memory.
- mschuetz 9y agoStrong typing is a start but not enough for my taste. Static typing serves as documentation and compile time bug check, which is awesome to have. I'd like to have both, without the detour over typescript.
- seanwilson 9y agoI don't think you're going to get strong types in standard JavaScript any time soon. Isn't TypeScript a very good compromise right now?
- flavio81 9y agoMy take is that having dynamic typing plus strong typing is a (pretty) good compromise. And static typing plus weak typing, insufficient.
- seanwilson 9y agoWhat languages would you put in these two categories?
- flavio81 9y agoNot all languages but here's a list: dynamic typing, strong typing: python (for the most part), Scheme dynamic typing, weak typing: Javascript, PHP static typing, strong typing: Pascal, Ada, Java, C# static typing, weak typing: C, Typescript, perhaps others SPECIAL CASES: strongly typed, dynamically typed, but with some compilers it can also be statically typed: Common Lisp strongly typed, statically typed but can infer types: Haskell, ML family strongly typed, can infer type with "auto" keyword: C++ (latest version) non-typed: Machine language, assembler, perhaps Forth
- seanwilson 9y agoWhat better alternative do you have to TypeScript right now though that you can use practically with existing libraries? Perfect is the enemy of good. TypeScript can capture more complex properties than C as well.