4 ms·
TS really stands out as amazing. It’s realized a lot of the promise of strong typing.
by pyuser583 3y ago
TS really stands out as amazing. It’s realized a lot of the promise of strong typing.
- malcolmgreaves 3y agoI agree that TypeScript is quite amazing. And that it's indeed improved the programs created that run in the browser or on `node`. However, I wanted to point out something that I think often gets overlooked when folks talk about TypeScript. I'd argue that TS has realized it for the web programming masses, who usually don't have any computer science education and thus are unaware of computing fundamentals such as types. TS hasn't realized the promise of strong typing only because it has been quite late to the game, so to speak. I do think I understand where you're coming from. Web programmers are the largest group of programming-related professionals. Bringing CS wins to this large group absolutely does bring the largest gains and impact to industry. There have been many programming languages created decades before TypeScript that have realized the promise of strong typing. Unfortunately, I think this road took too long. Collectively, people have known about these ideas since John Backus's 1977 Turing Award Lecture [1] -- "Can Programming Be Liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs" Anyways, I digress. Hopefully this was insightful! Have a great day :) [1] https://dl.acm.org/doi/pdf/10.1145/359576.359579 https://dl.acm.org/doi/pdf/10.1145/359576.359579
- anthk 3y agohttps://hypercubed.github.io/joy/joy.html https://hypercubed.github.io/joy/joy.html
- cgh 3y agoHow so? It looks a lot like a less-rich Java, whose type system has existed for literally decades. In fact, the generics syntax and type erasure was directly influenced by Java.
- coev 3y agoMore like indirectly influenced by Java by way of C# (Anders Hejlsberg designed both C# and TS)
- ildjarn 3y agoTypescript has far more powerful type constructs than Java.
- pionar 3y agoI disagree. The language was probably more inspired by C#, which is itself inspired by Java. Type erasure is just part of transpiling to JS.
- acchow 3y agoTho Typescript does have structural types, mapped types, union types, optional types, type aliases..... Bunch of useful type features.
- skybrian 3y agoI haven’t used Java in many years, but TypeScript’s structural types give it a different flavor than I remember from Java. Unlike in Java, most of the types I define aren’t classes or interfaces. It’s just data that has an expected shape. Check out the design of Zod, for example. I have a bunch of Zod types for the validation of incoming JSON messages. This automatically generates the corresponding TypeScript types through the magic of type inference. It’s quite easy to create discriminated unions, which are just structs where one field has a fixed value.
- pyuser583 3y agoIn functional programming, a type is just a function that returns a list of possible values. It’s not a class.
- skybrian 3y agoConceptually, you can think of a type as a set of values, but no, it’s not how static type-checking is implemented. Some sets are very large (consider the set of all JSON values) and enumerating them isn’t useful.
- dragonwriter 3y ago> In functional programming, a type is just a function that returns a list of possible values Its literally not; there may be a language which does this or something close (actually, I’ve seen narrow, purpose-focussed relational languages where this is the case, and all types are enumerable), but it's definitely not generally the case in functional languages.
- ildjarn 3y agoTS has a powerful type system that behaves in strange and counter intuitive ways, particular for people coming from JS. It doesn’t even have a spec, really. I would prefer something less powerful but more predictable, personally.