6 ms·
But because they had an existing body of code that was not class based, it would be more of a re-write (C#) versus a refactor (Go). I don't understand this rea
by Teckla 2y ago
But because they had an existing body of code that was not class based, it would be more of a re-write (C#) versus a refactor (Go).
I don't understand this reasoning at all, and I'm hoping you can shed some light on it.
As far as I know, C# supports static methods. Thus, using OO in C# would not have been required, would it?
I feel like I'm missing something here.
- Kipters 2y agoThat wouldn't feel very idiomatic - you can do it but would feel wrong
- int_19h 2y agoC# supports top-level functions as well, that's not the issue. But, just to give a simple example, in TS you can do things like: var foo: { bar: { baz: string } } which have no equivalent in C#, because it doesn't have anonymous struct types, and its typing system is almost entirely nominal. Go, on the other hand, can translate this directly pretty much mechanically: var foo struct { bar struct { baz string } } And keep in mind that they aren't completely ditching the existing implementation, either, so for a while they're going to have to e.g. fix bugs in both side by side. It helps when the code can also be mapped almost 1:1.
- CharlieDigital 2y agoThe interesting thing is that you can do this in C# with tuples because tuples can nest tuples. type Platform = "Mastodon" | "Bluesky" | "Threads"; type Profile = { name: string, socials: { handle: string, platform: Platform }[] } function getProfiles() : Profile[] { return [{ name: "Charles", socials: [ { handle: "@chrlschn", platform: "Mastodon" }, { handle: "@chrlschn", platform: "Bluesky" } ] }, { name: "Sandra", socials: [ { handle: "@sndrchn", platform: "Threads" } ] }] } Versus: using Profile = ( string Name, ( string Handle, Platform Platform )[] Socials // Array of tuples in another tuple ); enum Platform { Mastodon, Bluesky, Threads } Profile[] GetProfiles() => new[] { ("Charles", new[] { ("@chrlschn", Platform.Mastodon), ("@chrlschn", Platform.Bluesky), }), ("Sandra", new[] { ("@sndrchn", Platform.Threads) }), }; With some caveats
- afiori 1y agoI would love if in mapping the typescript types to go they ended up building a "compiler plugin" to enhance go's type system.
- bheadmaster 1y agoTypeGo by Microsoft (TM). Considering how fast the TypeScript compiler is, the TypeGo -> Go transpilation might as well be similar (up to a constant factor) in speed to Go compilation itself. I'd give it a try. As a highly enthusiastic Go programmer, a powerful TypeScript-like type system is something I'd welcome in Go with open arms.