Top
Best
New

Posted by database64128 18 hours ago

Go 1.27(go.dev)
683 points | 207 commentspage 4
SpaceManNabs 16 hours ago|
Wait generics? What changed? Why is golang accepting of generics now?
a2ff6eeb0 16 hours ago||
They landed half a decade ago...
nrr 16 hours ago||
There are some details here about the history of how generics finally came to Go: https://golang.design/under-the-hood/en/part2lang/ch08generi...

The tl;dr boils down to a combination of valuing both compilation speed and execution speed.

BeriV2 13 hours ago||
does it have goroutine termination, i recently found out you need a runtime patch for it
dolmen 2 hours ago||
The rule is to start a goroutine only if you know how it will end.

A goroutine that has to be killed (no other way to tell it to stop) is a bug.

ameliaquining 12 hours ago||
What exactly do you mean by "goroutine termination"?
tgv 6 hours ago||
I suppose: a "go" returns an id, and then you call kill(id) to terminate it, as if it were a pthread or a process. In which case the answer is: no.
ameliaquining 6 hours ago|||
Non-cooperatively terminating a shared-memory thread is an inherently unsafe thing to do, and basically every runtime that has an API for it regards it as a design mistake. See, e.g., https://docs.oracle.com/javase/8/docs/technotes/guides/concu... and https://learn.microsoft.com/en-us/windows/win32/api/processt.... (POSIX's pthread_cancel is somewhat different, and avoids some of the worst failure modes, but at the cost of not actually consistently killing the thread when you call it—and it still has a lot of problems besides that.) So I don't think Go is ever going to add this, nor should it.

(Having the go statement return a handle that you can block on would of course be completely fine, but at this point they're probably not going to do that either.)

robryan 1 hour ago||||
Can just pass it a context, cancel the context, and handle for it in the goroutine.
Fervicus 13 hours ago||
I really want to like Go, but I can't stand looking at Go code. The error handling is such a turn off.
Arbortheus 1 hour ago||
This was my original take when I learned the language, but I later realised “errors as values” is one of the strengths of the language.

I have run both Go and Python backends in production for years. There is an entire class of bugs present in Python services (missing error handling) that simply does not happen in my Go services.

Python puts the burden of knowing what exception types a function call will raise on the caller, in Go I just check for err. Even if I do not anticipate every failure mode the Go call will raise, I will always log the error and handle it in a controlled manner. I couldn’t count the number of times I’ve encountered an unhandled exception in my Python code, and often in such a case the logging will be lacklustre because you will just see a huge stack trace, but lose the contextual logging I would have automatically added in Go.

Perhaps a syntactic sugar is in order to reduce verbosity.

vrosas 12 hours ago|||
Why would you say something so controversial yet so brave?
kajika91 12 hours ago|||
Not that I like go at all but because of it my C++ is starting to look like it as I am returning tuples of [result, error].

I try to avoid exceptions, is there any better ways? (Variant looks a bit more complicated but could be a totally OK alternative)

ameliaquining 12 hours ago||
C++23 introduces std::expected, which is a simpler alternative to std::variant designed specifically for the result-or-error use case. You still don't get pattern matching, but Go-style tuples don't give you that either.
preisschild 7 hours ago|||
its simple and it works
whalesalad 12 hours ago||
Personally I feel go has many issues and is ugly as hell but the error handling is really the least of my worries.
pmkary 10 hours ago||
I'm always amazed on how the Go team has bo faith in syntax highlighting.
pregnenolone 16 hours ago||
Wasn't Go supposed to be "simple"? I remember how Go advocates used to boast about not having generics and now it almost seems like Go is trying to become some sort of C# or Java Frankenstein. I'm not even trying to badmouth Golang - just legitimately confused.
pansa2 13 hours ago||
> almost seems like Go is trying to become some sort of C# or Java Frankenstein

The original Go team was trying to avoid this:

"Java, JavaScript (ECMAScript), Typescript, C#, C++, Hack (PHP), and more [...] actively borrow features from one another. They are converging into a single huge language." [0]

That team has since moved on, and now Go has begun to join that convergence.

The problem is that most programmers seem to want to write Java, more-or-less. New, simpler languages come along, but once they get popular, the pressure is on to turn them into Java-likes. It happened to Python and now it’s happening to Go. It takes a strong will for language maintainers to say “no”, and their language will suffer in popularity as a result - see, for example, Ruby.

[0] https://go.dev/talks/2015/simplicity-is-complicated.slide#5

za3faran 13 hours ago||
I would argue that languages like Java (C#, Kotlin, etc.) strike a very good compromise between modeling ability and comprehension, which is why they are popular and people gravitate toward them.

You can have more complex languages like Scala that provide stronger modeling ability, but at the cost of complexity. Golang started off as extremely naive/simplistic, and is now converging in some ways. But it still has a ways to go: no generics on interfaces, no unions/ADTs, no pattern matching, no proper enums, error handling leaves much to be desired, and much more.

JodieBenitez 8 hours ago|||
I'm pretty sure there is a silent majority of Go users who don't want/need/know about generics.
LandR 4 hours ago||
And they can simply not use them ?
JodieBenitez 3 hours ago||
Indeed ! So I don't see what the problem is here...
kermatt 15 hours ago|||
A problem was so many others were screaming about the lack of generics, as though there were not other language options that provided them.
bikelang 12 hours ago||
Go genetics are still incredibly simple compared to languages with a rich type system.
freakynit 10 hours ago|
As I've always said: every non-functional programming language, as it matures, it's adoption rises in enterprise, eventually starts to become more and more like Java in terms of it's syntax and feature-set.
someothherguyy 10 hours ago|
because functional languages already have those features?
freakynit 9 hours ago||
naah.. they are just too different syntactically.. and the way programmers use them..