2 ms·
the author also complains that There is only one way to loop (for). that seemed odd to me. i thought is go really that limited? for loops used to be the bane of
by em-bee 2y ago
the author also complains that There is only one way to loop (for). that seemed odd to me. i thought is go really that limited? for loops used to be the bane of programming. that can't be true, and it isn't.
it just happens that things like while or foreach or however they are called in your favorite language are all done with the same for keyword. is that bad? i don't know.
as for map/reduce, in most languages that i am familiar with those are functions. and nothing prevents go to have these functions too. if they are not in the standard library, add them. there are multiple implementations available. eventually one will make it into the standard library.
- p2detar 2y agowhile-loops are also seldom used in Java code. At least from my observations. For-each and stream functions have deprecated for/while in modern Java code. As a Java dev, I love Go by the way. Recently adopted it and I find it anything but boring.
- em-bee 2y agoagreed, i use while very rarely in any language. iterating lists is really the main use of looping, so some form of for-each is my preferred tool. even when a traditional for loop is better, my first instinct is to try for-each first. it's a pity that javascript's forEach is so awkward to use, needing a callback. i remember when pike's foreach was extended from only handling arrays to also supporting mappings and anything else iterable, it felt like a massive improvement. go's for/range syntax is a bit different, but it does the job. i could not ask for anything more.