3 ms·
Generally the problem is that dealing w/ memory is hard. Either it's explicit like C and you've got a lot of memory management code, or it's implicit like Rust
by camgunz 4y ago
Generally the problem is that dealing w/ memory is hard. Either it's explicit like C and you've got a lot of memory management code, or it's implicit like Rust and you've got a lot of constraints on what you can do, or you're using GC and you're not a systems language.
Integrating this idea, other ways of phrasing what you're asking is:
- Why don't we add pointers, malloc, and free to TypeScript?
- Why don't we add a borrow checker to TypeScript?
It might seem simple to just add "access to pointers", but the totality of what this means is you have to define semantics for allocation. That means things like .map, .filter, .foreach, the spread operator, and so on. From the TypeScript point of view, that would gum up the works a lot.
Or you could add a borrow checker, but that would invalidate... maybe every existing non-trivial TypeScript program.
---
Secondly, you're asking for an entirely different backend infrastructure. TypeScript compiles to JavaScript, systems languages compile to object code. There would be significant complexity converting all the features of TypeScript into object code, generators and async/await come to mind.
---
TL;DR you really can't separate a language's features from the rest of its design. It influences everything from semantics to syntax, and designers carefully balance all this based on the problems they assume their users are trying to solve.
- grumblingdev 4y agoI think AssemblyScript is the best example. Adding the borrow checker is quite invasive though. This guy is trying https://github.com/alshdavid/BorrowScript https://github.com/alshdavid/BorrowScript. I think it's a kind of fun constraint that experienced and bored devs like to challenge themselves with - the borrow checker. The latest obsession. You absolutely don't need a borrow checker, just like you didn't need everything to be functional programming, but it's intellectually stimulating.