Live data from Hacker News

Generics enabled by default in Go tip

go-review.googlesource.com

311–320 of 378 posts

Re: Generics enabled by default in Go tip

#311
post #293

Earlier quoted context omitted.

IMO, “learning the language” and “getting used to it” are different things. The first is a purely theoretical exercise, the second a applied one that involves not only the language but also its ecosystem (implementation(s), library of functions and tooling)

I am not sure if we are agreeing or not, but I feel like we are. I think when people refer to "learning" a language, they mean they actually know how to use it properly. Learning the syntax does not count - that is just trivia any one of us can do.

(Nitpick: I assume you mean learning both the syntax and the semantics. That isn’t always trivial, as some languages have features one may not have seen before)

I think we mostly agree, too.

However, I distinguish between learning a programming language and learning to use it. I learn many programming languages without ever writing any line of code in them.

Once you’ve seen enough languages, if you combine that with reading about other people’s experience with working with the language, that can give you a decent idea about how the latter is without having to spend the effort (without being as good as doing it yourself, of course. Apart from “which one is the brake pedal”, I think I know how to drive a car, but I also know I can’t drive a car)

That’s why I posted my first comment: the poster you replied to may share my opinion between “learning” and “learning to use”.

Re: Generics enabled by default in Go tip

#312
post #107

Earlier quoted context omitted.

You say "verbose and repetitive", I say "easy to read without any surprises". The verbose patterns (if err!= nil for example) make the code predictable to read, you notice the code smell of missing error handling really fast.

I think readability has multiple dimensions, and it really depends what you are looking for. For example here's a code in Go to look for a Prime: func IsPrime(n int) bool { if n It's readable as it is simple to understand what each line does. Here for example is a code that does the same thing in Rust: fn is_prime(n: u64) -> bool { match n { 0...1 => false, _ => !(2..n).any(|d| n % d == 0), } } It's might seem more c…

Go is crazy verbose. Even Java can do it much more simply:

    static boolean isPrime(int n) {

        return switch (n) {
            case 0, 1 -> false,
            default -> !IntStream.range(2, n).anyMatch(i -> n % i == 0)
        }
    }

Re: Generics enabled by default in Go tip

#313
post #255

Earlier quoted context omitted.

No, it's relative. For the top 5% - 10% of developers, generics are a useful tool for doing their job efficiently. For the bottom 50% of developers, generics are complex and confusing, and only provides more footguns.

And the top 1% of developers know that you are most productive when you stick to the simplest primitives ;) I jest, but I also don't. All the best developers I know strongly prefer footgun-free libraries and primitives. The advantage is that you don't _need_ to spend brain cycles checking and double checking that it was written correctly, and when you want to make changes you don't need unwind an elaborate abstractio…

Generics use the type system to make the compiler check the code for you. It makes the code easier to understand, more correct, and concise if you use them as they were intended. It avoids tedious and error prone duplication of logic. Create ONE efficient debugged implementation and reuse it as much as possible. The crappy workarounds for generics introduce their own complications and issues.

But I know what you mean. I've worked on Scala code for years and seen less mature developers over-engineer things and get way too clever with the type system. Scala is a really practical and powerful industrial language that requires some maturity to use the abstractions sparingly. It's only good for the top 5% of developers.

However, Go doesn't have such a powerful type system. It looks like the Go designers implemented relatively simple generics. You have to draw the line somewhere. If simple Go generics are too confusing and complicated then that developer should probably find another job, as generics are a basic concept in programming. The Go designers are pragmatic people, and they've decided that relatively simple generics will make things easier in mainstream commercial codebases.

Re: Generics enabled by default in Go tip

#314

Language flamewars on internet forums are... strange. Why have we all so strongly coupled our identities as programmers to the language we use? Sense of community and a perceived need to defend it? I don't think Go needs generics, but I'm not about to invent obscure edge cases to justify for/against the idea. That's a recurring theme in all defenses of any language. It's not helpful. Use Go if you like the "clarity",…

For me it's about paradigms the language represents. I try to extend the simplicity of golang all the way to the network architecture. I've learned that it's better to build many very very simple things and connect them. Not for any technical reasons, but because it allows other developers to quickly begin adding to and fixing your systems. You get to leverage the large amount of mediocre programmers when your system…

> I've learned that it's better to build many very very simple things and connect them. Not for any technical reasons, but because it allows other developers to quickly begin adding to and fixing your systems. You get to leverage the large amount of mediocre programmers when your systems are simple instead of looking for heros. It's definitely easier said than done though to make systems naturally intuitive and simple.

