3 ms·
Yeah, I think that's a good point. I'm actually quite on the fence about dynamic and static typing - I like both. With a small team that knows what they're doin
by fhd2 2y ago
Yeah, I think that's a good point. I'm actually quite on the fence about dynamic and static typing - I like both. With a small team that knows what they're doing, I tend to go dynamic. With a larger team, it does tend to become a bit of a mess and weird workarounds to not having static typing (like some mystical 100% test coverage) start to surface.
I love the approach Python and MyPy took there: Python supports but ignores type annotations. You can add them to any part you want and check it with MyPy, but you can truly do it gradually, and you can always decide not to do it. An approach like that would fit JavaScript beautifully, I think.
- gregplaysguitar 2y ago> supports but ignores type annotations That’s how TS works too though - compilation just strips the types via babel etc, with type checking a separate process. You opt in file by file by switching .js to .ts
- fhd2 2y agoWell, the nice thing with Python types is that the _only_ difference to untyped Python is the type annotations. Last time I worked with TypeScript (two and a half years ago), it felt more like a different language _similar_ to JS. In my experience it was quite... viral. With MyPy I've genuinely seen just specific parts of a code base become typed and didn't notice any friction. I wonder what would happen if that proposal for type comments in JS went through. Would TypeScript become just a type checker / optimizing compiler? Google's Closure had an (IMHO) nicer approach (using doc comments for type annotations, see: https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System https://github.com/google/closure-compiler/wiki/Types-in-the...), but I don't get the impression it'll ever catch on outside Google.
- goeiedaggoeie 2y agoClosure team have also deprecated a lot of the old tooling. Closue was ahead of it's time for sure and as someone who heavily used the Closure Library and Closure compiler in advanced mode, it is sad that it did not catch on. However using TSickle you can transpile Typescript into javascript which closure compiler uses for advanced optimisations.
- Quothling 2y agoI'm not absolutely certain, but doesn't Typescript work exactly the same way Python does if you set it up to do so? I think the reason you may think you can't have dynamic types in Typescript is because it's generally recommended not to do so. Sort of because that if you're using dynamic types, then you might as well be using pure JavaScript with JSDoc. Having a couple of decades of experience with dynamic and static typing, I tend to prefer static typing because it's just "easier" (more maintainable, lets you onboard people faster, lets you do a lot less code-reviewing, and other advantages all of which are more on the "managing people" side of things). Dynamic typing can be good and it certainly lets you prototype faster, but to do it well over a 5 year period you're going to need some serious governance. One thing I never liked about Python is that sometimes it "guesses" the types wrong behind the scenes. This is sort of an issue with most "magic" that you'll also see in some of the parts where Java, C# and others, lets you skip writing a lot of boring code by "guessing" your intentions. But where it's relatively easy to tell the runtime environment how to do it the way you want it in something like C#, it's not in Python. It's also often a lot less obvious unless something fails in a manner you've taken steps to expect. With JavaScript (and this includes Typescript) you have another set of issues. Since classes, types and so on are all abstractions of object and since Javascript will happily pass "nothing, but not null" around. Well... It's just so easy to make spaghetti or even code which isn't very performant. Things like classes have very little function in Typescript, I'm not saying you should never use them, because you should never be religious about these things. For the most part it's typically better to use a type/interface and a stand alone non-hoisting functions. Personally I prefer rather opinionated languages like Go, or very strict languages like Rust where everything is very locked down and unmutable until you specifically tells it not to be. Of course Rust comes with it's own "interesting" things like the borrow checker.
- cranberryturkey 2y agoThey say TS is optional but I've ran into issues using 3rd party libraries that require it when calling their methods. I just never really used typing. I started with perl and then did php and ruby for awhile before focusing on javascript. So I never knew what I was missing. I'm just much much faster in vanilla js than I am with typesh