Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

My first example did not have a closure. Simplified further: https://play.golang.org/p/ttdmropzSu

It's literally about nothing but how the 'value' variable in go for loops is handled by the language.

To make it worse, a common solution is to do this: https://play.golang.org/p/BTRs_TCQdu

That code looks like line 10 shouldn't be needed, does nothing, and during someone elses refactoring it might be deleted and result in the code blowing up again. No warnings, just silent data corruption.

The second one is a bit complicated, yes, but again I've seen them in the wild. Again they wouldn't have compiled in rust.



You're still being clever in that first example. `string` is a weird data type in Go, and `[]string` doubly so. You're going out of your way to find a confusing example, but that's not what the original poster was saying, which is that you can write a simple loop over and over again that doesn't have surprises.


Bah, the HN markup dropped my asterisks in those types.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: