←back to thread

Constraints in Go

(bitfieldconsulting.com)
211 points gus_leonel | 1 comments | | HN request time: 0.372s | source
Show context
indulona ◴[] No.42163167[source]
i have been writing Go exclusively for 5+ years and to this day i use generics only in a dedicated library that works with arrays(slices in Go world) and provides basic functionality like pop, push, shift, reverse, filter and so on.

Other than that, generics have not really solved an actual problem for me in the real world. Nice to have, but too mush fuss about nothing relevant.

replies(10): >>42163189 #>>42163244 #>>42163415 #>>42163694 #>>42163834 #>>42164296 #>>42164983 #>>42165141 #>>42165270 #>>42165680 #
throwaway63467 ◴[] No.42163189[source]
Honestly so many things profit from generics, e.g. ORM code was very awkward before especially when returning slices of objects as everything was []any. Now you can say var users []User = orm.Get[User](…) as opposed to e.g var users []any = orm.Get(&User{}, …), that alone is incredibly useful and reduces boilerplate by a ton.
replies(3): >>42163242 #>>42163295 #>>42168753 #
vbezhenar ◴[] No.42163242[source]
ORM is anti-pattern and reducing boilerplate is bad.
replies(5): >>42163314 #>>42163315 #>>42163626 #>>42163744 #>>42168321 #
bluesnews ◴[] No.42163315[source]
Could you expand on this?

I don't like ORM because in my experience you inevitably want full SQL features at some point but not sure if you have the same issues in mind or not

replies(1): >>42163404 #
vbezhenar ◴[] No.42163404[source]
ORM is for object-relation mapping. Go is not object-oriented language and OOP-patterns are not idiomatic Go, so using ORM for Go cannot be idiomatic. That's generic answer. As for more concrete points:

1. Mapping SQL response to maps/structs or mapping maps/structs to SQL parameters might be useful, but that's rather trivial functionality and probably doesn't qualify as ORM. Things get harder when we're talking about complex joins and structs with relationships, but still manageable.

2. Introducing intermediate language which is converted to SQL is bad. Inevitably it will have less features. It will stay in the way for query optimisations. It'll make things much less obvious, as you would need to understand not only SQL, but also the process of translating intermediate language to SQL.

3. Automatic caching is bad. Database has its own caching and if that's not enough, application can implement custom caching where it makes sense.

In my opinion the only worthy database integration could be implemented with full language support. So far I only saw it with C# LINQ or with database-first languages (PL/SQL, etc). C# and Go are like on opposite spectrum of language design, so those who use Go probably should keep its approach by writing simple, verbose and obvious code.

replies(2): >>42163641 #>>42163647 #
indulona ◴[] No.42163641[source]
> Go is not object-oriented language

That is most definitely not true. Go just uses composition instead of inheritance. Still OOP, just the data flow is reversed from bottom to the top.

replies(4): >>42163740 #>>42164085 #>>42164581 #>>42194567 #
1. frou_dh ◴[] No.42194567[source]
It goes like this:

1. Software development is a fashion industry.

2. OOP is currently uncool.

3. People who identify as Go programmers don’t want it to be thought of as connected to OOP at all, because then it is uncool by association.