Re: [go-nuts] Re: Range over int

2024-02-23 Thread Amnon
So in 2012 Cyril Oblikov wrote Why isn't this code correct? var N int = ... for i := range N { doSmth(i) } In my opinion it looks much simpler than: var N int = ... for i := 0; i < N; i++ { doSmth(i) } So we should say to Cyril (whether he is today), that it is now correct. You just n

Re: [go-nuts] Re: Range over int

2024-02-23 Thread Duncan Harris
I made some changes to use range over int in our code base and was pleasantly surprised with the improvement in readability. We had quite a few instances where the number of iterations involved a function call which we don't want to repeat: - for i, n := 0, f(); i < n; i++ { + for i := range f(

Re: [go-nuts] Re: Range over int

2024-02-22 Thread Henry
This is one feature that provides little value beyond saving a few keystrokes and looking slightly nice, but with potential of increased complexity when we need to implement more important features to the language down the road. This is my opinion. It shouldn't have been added, but what was don

Re: [go-nuts] Re: Range over int

2024-02-17 Thread poweredbycitizen
I agree with you. Powered By Citizen  On Saturday, February 17, 2024, 1:19 AM, Kurtis Rader wrote: It's not just changing `k` inside the loop body that makes the transformation invalid -- your observation also applies to modifying `i` inside the loop body. Modifying either variable inside t

Re: [go-nuts] Re: Range over int

2024-02-16 Thread Kurtis Rader
It's not just changing `k` inside the loop body that makes the transformation invalid -- your observation also applies to modifying `i` inside the loop body. Modifying either variable inside the loop body is extremely rare in my experience and doing so warrants a "dragons be here" comment. Still, y

Re: [go-nuts] Re: Range over int

2024-02-16 Thread Patrick Smith
On Fri, Feb 16, 2024 at 10:27 PM Amnon wrote: > But now it is out, I think it is great, and have run > perl -pi -e 's/for (\w+) := 0; \1 < ([\w()]+); \1\+\+/for \1 := range > \2/' $(git grep -l for) over my entire codebase to use it everywhere. > You know your own codebase, and maybe this wa

Re: [go-nuts] Re: Range over int

2024-02-16 Thread Amnon
Indeed. The thread started 12 years ago. At the time I thought the idea of ranging over an int was just dumb, and un-go-like. But now it is out, I think it is great, and have run perl -pi -e 's/for (\w+) := 0; \1 < ([\w()]+); \1\+\+/for \1 := range \2/' $(git grep -l for) over my entire code

Re: [go-nuts] Re: Range over int

2024-02-15 Thread Jorge Massih
Hey folks! Now in in Go v1.22 (released 02-06-2024) it's possible to iterate over a range of integers by doing the approach mentioned at the beginning of this conversation. - JM El miércoles, 7 de enero de 2015 a la(s) 9:42:07 p.m. UTC-4, Sean Russell escrib