News for hackers. Stuff that matters.
Re:What makes you enjoy Go lang? by pass-by-value on Monday April 24, 2023 @10:03PM (#35695734)
I like being able to unmarshal a json response into a typed struct. That gives me the ability to get intellisense in my IDE. Then I don't have to guess what the json response shape looks like. It also helps me prevent issues with trying to access invalid keys in the json response. This really helps when dealing with an external API.
Re:What makes you enjoy Go lang? by isanjay on Monday April 24, 2023 @11:51PM (#35696338)
This is similar to other types languages no ?
Re:What makes you enjoy Go lang? by rcme on Tuesday April 25, 2023 @12:16AM (#35696433)
Kotlin is the only statically typed language that has the same ergonomics as Go (that I know of), and even then you need an external dependency.
Re:What makes you enjoy Go lang? by beatbrot on Tuesday April 25, 2023 @01:14AM (#35696747)
Java can do the same with a library like Gson or Jackson
Re:What makes you enjoy Go lang? by didip on Tuesday April 25, 2023 @02:31PM (#35704696)
Jackson is no where near as convenient as Go's marshaling system.
Re:What makes you enjoy Go lang? by isanjay on Tuesday April 25, 2023 @11:23AM (#35701755)
.NET has System.Text.Json.

I wonder how does it compare to go's implementation

Re:What makes you enjoy Go lang? by rcme on Tuesday April 25, 2023 @02:43PM (#35704848)
.NET is ok, but the classes you make serializable generally aren't how you'd write a normal class, which is what I mean by "ergonomic." As far as I know, you need your fields to be public for both reads and writes, and you need to write a separate constructor if you want to create the types programmatically. Go lets you serialize objects more-or-less how you'd write them without serialization, as does Kotlin.
Re:What makes you enjoy Go lang? by hakanderyal on Wednesday April 26, 2023 @04:03PM (#35719222)
Record types introduced in C# 9 solves this.

It's now as simple as

record SomeData(string Name, int Id);

Which gives you an immutable object, auto generated constructor, and some additional helpers to make life easier.