News for hackers. Stuff that matters.
Re:Why people are angry over Go 1.23 Iterators by unscaled on Tuesday June 18, 2024 @12:06AM (#40713969)
This is the textbook definition of the Blub Paradox[1]. If you've mostly used Go (or moved to Go from JavaScript before it had iterators, or from Java where iterators are a royal PITA to write), it won't make sense. That's okay, since it is often hard to imagine how a feature will be used without getting used to it yourself. I'm pretty sure that most FORTRAN 66 developers coming to Go would be puzzled on why you need for loops at all, when you can write DO loops and specify the line number where the loops end (older Real Programmers[2] don't even understand why you need loops at all, since you can always GOTO anywhere you'd like).

So to cut it short, iterators, as Go implements them, should be useful at least for the following cases:

- Iterating over custom collections (e.g. trees, concurrent maps, queues) that are not provided by the language (and "range for" doesn't have custom code for inside the compiler).

- Iterating over a collection in a different way, for instance filtering out some elements or iterating over the collection backwards (as in the giving example).

- Reification - if abstract iterators can be passed to functions (instead of actual slices), you can write functions that operate on a theoretically infinite stream.

- Chaining iterators. If iterators can be reified, you can also chain them together. This is somewhat cumbersome with the syntax Go 1.23 will offer, but in many languages you can write code like this:

  let incompatibleTransactions = user.Accounts
    .Filter(account -> account.Balance <= 0)
    .FlatMap(account -> account.PendingTransactions())
    .Filter(tx -> !tx.AllowCredit())
  
Once you know what each function does, it is clear that the code goes through all the accounts that have a zero or negative balance and returns all the pending transactions that do not allow credit from these accounts.

The equivalent imperative code is harder to figure out at first glance

  incompatibleTransactions := []Transaction{}
  for _, account := range user.Accounts {
     if account.Balance < 0 {
         for tx := range account.Transactions {
             if !tx.AllowCredit() {
                 incompatibleTransactions = append(incompatibleTransactions, tx) 
             }
         }
     }
  }
If the accounts and transactions collections are not built-in the iteration code would even look worse. This code is harder to read since it conflates the What (what we want to achieve with the code) with the How (how to implement this with a for loop). Obviously, this is what imperative programming is all about, and Go is indeed becoming less imperative.

[1] http://wiki.c2.com/?BlubParadox [2] https://sac.edu/AcademicProgs/Business/ComputerScience/Pages...

Re:Why people are angry over Go 1.23 Iterators by neonsunset on Tuesday June 18, 2024 @02:36AM (#40714704)
Yup.

This is why I'm despairing so much over Go's popularity after using C#/F# and Rust which have rich and idiomatic iterator APIs. Go implementation is plain ugly, flawed and, most of all, is going to be slow unless you write it in the most verbose way due to Go's compiler weakness.

There are languages that move us forward, Go sets us back by 20 years.

Re:Why people are angry over Go 1.23 Iterators by Karrot_Kream on Tuesday June 18, 2024 @04:21AM (#40715317)
Some people enjoy expressiveness in their programming language. Some people don't. Some people like both, I'm one of them, and for some programs I choose expressive languages like Haskell or Common Lisp and for others I use unexpressive languages like Go or Zig.

Take these things a little less personally. Live and let live. People think differently from you, and that's okay.

Re:Why people are angry over Go 1.23 Iterators by neonsunset on Tuesday June 18, 2024 @07:23AM (#40716437)
This is not about personal choice but rather Go's undeserved adoption in domains it has absolutely zero business being applied to. This leads to me to generally approach engineers promoting it as misguided and severely lacking in some area of knowledge the moment Go is suggested to be used anywhere beyond light networked microservices or CLI utilities.

Instead, people shoehorn it into data processing and databases, the domain at which .NET is incomparably more adept due to performance primitives it offers, if we still talk high-level-ish languages with automatic memory management. Of course if there is no such requirement, there are many (like Zig, Rust and C++) systems programming languages that are better in every possible way at solving the task. And yet, we get Go and startups struggling to scale. But all the interesting problems in which Go is attempted to be applied to, where the solution, if successful, is despite Go not because of it, would have benefited from C#/F# which offer much better control and performance assurances, without having to fight the tool.

Re:Why people are angry over Go 1.23 Iterators by Karrot_Kream on Tuesday June 18, 2024 @01:24PM (#40720105)
Take these things a little less personally. Live and let live. People think differently from you, and that's okay.

I have meticulously benchmarked Go in previous roles and also used Go as a load generator and with smart allocation strategies the language is quite fast. I think you're letting your emotions cloud your judgement but that's nothing new in PL discourse. There's no better way to bring out those that identify with/against programming languages than PL discourse.

Re:Why people are angry over Go 1.23 Iterators by samatman on Tuesday June 18, 2024 @01:55PM (#40720402)
> I use unexpressive languages like Go or Zig

See, I would not call Zig unexpressive. I've written a number of iteration structs in Zig, because it has true optionals this is easy, using them is just:

    var iter = thing.iterateSomeWay();
    while (iter.next()) |item| { 
        // do stuff
    }
It's a low level language, yes, but an expressive one given that design constraint. Go just makes this stuff harder, because nil is just zero wearing a costume, an antipattern it inherited from C. In Zig every type can be nullable, and the compiler takes care of representing the null case distinctly from the load-bearing one.
Re:Why people are angry over Go 1.23 Iterators by pjmlp on Tuesday June 18, 2024 @07:25AM (#40716454)
Unfortunately Microsoft is also to blame, instead of .NET, all their Azure contributions to CNCF are based on Go and Rust, and all their recent CLI tools are written in Go (older ones used Python).

Also by not doing enough to make UNIX culture startups have a different opinion of Microsoft, instead of still doing M$ jokes.

The same kind of startups that won't have any qualms adopting Swift, or dealing with its current poor state on GNU/Linux.

Re:Why people are angry over Go 1.23 Iterators by foldr on Tuesday June 18, 2024 @04:41AM (#40715411)
I've used plenty of languages with iterators but have also never really missed them very much in Go. So I think this is a flawed analysis. The proposed Go iterators are just syntax sugar over some existing code patterns. They'll be nice to have but one can very easily do without them.

By way of analogy, consider that almost any language is missing lots of features present in some other languages. For example, Go does not have inheritance. If I do not miss that feature while using it, that does not necessarily mean that I'm a Blub victim.

Re:Why people are angry over Go 1.23 Iterators by klabb3 on Tuesday June 18, 2024 @05:53AM (#40715801)
GP here. Yeah I don't think I’m blubby in that sense. I used to work daily in Rust, including with custom collection types. And lots of other language experience with iterators. Go has maps and slices, and slices fit 99% of my use cases. You can index, reslice, concat, append, sort, sort by, clone, and yes, iterate with range (although the range syntax itself is merely a small convenience).

As for the chaining, yes I do miss filter and map but is again totally doable with vanilla slices (they just haven’t added those methods to the slices package).