| ▲ | The history of C# and TypeScript with Anders Hejlsberg | GitHub(youtube.com) |
| 86 points by doppp 5 days ago | 54 comments |
| |
|
| ▲ | m132 2 hours ago | parent | next [-] |
| Surprising to me that (in the context of TypeScript) ECMAScript 4, ActionScript, and Google Closure were not mentioned! Especially the first two; Macromedia/Adobe and Netscape/Mozilla have been working on baking TypeScript into JavaScript proper for a whole decade before HTML5, the mobile boom, and the associated problems have emerged. ES4/AS3 even had a nearly identical syntax. What's even more interesting is that Microsoft and Google were part of TC-39 at the time, and were the main opponents of ES4. While they had some rightful reasons to take this position, there's no way ES4 hasn't shaped TS in the end. Perhaps the lack of mention of any of this is due to that TypeScript might have been handed to Anders' team after the project vision and original design have developed (in the video, it is introduced as a continuation of "SharpScript"), but the interview still left me rather insatiated. |
| |
| ▲ | epolanski 2 hours ago | parent [-] | | Out of the big 4 involved in typescript, only one was involved with the tc39 |
|
|
| ▲ | pdevr 3 hours ago | parent | prev | next [-] |
| I watched this last week. The part about veering constantly to navigate the maze of internal politics is fascinating. The compromises he had to make, like not being able to put in on Github initially. The easy victories, like making TypeScript open source. The long road to success. The obligatory advice for people writing new programming languages (Hint: Mostly, don't.). His opinion about creating a new language for AI (I agree with his insight, but still think it is possible). Overall, well worth watching. |
|
| ▲ | socalgal2 4 hours ago | parent | prev | next [-] |
| I don't know that many languages but, having been writing lots of typescript in the last 3 years there are so many things I love about it. It infers types. If I do const data = [
{ name: 'bob', age: 35, state: 'CA' },
{ name: 'jill', age: 37, state: 'MA' },
{ name: 'sam', age: 23, state: 'NY' },
];
Typescript knows data is an array of { name: string, age: number, state: string }. I don't have to tell it.Further, if I use any field, example const avg = data.reduce((acc, { age }) => acc + age, 0) / data.length;
It knows that `age` is a number. If I go change data and add an age that is not a number it will complain immediately. I didn't have to first define a type for data, it inferred it in a helpful way.Further, if I add `as const` at the end of data, then it will know 'state' can only be one of `CA`, `MA`, `NY` and complain if I try to check it against any other value. Maybe in this case 'state' was a bad choice of example but there are plenty of cases where this has been super useful both for type safety and for code completion. There's insane levels of depth you can build with this. Another simple example const kColors = {
red: '#FF0000',
green: '#00FF00',
blue: '#0000FF',
} as const;
function keysOf<T extends string>(obj: { [k in T]?: unknown }): readonly T[] {
return Object.keys(obj) as unknown[] as T[];
}
type Color = keyof typeof kColors;
const kAllColors = keysOf(kColors);
Above, Color is effectively an enum of only 'red', 'green', 'blue'. I can use it in any function and it will complain if I don't pass something provably 'red', 'green', or 'blue'. kAllColors is something I can iterate over all colors. And I can safely index `kColors` only by a ColorIn most other languages I've used I'd have to first declare a separate enum for the type, then associate each of the "keys" with a value. Then separately make an array of enum values by hand for iteration, easy to get out of sync with the enum declaration. |
| |
| ▲ | grumpyprole 3 hours ago | parent | next [-] | | What you are describing is structural types. It is indeed a mystery that these are so under used, especially as they are a cornerstone of type theory. Structural types are so useful that they creep into most languages in some way. Even in Java, the Kingdom of the Nouns, where the rulers refused to merge a pair class, functions essentially take tuple arguments and these tuples don't have to be named and defined. You can't return a tuple though, so there is an unfortunate asymmetry. In Haskell and OCaml, we like to describe functions in a structural way, so com.google.android.Predicate would be just "a -> Bool". You wouldn't have to convert your com.google.guava.Predicate. But even these languages lack structural records and variants and suffer for it. | |
| ▲ | fuzzy2 3 hours ago | parent | prev | next [-] | | Inferred types are really great, but I feel they do not scale. Inside a method/function? Generally fine, but the signature, including the return type, had better be explicit. Also, I think there was some performance issue with too much inference? Could be wrong, could also be fixed. | | |
| ▲ | g947o an hour ago | parent | next [-] | | This. As soon as you need to use the type in another function (e.g. function parameter), you'll discover that it's better to just write it out. | |
| ▲ | epolanski an hour ago | parent | prev [-] | | They do scale, but explicit types have two bonuses in my eyes: 1. can be read without a compiler, useful when reading PRs 2. They make the compiler work less, it's easier to check than infer |
| |
| ▲ | g947o an hour ago | parent | prev | next [-] | | Even though that works reasonably well, you may still want to explicitly define your types/interfaces. In this example, if I do need to hardcode the data instead of fetching it somewhere, I would define the interface with "state" being a union of values, because there is nothing that stops you from using `state: 'ABC'` which would be hard to discover. | |
| ▲ | sfn42 4 hours ago | parent | prev [-] | | Lots of languages can infer types. And your last example with the colors is just a dictionary. | | |
| ▲ | grumpyprole 3 hours ago | parent | next [-] | | Most languages have poor support for structural types though. If you try and join two records together (like a SQL join), what will your favourite language infer then? | | |
| ▲ | sfn42 3 hours ago | parent [-] | | C# has anonymous types which is pretty much the same thing. Though I prefer to declare actual types for most usecases, I'll only use anonymous types for intermediate results and such. | | |
| ▲ | grumpyprole 2 hours ago | parent [-] | | I certainly don't mean to knock nominal types. But I think structural types are more fundamental. A language would only need a single "newtype" or "nominal" keyword to create nominal types from structural types. |
|
| |
| ▲ | sheept 3 hours ago | parent | prev | next [-] | | dictionaries generally aren't guaranteed to contain an entry for every possible value of the key type. while you could implement the colors example with a dictionary, ideally you'd want the type system to assure that given a Color, there will be a string associated with it | | | |
| ▲ | fuzzy2 3 hours ago | parent | prev [-] | | It's not a dictionary (type-wise). "as const" is the magic ingredient. |
|
|
|
| ▲ | theusus an hour ago | parent | prev | next [-] |
| Wasn’t he fired by MS? |
|
| ▲ | andrewstuart 4 hours ago | parent | prev | next [-] |
| We need Anders to make one final language. A MINIMAL memory safe language. The less it has the better. Rust without the crazy town complexity. The distilled wisdom from C# and Delphi and TypeScript. A programming language that has less instead of more. |
| |
| ▲ | bonesss 27 minutes ago | parent | next [-] | | On the .Net VM you’re describing F#, mostly by virtue of being based on OCaml. Contrasted with TypeScript and C#, F# is smaller, more expressive, stricter, with mature pattern matching and type resolution baked in from the ground up. F# was years ahead of the major languages on what are increasingly looking like ‘the basics’ around ADTs and immutability in modern distributed computing. OCaml and F# capture the linguistic high points of VB, Delphi, and C# with a broad spectrum of OOP(-lite) approaches, and have led those languages by decades on functional constructs that result in meaningfully tighter code. With the benefit of hindsight some approaches clearly map better to cloud computing and system verification. F# also sits parallel to lots of living C#, objectively we see ‘less is more’. Less code per line, fewer lines per solution, terser and more LLM-efficient language. Error rates and refactoring costs are also meaningfully better IME, but harder to quantify in general terms. | |
| ▲ | blackoil 3 hours ago | parent | prev | next [-] | | I want something that will bring productivity of Delphi to Web. May be I am old now, but I could have built applications in a weekend in Access or Visual Basic that will take weeks now in latest web stack. | |
| ▲ | tonyedgecombe 2 hours ago | parent | prev | next [-] | | >We need Anders to make one final language. I do feel like there is a gap for a modern compiled, functional and garbage collected language. Go isn't it because it lacks the functional constructs. C# and Java aren't it because they depend on a VM. Rust isn't it because of its difficult memory management. Swift isn't it because it is so tied to Apple and their platforms. | | |
| ▲ | rednb 2 hours ago | parent | next [-] | | What you are looking for is called F#. You get native interop with C# and access to all .NET/C# libraries as a bonus. We use it as a daily driver for a complex B2B2C cloud platform. | | | |
| ▲ | jorams 44 minutes ago | parent | prev | next [-] | | There are plenty of languages in that niche you could be using. OCaml, Haskell, F#... | |
| ▲ | kryptiskt 2 hours ago | parent | prev | next [-] | | C# doesn't depend on a VM these days when it is AOT compiled. Same for Java, though C# is rather more user friendly in how it goes about it. | |
| ▲ | EddieRingle 2 hours ago | parent | prev [-] | | Kotlin has a LLVM backend, among others. |
| |
| ▲ | tester756 3 hours ago | parent | prev | next [-] | | C# is way to go then | |
| ▲ | aloha2436 4 hours ago | parent | prev | next [-] | | > Rust without the crazy town complexity. To be clear, the language has a GC then? | |
| ▲ | Sharlin an hour ago | parent | prev | next [-] | | The minimal memory-safe language is Go. Turns out it's too minimal for most. | | | |
| ▲ | gucci-on-fleek 4 hours ago | parent | prev | next [-] | | What about Lua? The language is very minimal, memory safe, and has Pascal-like syntax just like Delphi. | | | |
| ▲ | LarsKrimi 4 hours ago | parent | prev | next [-] | | Oberon 07? | |
| ▲ | appsoftware 4 hours ago | parent | prev | next [-] | | What would you take out of C# etc? | | |
| ▲ | littlecranky67 3 hours ago | parent [-] | | (not OP) I would take out mostly historic stuff, that is in there for backwards compat, that has been superseeded. But this could be achieved using linters. |
| |
| ▲ | vaylian 4 hours ago | parent | prev [-] | | Sounds like golang to me | | |
|
|
| ▲ | rixtox 3 hours ago | parent | prev [-] |
| If you feel that TypeScript, or hell even JavaScript, is becoming more alike C#, it's actually deliberately done by Microsoft in benefiting their ecosystem. In this interview they mentioned they had internal demands to convert/transpile C# into JavaScript or TypeScript. So by making these target languages more like C#, it directly benefits their need. But I don't think this should be the driving force in designing ECMAScript. When they are pushing a language feature, they have an unspoken internal goal, and every choice they make is to make JS/TS look more like C#, and they are more likely to dismiss proposals that preventing them from deliverying that goal. There's likely a bit of conflict of interest there. |
| |
| ▲ | pmkary a few seconds ago | parent | next [-] | | Not at all. Before the use of TypeScript exploded, they had two features brought into it from C# which were namespaces and enums (both of which are amazingly good features. For the first one, no one knew what was the right choice back then. We had almost a dozen different module systems and TypeScript had gone their way to support all of them and namespaces were their own solution to the mess (remember they were trying to solve their own problems at first, it wasn't to dominate anything). I personally used namespaces and I could have only the TypeScript compiler running and producing a single JS file for rapid development without the burden of --- then very slow --- webpack. And for enums, using strings as enums was not a very efficient idea. I think JavaScript introduced Symbols for locked/hidden properties but also meant to use them as enums. It never worked either and then the sum type, union type feature of TypeScript made the whole community to keep using strings as enums. This is still a very bad idea, it is not ergonomic, it is prone to many problems, and very inefficient to compare strings instead of integers. But hey TypeScript tried to fix the problem and almost everyone rejected it. And so enum is now discontinued. Rest of the changes to TypeScript came from almost any other language but C#, probably the biggest changes ever to happen to JavaScript came directly from CoffeeScript. And then I personally saw how each of these new changes --- one by one --- arrived at C#. For what I have seen firsthand by reading the TC39 proposals, each feature came from a different community and different programming languages, (think about null operators !/?, the nullish coalescing ??, the incoming pipes, fat arrows and lambdas, mixings) as JavaScript is the only language everyone has to use, and it has benefited everyone to have a language that has all the great things from all other languages. | |
| ▲ | oaiey 2 hours ago | parent | prev | next [-] | | As a long term observer: definitely not a goal. But you have to be clear here: JavaScript and C# both are OO languages, both are having origins stories in Java/C++, both are facing the same niche (system development), same challenges (processor counts, ...) and so on. And then, you put teams on it which look left and right when they face a problem and then you wonder that they reuse what they like? C# language team is also really good. They did not do a lot of mistakes in the 25+ years. They are a very valid source of OO and OO-hybrid concepts. It is not only TS/JS but also Java and C++ who often look to C#. The story was not to transform C# code to JS but to use C# to write the code in the first place and transpile it. Not for the sake of having .NET usage but for the sake of having a good IDE. | | |
| ▲ | m132 an hour ago | parent [-] | | > They did not do a lot of mistakes in the 25+ years If my memory serves, .NET and WinFS were the two major forces that sunk Longhorn, and both have been given their walking papers after the reset [1]. .NET and C# have grown to be mature and well-engineered projects, but the road there was certainly not without bumps. It's just that a lot of the bad parts haven't spilled outside of Microsoft, thankfully. [1] https://www.theregister.com/2005/05/26/dotnet_longhorn/ | | |
| ▲ | Sammi 21 minutes ago | parent | next [-] | | Are we mixing the language and the runtime here? C# the language seems weirdly free of weirdness and footguns. | |
| ▲ | moron4hire 10 minutes ago | parent | prev [-] | | .NET was already a going concern before Longhorn even started. What sank Longhorn was the fact that writing an OS from scratch is hard and maintaining compatibility with existing OSes in the process is even harder, especially when you're adopting a completely new architecture. Longhorn would have been a microkernel running 100% on the .NET runtime, mainline Windows is a monolithic kernel written in C++. I don't know how it would have ever worked, whether .NET was "perfect" or not. |
|
| |
| ▲ | steve1977 2 hours ago | parent | prev | next [-] | | Well, for one, benefiting Microsoft's ecosystem does not imply being detrimental to other ecosystems per se. Furthermore, couldn't the convergence of TypeScript towards C# be simply a result of shared goals and values of the two languages, especially considering they have the same principal designer? | |
| ▲ | epolanski an hour ago | parent | prev | next [-] | | C# is inherently OOP oriented and it's type system works completely differently. | |
| ▲ | tester756 3 hours ago | parent | prev | next [-] | | It sounds like conspiracy theory that they design TS/JS to convert from C# easier, huh. The truth is that C# is probably the best designed mainstream language out there. C# was known as a language with lowest amount of WTF per LoC | |
| ▲ | froh 3 hours ago | parent | prev [-] | | that's the "evil MS" perspective The sequence of turbo pascal / delphi / c# / typescript which brought us LSP as a sidekick (!) IMHO has benefitted the whole industry at least as much as "transpile c# to ecma script via typescript" . no. much much much more. I do not see a problem with MS also having an internal use case . you know I wouldn't stop using python "because" Guido now works at MS ... | | |
|