3 ms·
After trying TS, I basically never want to write JS again. I know that 'OO' and 'typing' is not the solution to everything ... but aside from all the nice thin
by edblarney 10y ago
After trying TS, I basically never want to write JS again.
I know that 'OO' and 'typing' is not the solution to everything ... but aside from all the nice things you can do in TS ... the 'enforced architecture' of OO-ish paradigms, combined with typing, and essential obfuscation of the prototype paradigm ... has cut the time to development in half.
I can hardly think of a reason to use JS now that TS exists.
Of course - there are some reasons, in some specific situations, but by and large, TS is the future.
- woah 10y agoWhat OO does typescript have that js doesn't?
- edblarney 10y ago+ Member access private/protected + Static members (theoretically exist in JS, but much cleaner and 'compiler aware' in TS) + Interfaces When I write JS, I end up with closures within closures within closures. When I write TS, I find myself sticking to much cleaner abstraction. I end up (having to) create classes, and usually it's for the better.
- woah 10y agoA class is a pretty bad abstraction to try to fit the world into. It might work for some things, but it usually results in a lot of ceremony, and a lot of concepts in your program that exist only to service the abstraction. It's useful in JS for some special cases, but being forced into it is just going to make your code verbose and complicated for no reason. I'll stick to Flow for now.
- DanRosenwasser 10y agoFor the record, you're not forced into it at all. I'll mention that in the TypeScript compiler, we use very few classes at all - it's mostly written in a function-oriented style. TypeScript tries not to impose any sort of restrictions on coding style.
- edblarney 10y ago"A class is a pretty bad abstraction to try to fit the world into" I totally disagree with this. They are basically one of the best forms, if not 'the best' form of abstraction we have, particularly when it comes closer to the level of 'real world' abstraction. Classes are the basis of 'typing' - which is to say, typing beyond primitive types. They provide us with the ability to 'define things' that are not simply strings, numbers or booleans. It's why JS has moved onto classes, and almost all popular languages use them. The only time I find they can be limiting, is when there is the necessity to deal with looser typing, i.e. quick litoral objects ... but even then, 9 times out of 10 when I want to 'get around classes' - I'm just being lazy.
- twfarland 10y agoI've stopped using those OO-ish paradigms in JS (no 'this', 'new', 'prototype'), but even still, have much preferred using TS. You can get a long way (and have great flexibility) with only interfaces and generic functions.
- boubiyeah 10y agoSame, it's so much saner. classes or prototypes bring nothing but troubles to the table, except when you want to have tons of objects in a memory efficient way in library code. TS does a great job without OO thanks to structural typing.