Creating a bunch of microservices and connecting them has just moved your complexity from the "monolithic app" kind to the "integration" kind. It's much harder to understand the potential impact of your changes when "anything" could be using a service via the network.

It's a trade off here. If you have integration complexity, you need integration heroes.

> I've also learned that in most cases you don't need to invent some giant application. It's far easier to create extensions or wrappers to existing operations or service tools, with a bonus (again) being easier hiring and delegation. You can hire someone who knows a standard piece of tech and quickly ramp them up on a small extension or wrapper that you wrote. Golang is the language that made me always take this simple approach first and look for something that does 80% of what I need and think about problems very generically.

This is a great idea. Leverage industry experience when and where you can. Minimize the amount of "tribal knowledge" that your team requires to be effective.

Re: Generics enabled by default in Go tip

#315
post #213

Earlier quoted context omitted.

I don't have problem with being strong typed, I like that as well. The problem is that the stdlib doesn't really support other types and that's mostly due to lack of generics, so using uncommon types becomes quite annoying.

TBF the float Min/Max issue has nothing to do with generics, there isn't a "floating-point" generic class, and the entire reason why Go has an f64 Min/Max in the first place is that floats are not fully ordered[0], so you "can't" use regular comparisons (which you'd be told to do for integers) and thus you could not have a generic min/max relying on that even if there was one (e.g. in Rust `f32` and `f64` are not `Or…

I'm aware of it, in the example given I used float32. Anyway Max/Min was just example I used other functions from math as well.

Anyway my point was that with generics, they wouldn't need to copy anything, the math package would work with both float32 and float64 and many functions likely would also work on all integers.

Re: Generics enabled by default in Go tip

#316
post #301
post #297

Earlier quoted context omitted.

There is no doubt that Go needs generics. Pretty much every Go container and data structure library on github will benefit from generics. The empty interface is used everywhere , leading to all kinds of panicking typecasts, hard to debug errors, and inefficient conversions. The vast majority of these uses can be made type-safe, more efficient, and clearer with generics. There is nothing subjective about the benefits…

There's some pain in writing generic data structure algorithms for sure. It would have been an interesting experiment though if the Go authors would have tried to improve the tooling around code generation and making it easier to use, as an alternative avenue to generics as code generation might satisfy some of the cases likely to trigger those complains. Anyway, interesting to see how far they will take the generics…

It isn't as if previous languages did not used code generators before generics were a thing on them.

Re: Generics enabled by default in Go tip

#317

Earlier quoted context omitted.

> Go adds generics. HN thread: I don't want this If generics are a good idea for a language, then it's better to add them in version 0.01 of the language and build up from there with generics as an intrinsic part of the language and standard libraries. No, I don't want _tacked on_ generics. Generics are not in 2021 a "bleeding edge" feature, that _might_ be useful later. They are established and proven in ways that t…

No, I don't want _tacked on_ generics. What languages in your opinion have good, non-tacked-on generics? Are they generally better than other languages? Here are some pretty successful languages that gained generics after maturity: C++, Java, C#, TypeScript (based on JavaScript), Objective-C, even Python.

Ada, ML, Modula-3 and CLU got generics since day one.

In fact, so much research and Go generics are mostly similar to CLU.

Re: Generics enabled by default in Go tip

#318

Every HN thread about go: go is useless because it lacks generics. Go adds generics. HN thread: I don't want this. Good case study about the people drawn to comment on a topic.

From what I have seen over the years, the "I don't want generics" crowd showed up just as often as the "Go is useless without generics" crowd. This time, though, only one of those groups can reasonably continue to comment.

[deleted]

Re: Generics enabled by default in Go tip

#319
post #42

Earlier quoted context omitted.

a couple high profile projects (k8s) needed generics, there are limited use cases outlined in the planning docs that detail the holes in the language they're filling, it wasn't just squeaky wheels.

Shame how k8s was a failure without generics. Think what could have been.

UNIX was re-written in a clunky unsafe systems programming language, by being free beer due to legal impositions on research work, its adoption settled the future of this language across the industry.

Yet even C supports lightweight generics, so they must be worth something.

Re: Generics enabled by default in Go tip

#320
post #53

Earlier quoted context omitted.

If i wanted or needed generics i would use another language. I have been able to write great code without them for 5 years now though. But now i get to defend my codebases from the unneeded introduction of them from largely developers who think they are too smart.

you sound like you're too smart for generics.

No I’m likely too dumb for them but my code base is clean and easy to onboard people to. I take great pride in new hires telling me something is easy to do after only working in it a week

And like i said generics have a place its just a way smaller place than many people think

Post reply on HN