While simple, code duplication can be a pain when you need to change existing code. Instead of making the change in one place, now you need to do it in many different places and you must ensure not to forget any of them. Otherwise, it may cause bugs, some of which may be subtle. It gets worse if the code is some else's work that you may not be thoroughly familiar with. Of course, being engineers that we are, we can find workaround to mitigate the problems using testing, documentation, project organization, IDEs, etc.
There is nothing wrong with Go not having generics. However, dissing generics as if it is useless is just not right. It's all about having the right tool for the job.
-j
Not true. interface{} and reflection is, for example, used by fmt.Printf for purpose where generics won't help. Alternatively everything must have a Format() method. But predeclared types cannot have methods.
func reduce<A,B>(array []A,out B,in A)B {}
used by fmt.Printf for purpose where generics won't help.
I love playing with package reflect, which is much more powerful than generics by the way (you can't implement gob or json with generics).
-j
I was watching rus cox's last talk and he mentioned that not every problem should be solved by language change. Some can be solved by tooling or library change.I am curious has any of the generics lovers written a tool that helps for generic behavior. Something like,*
Also, building a basic one yourself if you don't want to use those tends to be exceptionally straightforward.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Also, building a basic one yourself if you don't want to use those tends to be exceptionally straightforward.Thanks for examples, i can't tell if they are experimental or viable for production use.
But if it's that straightforward, why people complain about it too much.
I just want to know sincerely, if people REALLY need generics so much, or they are just complaining because they are used to it and it's in their favorite programming language.
What changes would improve Go most?
1 generics
- You don't need generics to write Kubernetes.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
On Sat, 29 Jul 2017, 23:59 Shawn Milochik, <shawn...@gmail.com> wrote:
- You don't need generics to write Kubernetes.
I've had no personal need for generics, but k8s client-go is the one case I've seen where I thought they would help, the informers packages in particular.
> import hpaInformer informer<v2alpha1.HorizontalPodAutoscaler>
>
> myInformer := hpaInformer.New(sharedUnderlyingCacheThing)
So... to me, the implementation of NewHorizontalPodAutoscalerInformer looks
pretty much exactly like what you've got there, where sharedUnderlyingCacheThing
is the result of cache.NewSharedIndexInformer as called currently in the
code. That is, that constructor inside the call to NewSharedIndexInformer
seems a lot like a constructor for sharedUnderlyingCacheThing to me.
I'm not entirely convinced that generics would make the code much
cleaner in this case.
You might want to experiment by refactoring some of that k8s code to use
generics (using whatever your preferred formulation might be) and see
what it might look like, and whether it looks significantly
nicer/simpler/cleaner
as a result
I suspect that it might not look that much different - whether you're using
type-parametric polymorphism or interfaces, somehow you've got to
plug the specific code into the generic code, and that existing k8s code
doesn't look like it has that much redundant boilerplate to it.
cheers,
rog.
We use sets in the graph packages, but the number of set types is
pretty limited (sets of nodes and sets of either int or int64) and
map[T] works for that level of use.
The only other place where it might be useful for us is in in place of
generating float32 versions of float64 blas and lapack implementations.
Honestly, I've never really felt a lack.
On Mon, 2017-07-31 at 05:50 -0700, Mandolyte wrote:
> It's been many years since I was involved in developing complex
> systems
> (C++ and Java). But I agree, it was mostly lists and sets with
> searching
> and sorting. But I also used them for algorithms a good bit. Thus I
> would
> guess that the maintainers of GONUM libraries might benefit (anyone
> confirm?).
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
it's amazing to see what people were able to accomplish with 2KB RAM, *one* general-purpose register, no hardware multiply/divide,
Go to me is an awesome little house on a beach. I love going to it in the summer. Everything is great about it. Almost. It just doesn't have hot water. I have to heat water myself and carry it for a 1/4 mile every time I want to shower. It's kind of annoying, but not a big deal in itself to make me stop going to the awesome super fun summer house.
COPY PAYLIB REPLACING A BY PAYROLL B BY PAY-CODE C BY GROSS-PAY D BY HOURS.
"Halfway the functional design of the X1, I guess early 1957, Bram and Carel confronted me with the idea of the interrupt, and I remember that I panicked, being used to machines with reproducible behaviour. How was I going to identify a bug if I had introduced one? After I had delayed the decision to include the interrupt for 3 months, Bram and Carel flattered me out of my resistance, it was decided that an interrupt would be included and I began to study the problem. To start with I tried to convince myself that it was possible to save and restore enough of the machine state so that, after the servicing of the interrupt, under all circumstances the interrupted computation could be resumed correctly."
-j
In my opinion generics added to Go would make Go really take off. Currently Java developers would not change to Go. With Go having generics this would change and more people would consider Go also when not coming from Java/C#/etc.
I beg to differ. Most Java apps I have seen over many years almost unanimously suffer from over-modeling. That Go encourages another style of modeling does not make it too simple. It only makes it different which may be good or bad according to taste.
That said, I personally think that generics would be a net win if it was somehow possible to design a version of it that still encourages simple abstractions rather than the complicated mess so often seen.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
I quite agree: I suspect it a tradeoff, in which the more you can easily represent, the more you need to carefully architect exactly *what* you represent.