←back to thread

Constraints in Go

(bitfieldconsulting.com)
210 points gus_leonel | 2 comments | | HN request time: 0s | 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. nordsieck ◴[] No.42164085[source]
>> Go is not object-oriented language

> That is most definitely not true.

I think at best, you could say that Go is a multi-paradigm language.

It's possible to write Go in an object oriented style.

It's also possible to write programs with no methods at all (although you'd probably have to call methods from the standard library).

That's in contrast to a language like Java or Ruby where it's actually impossible to avoid creating objects.

replies(1): >>42164205 #
2. pjmlp ◴[] No.42164205[source]
Unless you happen to want to warm up the CPU, there is very little Go code that is possible to write that does anything useful without OOP concepts, like interfaces, methods and dynamic dispatch.

Creating objects on the heap isn't the only defining feature how a language does OOP or not.