6 ms·
Okay, now it is official, JS/TS becomes a C# clone ;) no surprise considering the TS people
by oaiey 3y ago
Okay, now it is official, JS/TS becomes a C# clone ;)
no surprise considering the TS people
- dgellow 3y agoNominal types versus structural types is basically the main distinction at this point (if we ignore .net, etc). I like both languages, happy to see them converge while keeping their defining characteristics
- CharlieDigital 3y agoWhere do C# anonymous types fall? From a functional perspective, they are a purely structural type. Here's a snippet of C# I wrote recently to transform some JSON: var transformed = media.Select(m => { var parts = m.Split('/'); return new { addedAtUtc = "2023-05-15T05:59:31.398Z", originTripUid = parts[4], path = $"{parts[4]}/{parts[5]}", rank = "", size = 103978, stored = true, type = "document", }; }) File.WriteAllText( Path.Combine(Environment.CurrentDirectory, "output.json"), System.Text.Json.JsonSerializer.Serialize(transformed) ); It would be easy to mistake this as JS at a quick glance.
- oaiey 3y agoAnonymous types are nominal types (like all others in .NET). They are just auto-generated and auto-named. Duck Typing at runtime is possible and to a degree checkable and compile-time.
- CharlieDigital 3y agoI get that; that's why I qualified it as a "functional perspective" because even though the underlying implementation is an auto-generated, auto-named type, the functional usage of it is a structural type (with limitations).
- AshleyGrant 3y agoThey aren't structural because the following doesn't work in C#, but would work (with tweaks to make it valid code) in a structurally typed language such as TypeScript: var transformed = media.Select(m => { var parts = m.Split('/'); return new { addedAtUtc = "2023-05-15T05:59:31.398Z", originTripUid = parts[4], path = $"{parts[4]}/{parts[5]}", rank = "", size = 103978, stored = true, type = "document", }; }).ToList(); transformed.AddRange(otherMedia.Select(m => { var parts = m.Split('/'); return new { addedAtUtc = "2023-05-15T05:59:31.398Z", originTripUid = parts[4], path = $"{parts[4]}/{parts[5]}", rank = "", size = 103978, stored = true, type = "document", documentType = parts[6] }; })); Adding "documentType" breaks in C# but would work in a structurally typed language as a structural type checker can see that the second result fulfills all of the necessary properties. Doing this in C# would require creating an interface and being explicit.
- littlecranky67 3y agoUnless you were using the (yet unimplemented) exact types in TS. https://github.com/Microsoft/TypeScript/issues/12936 https://github.com/Microsoft/TypeScript/issues/12936
- AshleyGrant 3y agoSure, but that would be opt-in if it were ever implemented. I think both styles of type system have their pros and cons. I have loved the cross-pollination between C# and TS with great ideas flowing in both directions.
- RyanCavanaugh 3y agoRuntime type systems: TS has none; C# has extensive RTTI Function dispatch: TS is purely dynamic; C# has both static and dynamic OOP: Mandatory in C#, optional in TS Variance: Implicit in TS, explicit in C# Numeric types: TS has one (number); C# has the entire signed/unsigned/float x 8/16/32/64-bit matrix There's really no intentional effort to converge them.
- dgellow 3y agoYour list of differences is correct but not really what I meant. The points you listed are mostly due to JS runtime constraints. The choice of nominative vs structural type system is purely a design choice by the typescript team.
- no_wizard 3y agoTS has two. number and bigint[0], corresponding to Number and BigInt in JS, respecitvely [0]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#bigint https://www.typescriptlang.org/docs/handbook/2/everyday-type...
- AbuAssar 3y agobut using keyword will be in js eventually as it is in stage 3 now
- garganzol 3y agoAnd this is a good thing. I would love to see something like a proper C# instead of a hacky TypeScript. It would be so much more productive. JavaScript is a cool dynamically-typed language though. C# is on another side of the spectrum: it is super cool by being fully strongly-typed. But TypeScript is something in the middle and this uncertainty gives pains.
- oaiey 3y agoBut that is the niche of TypeScript. It supports a dynamic typed language by enabling some but not all benefits of typed languages.
- chris37879 3y agoI find that Dart rides that middle line much nicer than typescript does, at least for now. As of Dart 3, you can now have sound null safety, and sound type safety for 100% of your code, if you want. The recent addition of records also makes working with some of javascripts methods with multiple return types better, as that is one of the things dart is still missing, union types. Though, I tend to prefer dart over typescript just because of not having to deal with the node ecosystem at all.
- deleted 3y ago[deleted]
- m_0x 3y agoToo bad Dart is only used in Flutter.
- chris37879 3y agoThat’s your choice, I suppose. I use it for everything from flutter to CLI to Cloud Functions to WebUi to daemons in tiny containers.
- garganzol 3y agoAny way to use Dart with React in a .jsx way? It looks like Dart has exclusive support for Flutter, and that's it.
- amitport 3y agoit's really not a c# clone. If anything JS is still more similar to python that it is to c#. JS already has 'with', so 'using' seems like to closest semi-standard keyword to use.
- moritzwarhier 3y agoOf course this does not change the fact that it is a reserved keyword, but "with" is prohibited in strict mode and as such also in any ES Module. I assume this also applies to any TS module regardless of the compiler. But since TS is supposed to be a superset of JS, of course this does not change anything
- oaiey 3y agowhen you substract everything what C/C++/Java is, this will be interesting comparison what is closer ;)
- gosukiwi 3y agoThat was my first though, but a) it seems that the `using` syntax is not exactly the same as in C# (unless the old C# I used to use) and b) still I wouldn't mind, C# is a great language
- nathias 3y agowasn't that the goal from the start