Hey Guys, i have some simple golang code which i run trough claude, it claims i have "a classic goroutine closure bug as all_params is passed to goroutine by reference", but instance of this variable should be created in each loop iteration as it's defined in the loop's body, not outside. So it doesn't matter (as i understand) if that's a reference or not.
Loop Variable Capture bug was fixed in go 1.22 and it's 2 years old already, and I don't need that code to compile in some ancient golang versions. By just capturing variables everywhere instead of passing, everything's more readable. Is that considered correct / safe approach or considered bad practice?
Apart from the main topic i have impression that this AI is just hallucinating and telling me what I want to hear. Eg. when i put some code in there looking for bugs it often finds (probably non-existing) bugs. Then I claim these bugs are not there and this code should be working as expected, and it (again) completely agrees with me telling me that there is no issue :D
You have some good (better) model for that ?
--------------------------------------------
const MAX_PARALLEL_CALLS = 10
ret := make([]string, MAX_PARALLEL_CALLS)
if data.GetParamExists("mdata-0") { // check if we're doing multi-call
wg := sync.WaitGroup{}
for i := 0; i < MAX_PARALLEL_CALLS; i++ {
pname := fmt.Sprintf("mdata-%d", i)
if !data.GetParamExists(pname) {
break
}
all_params := get_all_params(data.GetParamBUnsafe(pname, []byte{}))
wg.Add(1)
go func() {
ret[i] = this.runOpenRTB(all_params, is_debug)
wg.Done()
}()
}
wg.Wait()