Live data from Hacker News

Go 1.22

go.dev

141–150 of 164 posts

Re: Go 1.22

#141

Perhaps I'm a dinosaur but I don't like the range-over-function addition. I don't think it adds enough convenience to justify the complexity it adds to the language, and the functional style feels at odds with Go's explicit, imperative (albeit verbose) and feature-lean style, which I think was one of its major strengths. For the same reason I think the range-over-integer feature is a misstep. Go's lean feature set an…

I'm ambivalent as well. It doesn't even save lines of code compared to passing an inline function.

Re: Go 1.22

#142
post #57

I've been writing Go for 9+ years, but for the last 4 years, I had to write a lot of Dart (for Flutter). I consider these two languages to be on the opposite sides of the complexity stance. Dart tries to add and implement every feature possible, but Go is the opposite. Two observations: 1) I'm spending a lot of time fighting multiple ways to init stuff in a class (i.e., declare the variable and set the value). Depend…

We should be optimizing for expensive experts’ ability to communicate concisely with each other. Keeping the power tools of syntax out of novice hands just deters them from developing expertise.

Re: Go 1.22

#143
post #21

Earlier quoted context omitted.

I must be getting old because I almost wish they didn't add this as it's slightly ambiguous whether it's ranging from [0, 10) or [1, 10] and anything ambiguous is probably going to haunt me at 3am some day

Interestingly, this does not raise any error, rather has no effect. for i := range -10 { panic(i) }

Sure, presumably for the same reason a C-style for loop wouldn't do anything weird there either.

Re: Go 1.22

#144
post #73

Earlier quoted context omitted.

Sure, it's always a tradeoff. Yet my pet peeve is that people rarely talk about the social aspects of the programming language. It's called "language" for a reason. We express our thoughts using this language ("I intend this code to do such and such"), and we expect other people to be able to understand what we intended, and we want to make sure that they understand exactly as we want them to. I judge languages on th…

I don't know Dart at all, but I used Java from version 1.0, and watched as it morphed and morphed again - from for-loops, to collections with iterators, then "upwards" to list and map comprehensions, closures, function pointers. My younger colleagues were writing code I could barely understand; having left that world several years ago, I still find idiomatic modern Java difficult to mentally map to intent, as you put…

My experience with Go is quite the opposite. Python may be way slower to run, but it maps to my intent extremely well. In Go, every time you try to find an item in a slice, or convert a slice to a map for faster search, or whatever, one piece of intent turns into a whole paragraph of boilerplate or a completely ad-hoc helper function.

Reading Go feels like legalese.

Re: Go 1.22

#145

I've been mostly writing Typescript the past 3 years - and recently started writing code in Go. Initially I was a little apprehensive, lack of array functions, slightly less flexible type-system, etc. But after spending some time writing Go I now had to re-initialise a typescript project for a small-ish team (4-5 devs). The amount of time spent on things such as linting, selecting the correct library for server routi…

I feel the same way. I was recently evaluating TypeScript and Go for a small project at work, having little experience with either. I went with Go almost entirely because I’d made decent progress in solving the problem by the end of my timeboxed investigation period. After a similar time with TypeScript, all I’d really done was get bogged down trying to work out what tooling I should be using.

Compilation, testing, and automatically formatting TypeScript all have multitudes of options with their own pros and cons. All that stuff is just built into the Go toolchain. Yeah it’s not always perfect but it’s more than good enough and, importantly, it’s ubiquitous. There’s nothing to think about or argue over.

That said, I’ve been wanting to try Deno. My understanding is that it takes a much more Go-like approach to running TypeScript.

Re: Go 1.22

#146

I've been mostly writing Typescript the past 3 years - and recently started writing code in Go. Initially I was a little apprehensive, lack of array functions, slightly less flexible type-system, etc. But after spending some time writing Go I now had to re-initialise a typescript project for a small-ish team (4-5 devs). The amount of time spent on things such as linting, selecting the correct library for server routi…

> can't wait for some map/filter/find slice functions though!

just use a for loop. 90% of the time the code will actually be clearer, and faster.

the hoops people just through to avoid 2 extra lines of code is mind boggling.

Re: Go 1.22

#147

Earlier quoted context omitted.

range-over-functions is the experimental new feature where a function can generate a sequence by executing a bit at a time, i.e. s := []string{"hello", "world"} for i, x := range slices.Backward(s) { fmt.Println(i, x) } func Backward[E any](s []E) func(func(int, E) bool) { return func(yield func(int, E) bool) { for i := len(s)-1; i >= 0; i-- { if !yield(i, s[i]) { return } } } } I don't think anyone expects this to w…

Yes might depend on where you come from. As someone with decades of Java experience - not a fancy language over most of its lifecycle - I was mystified why there is no Iterator support as in Java for loops.

An idomatic way to do this now is to start a goroutine and range over a channel it writes to. Less ergonomic and more error prone, but it works.

Re: Go 1.22

#148
post #90

Earlier quoted context omitted.

While the phrasing is funny, it's really more "we now have a direct equivalent to 10.times in ruby"

Algol 68 had a loop where pretty much any part was optional, so both "TO 10" and "FOR i TO 10" (if you needed a loop variable) were possible. (Back when Go came out, there were some Algol 68 comparisons, IIRC)

[deleted]

Re: Go 1.22

#149
post #50

Still holding out hope for a "go run" flag to easily run module programs with replacements in go.mod go run k8s.io/kubernetes/cmd/kubectl@v1.28.2

Yes. Many times I've forgotten to remove my local "replace" in go.mod before git pushing. Would be nice to have a runtime replace for local dev.

If you use go.work (workspace) you don’t have to touch your go.mod file. Just don't commit go.work

Re: Go 1.22

#150
post #85

Earlier quoted context omitted.

On the other hand, I advise you NOT to use this kind of library and write simple, fast go code most of the time, with the occasional generics helper. Why the hell would I clutter my code with, for example: https://github.com/samber/lo?tab=readme-ov-file#fromentries-...

I strongly agree. Map / filter isn't included, but a fair number of the various utilities are included in the standard library in the `slices` and `maps` packages. `context` also helps solve a bunch of the channel related use cases in a more elegant (IMO) way. There are only a handful of things in that package I wish were included, such as "Keys()" on a map.

FYI - “Keys()”, “Values()” and others have been pulled because they’re likely to be implemented using the new range-over-function paradigm.

They were included in the experimental packages on google.com/x.

Post reply on HN