News for hackers. Stuff that matters.
Re:Go proposal: new package to provide generic slice functions by Cthulhu_ on Wednesday May 05, 2021 @10:42AM (#27050448)
One of Go's objectives is to have a simple and fast compiler; emphasizing simple and readable code will ensure that. It's one reason why type arguments were put off for as long as they have been.
Re:Go proposal: new package to provide generic slice functions by kubb on Wednesday May 05, 2021 @11:57AM (#27051577)
This is the decade-long argument of "let's sacrifice all our programmers to the devil so that we don't have work as hard on the compiler". I don't buy it, and it has never been demonstrated that the cumbersome style of writing go programs is helping compilation times, yet people keep saying it as if it's a fact.
Re:Go proposal: new package to provide generic slice functions by jolux on Wednesday May 05, 2021 @12:22PM (#27051933)
The cumbersome style seems to have become a strong part of the culture, almost a masochism about the limited features of the language. I find this ironic because I believe Go was intended to be highly pragmatic originally but it seems to have evolved an almost Scheme-like dogmatism about language complexity.
Re:Go proposal: new package to provide generic slice functions by skywhopper on Wednesday May 05, 2021 @02:13PM (#27053559)
Do you have specific examples you’re thinking of? Calling it masochism is weirdly insulting. Adding complexity is a one-way street. Languages live for decades. There’s no reason to rush adding features in a half-baked way, and the tradeoffs in terms of compiler complexity are very real.
Re:Go proposal: new package to provide generic slice functions by stouset on Wednesday May 05, 2021 @03:52PM (#27054827)
Virtually every large go program I've read has asymptotically reached 50%+ of its code being

    if res, err := fn(...); err != nil {
        fmt.Errorf("Look ma, I'm a human exception handler: ", err)
    }
This is held up as a positive thing, because handling errors is explicit and good. Somehow, the Rust equivalent of `?` is implicit and bad, despite desugaring to almost literally the exact same thing and being actually impossible to forget or overlook due to the return type of the function enforcing a Result.

In the same breath, devs will assert that the language is "low boilerplate" (despite 50%+ LOC being just one type of boilerplate) because Error Handling is Important. Which seemingly ignores that the important part of error handling is actually ensuring that errors are handled and not the mechanistic act of self-flagellation by wrapping every line of code in nearly-identical error handling ceremony. Which is unfortunate because golang doesn't do so great a job with the first part. It's surprisingly easy to actually forget to do something with the error while carrying on with a return value whose semantics are undefined (unlike Rust's Result, where you can have an error or a value and not both).

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @06:33PM (#27056668)
I use Go a lot and I really like Rust, so maybe I can add some context. Error handling boilerplate isn’t a big deal. Lines of code aren’t a big deal. That’s not where your bugs are coming from and you aren’t bottlenecked on your typing speed. It’s not a real problem, but rather a dogmatic pursuit of terseness for its own sake. Rust is an expression-oriented language—it needs something like ? because without it we would have gratuitous nested braces marching ever-rightward and that actually is laborious to keep track of (deeply nested match expressions). Go could drop some error handling boilerplate with an ? operator, but it wouldn’t benefit as much from it as Rust did.
Re:Go proposal: new package to provide generic slice functions by kubb on Thursday May 06, 2021 @05:01AM (#27060714)
Consider these three points:

* it has been actually demonstrated that shorter programs contain less bugs,

* code is read much more frequently than it's written, and to the point code is easier to read than code full of boilerplate and meaninglessness syntactic elements,

* menial tasks and distractions introduce mental fatigue that consumes your limited brain resources that you need to think about the structure of your code that is actually dealing with the problem at hand.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Thursday May 06, 2021 @01:49PM (#27066808)
I’m skeptical about the first bullet—is it the fewer characters or the reduced complexity which results in fewer bugs. If the latter, then it undermines your point; if the former the I’m very skeptical as it would suggest we should all be writing minified code.

With respect to the second bullet, I agree that code is read more frequently than it is written and that readability is paramount. I strongly disagree that minimizing the character count is the same as optimizing for readability. In particular, I find very syntactically terse languages like Haskell or Ocaml far harder to read—indeed ReasonML exists precisely because so many people find OCaml so difficult to read.

With respect to the third bullet, you should think about your error control flow. The structure of your code doesn’t change whether you’re using Go’s “if err != nil” or Rust’s ? operator. The difference is a dozen characters. I can’t believe that the real cognitive load is in the actual pressing of keys, but if that is your experience then text editors often have a “snippets” feature or extension that will let you map that boilerplate to a hot key.

Re:Go proposal: new package to provide generic slice functions by stouset on Thursday May 06, 2021 @01:31PM (#27066558)
Thanks for this, it's exactly what I had intended to reply with. Every single one of these points is spot-on.
Re:Go proposal: new package to provide generic slice functions by closeparen on Wednesday May 05, 2021 @07:54PM (#27057433)
Lines of code are a very big deal in an organizational context that cares about test coverage. Since all the error handling ceremony is written by hand, so too must a corresponding test case for each instance of the error-handling ceremony be written by hand. Typing out test suites for functions that compose several other error-returning functions is bureaucratic drudgery.
Re:Go proposal: new package to provide generic slice functions by lawl on Thursday May 06, 2021 @01:01AM (#27059322)
I'll bite. Why not ditch the "% test coverage" metric then, since as you just elaborated, it's not a good metric.

I would prefer my language wasn't designed around corporate bureaucracy personally.

Re:Go proposal: new package to provide generic slice functions by closeparen on Thursday May 06, 2021 @02:06AM (#27059701)
I don't think the coverage metric is necessarily wrong to highlight error return branches: they are program logic you typed, and might have mistyped. I certainly have mistyped them. Checked the wrong error value, or returned a different error from the one I checked. You get to skip tests for default exception handling behavior in e.g. Java because you know the language is going to do; there's no opportunity for human error.

It is possible to have company policies against abstraction and cleverness when working in more expressive languages, and this would achieve almost the same intent as Go, it's just that actually using Go is more convenient. The language is corporate bureaucracy. The whole point is what's not there. What can't go off in a weird directions on a per-project basis. What junior engineers in a high-turnover environment can't screw up. It's not by accident that the native toolchain will give you a test coverage report with untested error return branches in red. Google is just happy to pay people for that drudgery, I guess.

Re:Go proposal: new package to provide generic slice functions by lawl on Thursday May 06, 2021 @02:13AM (#27059752)
> You get to skip tests for default exception handling behavior in e.g. Java because you know the language is going to do; there's no opportunity for human error.

I fundamentally disagree with that. the only thing you know in java is that it throws an exception that's maybe caught somewhere. That's an untested branch aswell.

Re:Go proposal: new package to provide generic slice functions by closeparen on Thursday May 06, 2021 @02:35AM (#27059858)
You don't have to write a test for "if this underlying call throws an exception, that same exception is propagated up to me," which is about 80% of the test cases I write for Go.

You do have to test cases where exceptions are supposed to be caught and handled/eaten, which I agree is meaningful and relevant in all languages.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Thursday May 06, 2021 @01:54PM (#27066884)
You “don’t have to write the test case” in the case of exceptions, but then you’re not getting the same coverage as with go. Just because a branch isn’t represented syntactically doesn’t mean it doesn’t exist. Note also that Rust’s ? operator isn’t going to be saving you from anything here since it just uses fewer characters to express the same branching logic, while languages with exceptions use none.

In general your org’s policies for what to test seems like a recipe for a low-value, high-effort test suite. Reminds me of the unit tests for getters and setters in Java.

Re:Go proposal: new package to provide generic slice functions by closeparen on Thursday May 06, 2021 @02:15PM (#27067170)
You get to take the language for granted; you don't get to take your own code for granted. "String reverse" is an easy function to write and the same instructions end up in my binary either way. But if you write your own, you'd better test it. If you import one from the standard library, no need, the stdlib has already done that. Functionality being in the language does not just save you typing; it also saves you testing. That's my point.

I agree, given that Go is what it is, it's a bad policy.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Thursday May 06, 2021 @03:00PM (#27067698)
You aren’t testing whether exceptions propagate correctly, you test that you catch or don’t catch them appropriately just like you test whether or not you return your error appropriately. That said, doing this for every function you write is probably not going to lead to a high value test suite.
Re:Go proposal: new package to provide generic slice functions by closeparen on Thursday May 06, 2021 @03:48PM (#27068259)
“Make sure it doesn’t catch the exception” is like “make sure it doesn’t do a tap dance” - there are quite a few things a function could do, we don’t generally ask unit testing to prove negatives.
Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Friday May 07, 2021 @01:33PM (#27078521)
If you’re going to check that a function propagates an error in Go it equally makes sense to check that you check to make sure the equivalent Python/etc function propagates the exception. Of course I don’t think testing either of these is a good investment.
Re:Go proposal: new package to provide generic slice functions by eweise on Wednesday May 05, 2021 @05:59PM (#27056376)
I used to hardly think about exception handling on the jvm, mostly let them bubble up and be centrally handled except in special cases. Now I'm always worried that I'll forgot to manually handle the error in Go. Can't tell you how many times I've gotten panics as well, from nil objects.
Re:Go proposal: new package to provide generic slice functions by jolux on Thursday May 06, 2021 @12:16PM (#27065470)
I don’t think masochism is inherently negative and I did not mean to insult. For that I apologize. I was trying to characterize in a humorous fashion a difference between what I perceive to be the stated aims of the language and the experience of actually writing it.

It was also an oblique reference to this talk which is one of my favorites: https://youtu.be/mZyvIHYn2zk

Re:Go proposal: new package to provide generic slice functions by Serow225 on Wednesday May 05, 2021 @12:43PM (#27052252)
Thank you for naming this. I've always struggled with how to convey this to people.
Re:Go proposal: new package to provide generic slice functions by skywhopper on Wednesday May 05, 2021 @02:09PM (#27053494)
The Go compiler is much much faster than C++ and Rust. I don’t think that’s seriously disputed by anyone, is it?

There’s no universally correct answer to the right balance of “smart compiler” vs “simple language”. Having worked with Go on a daily basis for five years now, I really like the simplicity of the language. Compared to the cognitive load imposed by the language when using C++ and Rust, I much prefer the naive straightforwardness of Go. There’s no devilry about it.

Re:Go proposal: new package to provide generic slice functions by kubb on Wednesday May 05, 2021 @04:35PM (#27055402)
Go vs C++ is not a fair comparison, because C++ is a badly designed language from the 1980s. It also serves a different domain. Certain applications of C++ are not serviceable by Go.

Go vs Rust is not a fair comparison, because Rust's type system is much more powerful that Go's and enables applications that Go's doesn't (like embedded systems programming). Also some of the things I said about C++ apply here.

There are also features of Go absent from C++ and Rust (reflection, garbage collection). So it's really puzzling that you'd pick those two.

To have a fair comparison, you'd need to look at something like Kotlin sans the class system. There Kotlin is a clear winner, and with the same engineering resources put behind it, a cut-down version of Kotlin would easily be able to achieve build times in the ballpark of generic-enabled Go.

Despite its claimed simplicity, Go has inconsistent design and bug-prone unwieldy features (try to write code that merges streams of data from two channels without blocking unnecessarily). It also has unnecessary constructs that contradict its claim to include only what's necessary (interfaces are just structs of function pointers, type methods are just functions with a glorified first argument).

It may be enough to write one-off command line applications, but it doesn't give developers the tools to create complex distributed systems in a systematic, clean way, which was supposed to be its main area of application.

Re:Go proposal: new package to provide generic slice functions by geodel on Wednesday May 05, 2021 @06:10PM (#27056461)
> and with the same engineering resources put behind it, a cut-down version of Kotlin would easily be able to achieve build times in the ballpark of generic-enabled Go.

So basically no real example. It is only what would be possible if things were to happen certain way.

> It may be enough to write one-off command line applications, but it doesn't give developers the tools to create complex distributed systems in a systematic, clean way

This is just arrogant opinion. Distributed tools and applications like NATS, Kubernetes, Docker, CockroachDB and so many other exist and written in Go. Developers who can't write distributed systems themselves can ofcourse buy or license tools from vendors. And at that point, honestly, it could have been written in any language.

Re:Go proposal: new package to provide generic slice functions by erik_seaberg on Wednesday May 05, 2021 @06:43PM (#27056760)
If your team has to write and review boilerplate by hand, that’s millions of times slower than a computer generating it. The compiler only looks faster when we exclude all that wasted effort.
Re:Go proposal: new package to provide generic slice functions by dmitriid on Wednesday May 05, 2021 @10:46AM (#27050510)
`.map().filter().find(x)` is significantly more simple and readable than for-looping for every small thing in Go.
Re:Go proposal: new package to provide generic slice functions by patates on Wednesday May 05, 2021 @10:54AM (#27050635)
I really like chaining array methods but you should also never forget it's incredibly easy to introduce crazy computational complexity with them.
Re:Go proposal: new package to provide generic slice functions by coder543 on Wednesday May 05, 2021 @11:01AM (#27050746)
Rust has lazy iterators, so a chain of iterator steps like this has the same complexity as a single for loop over the iterator. There's no reason Go couldn't do that same thing.
Re:Go proposal: new package to provide generic slice functions by stouset on Wednesday May 05, 2021 @04:33PM (#27055380)
In fact, Rust's version compiles down to pretty much the optimal looping form. It will even vectorize your iterations using SIMD.
Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @06:38PM (#27056719)
Rust is seriously cool in this regard, but Go aspires to be different, namely more C-like and less C++-like. This means a dumber, faster compiler that is easier to intuit about, for better or worse. Rust is such an amazing piece of engineering (moreso an amazing process and culture for producing an amazing language), but I think Go’s approach is right for a whole lot of software—lots of things don’t need to be insanely performant (lots of things are chugging along in Python, which runs 2-3 orders of magnitude slower than Go) but we do need to be able to iterate on them quickly in a development context involving dozens or hundreds of other people.
Re:Go proposal: new package to provide generic slice functions by jolux on Wednesday May 05, 2021 @11:13AM (#27050929)
Not if you have solid lazy iterator support in the language. If they’re strict and every link in the chain is adding O(n) to the complexity then yes, this is a problem.
Re:Go proposal: new package to provide generic slice functions by twobitshifter on Wednesday May 05, 2021 @12:29PM (#27052044)
In the case we’d need a little context of what the map, filter, and find operations are, but if map is multiple by 2 and filter is less than 200 you can just replace the filter and map with a single if in the for loop that performs the multiplications and check and return immediately when you find X. That’s pretty obvious, always takes only one run, doesn’t reallocate, and doesn’t add concepts, which is of course adding complexity.
Re:Go proposal: new package to provide generic slice functions by stouset on Wednesday May 05, 2021 @04:22PM (#27055192)
Yes and we could replace all of that with an implementation in assembly which both compiles and runs faster.

But we don't do that because for the entire history of computing, we've come to realize that abstractions enable us to reason about programs at a higher level without having to be bogged down in irrelevant details and that getting those details right once lets us avoid the inevitable bugs that occur while reimplementing them thousands of times.

By absolutely every objective measure we know in software engineering

   let triples = ints.map(|x| x * 3)
is strictly superior to

    var triples = []int
    for value := range ints {
        triples = append(triples, value * 8)
    }
The fact that this even has to be argued is just bonkers to me.

The second one is trivial to introduce bugs into, reading it requires mentally filtering out 90% of the code as irrelevant minutiae, and it's even worse from a performance perspective unless you remember each and every time to allocate a result array of the appropriate length to avoid reallocation. None of the details of allocating a result array or iterating over indices/values are important from the purpose of expressing the problem to be solved, and yet every time someone has to read this solution those things are of greater visibility than the actual business logic.

Worse, repetitive and unnecessary boilerplate like this hides bugs. Did you catch the fact that I'm multiplying by the wrong value in the golang version? Did you catch that I'm accidentally tripling the indices and not the values themselves? If you did, would you at least acknowledge that the first bug is much easier to identify in the first example than the second, and that the second bug is strictly impossible?

As an added bonus, the first one (in Rust at least) is automatically vectorized using SIMD for optimal performance. This happens even as you chain additional operations to arbitrary complexity.

If you still somehow think the second version is "better", then whatever your argument is can trivially be repurposed to say this version is better still:

    int* triples = malloc(sizeof(int) * array_len);
    for (int i = 0; i < array_len; i++) {
        triples[i] = array[i] * 3;
    }
If those details of creating a result array and explicitly enumerating are important, why isn't maintaining your own counter and directly indexing? At least the C version somewhat encourages you to allocate a result array of the correct size.
Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @10:53AM (#27050606)
I disagree. Fewer characters != simpler or even more readable. Map/filter/etc are certainly more clever, and I enjoy writing clever code, but I reserve it for my personal projects bprecisely because it isn’t so clear. Note that Python has these first class functions as well as various kinds of comprehensions and still it’s frowned upon to use anything more complex than the simplest comprehensions.
Re:Go proposal: new package to provide generic slice functions by jolux on Wednesday May 05, 2021 @11:11AM (#27050897)
Map and filter are extremely simple, far simpler than a for-loop. They can only do two things: transform items in a collection, and remove items from a collection. After mapping you know for sure that a collection will still have the same number of elements. After filtering you know that all the elements remaining still have the same type. For-loops can do anything. It’s a question of what you’re most familiar with and used to.
Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @11:35AM (#27051246)
I’m not comparing for loops in general with map or filter, but rather the specific for loop boilerplate to implement map and filter. Moreover, the complexity of map/filter isn’t internal, but rather decomposing or breaking down one’s problem into map/filter/etc expressions. Often for loops are clearer, especially since you can frequently collapse a map and filter into a single for loop without thinking in map/filter/etc primitives. This is especially true when you need to abort the chain early (e.g., due to errors)—Rust’s FromIterator provides a clever solution to this problem, but it’s much harder to wrap one’s head around than a simple for loop with an early return branch.
Re:Go proposal: new package to provide generic slice functions by jolux on Wednesday May 05, 2021 @12:11PM (#27051787)
I find that decomposing iteration into map and filter expressions typically clarifies my understanding of the problem and makes the resulting code more general too, and I just disagree that for-loops are clearer. Combining a map and filter into one loop body tends to create specific, imperative code that doesn’t need to be specific or imperative. For one, loops require mutation to have the same effect as filter and map, and as soon as you’re maintaining state, things get confusing. My usage of higher order functions instead of for-loops is an expression of my belief that programmers should always use the least powerful construct they can to solve a problem.

In general though I think the functions used in map and filter should be total. Most languages are not expressive enough to handle errors fluidly in long chains like that, you can do it with monads but apparently everyone hates those except me.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @12:34PM (#27052123)
> I find that decomposing iteration into map and filter expressions typically clarifies my understanding of the problem and makes the resulting code more general too, and I just disagree that for-loops are clearer.

Agree to disagree I guess.

> Combining a map and filter into one loop body tends to create specific, imperative code that doesn’t need to be specific or imperative. For one, loops require mutation to have the same effect as filter and map, and as soon as you’re maintaining state, things get confusing.

I agree that immutable, declarative code is easier to reason about in general than mutable, imperative code, but it's not a binary proposition. I posit the cost of managing the tiny bit of very-local mutable state for a for loop is a lower cost than trying to model a problem in terms of map and filter. While I can appreciate the elegance in "immutable always", I think it's too puritanical for real world software development, especially in these cases which are simply expressed as for loops.

Note that languages like Python have strong support for immutable expressions and `for` loops, and it seems very common (even idiomatic) to use imperative `for` loops for anything more complicated than the simplest list comprehensions.

> In general though I think the functions used in map and filter should be total. Most languages are not expressive enough to handle errors fluidly in long chains like that, you can do it with monads but apparently everyone hates those except me.

I think it's just that monads tend to allow for very abstract code at the expense of understandability, and the abstraction that monads facilitate is often well in excess of what a given problem requires. If you're writing code to maximize abstraction (which is a lot of fun), monads (and map/filter/etc) are great, but if you're trying to work with a team to build software to solve real problems, you probably care a lot more about readability than gratuitous abstraction and the monad (/map/filter/reduce/etc) juice frequently isn't worth the squeeze.

Re:Go proposal: new package to provide generic slice functions by jolux on Wednesday May 05, 2021 @12:40PM (#27052198)
Python’s FP capabilities are severely constrained by not supporting multi-line lambdas or composition operators (pipe, sequence, etc). It is not a good language for functional programming at all. The community norms explicitly push you away from using FP in it because of how limited it is. We use it for wrangling large data sets and tend to hate every minute of it.

My workplace uses Elixir exclusively in production for our backend services, so we’re all functional programmers and we do not find that map, filter, and reduce make things harder to read, quite the opposite. Breaking up loops does not introduce cognitive overhead, it makes every step in the chain more explicit. You can call this personal preference but there’s nothing concrete in your belief that for-loops are more readable or easier for teams of programmers to maintain, many people disagree.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @02:02PM (#27053390)
> Python’s FP capabilities are severely constrained by not supporting multi-line lambdas or composition operators (pipe, sequence, etc)

Hardly. You can absolutely have multi-line lambdas, just not multi-expression lambdas (the real limitation is that there are no try/except expressions so certain fallible manipulations aren't so easily expressed). Similarly, Python lets you overload operators so you could always override `|` or whatever. Of course, operators are just syntax sugar for function calls so this strikes me as a cop-out. In either case, neither of these excuses are pertinent to the community's rejection of complex comprehensions or higher order functions.

> My workplace uses Elixir exclusively in production for our backend services, so we’re all functional programmers and we do not find that map, filter, and reduce make things harder to read, quite the opposite. Breaking up loops does not introduce cognitive overhead, it makes every step in the chain more explicit. You can call this personal preference but there’s nothing concrete in your belief that for-loops are more readable or easier for teams of programmers to maintain, many people disagree.

You could argue that any two models which evaluate to the same thing are fundamentally equally easy to understand. You could argue that monads are just as easy to understand as a sequence of statements in an imperative language, but experience suggests that people have a harder time understanding the more abstract concept rather than the more concrete concept. This shows up all over--Newtonian physics are more easily understood than the more abstract quantum physics and in mathematics "more advanced" math tends to mean roughly "more abstract".

Re:Go proposal: new package to provide generic slice functions by jolux on Thursday May 06, 2021 @11:36AM (#27064843)
> In either case, neither of these excuses are pertinent to the community's rejection of complex comprehensions or higher order functions.

I can only assume you haven’t done a lot of functional programming because Python is just not expressive as a functional language. Lambdas are extremely cumbersome. JavaScript by contrast has a huge FP culture and does not even have comprehensions. But it does have syntactically lightweight, multi-expression lambdas.

> You could argue that monads are just as easy to understand as a sequence of statements in an imperative language, but experience suggests that people have a harder time understanding the more abstract concept rather than the more concrete concept.

Except I’m not arguing that, because I don’t believe that monads are easier to understand, I believe that functional programming with pure functions is. This is just another restatement of the same argument you’ve been making the whole time. We onboard people who have never used FP into being productive Elixir programmers in two weeks or less. There are no monads in Elixir, nothing more advanced than recursion and function composition. My experience differs from yours. Our new programmers have very little trouble grokking how FP works. They have much more trouble understanding the Erlang concurrency model and the various primitives available, but those are unique to Erlang and uniquely powerful.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Thursday May 06, 2021 @01:58PM (#27066937)
> I can only assume you haven’t done a lot of functional programming because Python is just not expressive as a functional language. Lambdas are extremely cumbersome. JavaScript by contrast has a huge FP culture and does not even have comprehensions. But it does have syntactically lightweight, multi-expression lambdas.

You assume wrong, but more importantly you missed the point of the snippet of mine to which you are replying—namely the expressiveness isn’t the reason the Python community rejected those features, but rather the complexity and cognitive burden.

> Except I’m not arguing that,

I wasn’t arguing that you were arguing that, I was using it as an analogous argument. We’re not going to get anywhere if you aren’t going to respond to what I’m actually saying.

Re:Go proposal: new package to provide generic slice functions by iudqnolq on Wednesday May 05, 2021 @01:55PM (#27053263)
I generally agree with you, but it's nice that in Rust you can use a for loop if it makes more sense. I mostly end up doing this when I want to reduce to multiple collections (put type a in here, type b in there) or call functions that return different types of errors.

The other time it's very useful is when translating algorithms specified in an imperative form. I translated a bunch of algorithms specified as for loops to elixir, and it was annoying to have an extra source of complexity when comparing the implementations for correctness.

Re:Go proposal: new package to provide generic slice functions by jolux on Thursday May 06, 2021 @11:44AM (#27064978)
It’s definitely nice to have the imperative constructs but spending a lot of time with pure languages has changed my perspective on mutability. I think Rust mostly fits it, data is immutable by default in Rust.
Re:Go proposal: new package to provide generic slice functions by arethuza on Wednesday May 05, 2021 @12:41PM (#27052230)
I really like the method style of LINQ in C# - which I would agree are much clearer than the equivalent explicit loops.
Re:Go proposal: new package to provide generic slice functions by joelfolksy on Wednesday May 05, 2021 @12:38PM (#27052176)
This argument doesn't really have any content, because people who advocate for programming with higher order functions would not agree that such code is more clever; in fact, they would probably argue the opposite. What's the point of debating if you assume the people on the other side already agree with you?
Re:Go proposal: new package to provide generic slice functions by creata on Wednesday May 05, 2021 @11:02AM (#27050756)
Alright, if it's not too much trouble, can you show me what the equivalent of the following code would be in Go? I think this is extremely clear as-is, but I'd love to see how you can apparently make it even clearer by avoiding iterator combinators.

https://play.rust-lang.org/?version=nightly&mode=release&edi...

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @12:13PM (#27051813)
Personally I think this is clearer, but it's quite contrived either way: https://play.golang.org/p/FpUWwm5yZ8n
Re:Go proposal: new package to provide generic slice functions by creata on Wednesday May 05, 2021 @12:39PM (#27052187)
Nice! Out of curiosity, if the iterators weren't of the same type (e.g. one was an iterator over the values of a hashmap and the other was over the items in a list) what would you have used instead of

    for _, m := range maps { ... }?
Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @02:07PM (#27053461)
Just as with Rust, you'd have to convert both maps to the same type before you could iterate them over together (or chain them, in Rust).
Re:Go proposal: new package to provide generic slice functions by coder543 on Wednesday May 05, 2021 @01:57PM (#27053300)
If you could provide the hypothetical Rust code you're referring to, that would probably make your question more clear here. I know both Rust and Go rather well, and I'm confused about which direction you're wanting to take the code.