4 ms·
Yes, you can miss anything in any piece of code in a review. No, this doesn't mean you should use someone else's code for trivial stuff a la leftpad. However, i
by tagrun 10y ago
Yes, you can miss anything in any piece of code in a review. No, this doesn't mean you should use someone else's code for trivial stuff a la leftpad. However, if you're saying that you don't have confidence that you can properly review an array reversal, then it's something personal and you're extrapolating, and maybe shouldn't do code reviews at all (as harsh as this may sound, it's not meant to be a shallow insult ---take a second an think about it in the context you've given: if you're going to miss that -1 or the fact that array indices start from 0 rather than 1 in Go, how can you expect anyone to trust you with reviewing their code that involves arrays?).
Using 3rd party code for "basic" stuff only makes sense to me when it's a tricky algorithm to get right (such as quicksort) and the author of the 3rd part code is a renowned/reputable top developer. I definitely don't trust the b+-tree implementation of some random dude on github(which what javascript people do mostly).
No idea who wrote that piece of code, but you can simply define it without the -i part, and write a[last-i] = a[last-i], a[i] in the loop (and better not call it "oop" ---whatever that means). That way, it's very readable and understandable to me:
for i, last := 0, len(a)-1; i < len(a)/2; i++ {
a[i], a[last-i] = a[last-i], a[i]
}
I still don't see anything in what you wrote that justifies adding a new built-in function for a trivial operation such as reverse, or generics to the language as a whole.
If profiling shows that bounds checking in reverse() is a bottleneck in your program (although it's very difficult for me to imagine that this will happen a real-world program), then you probably don't want to use that unsafe code went through "expert attention".
While being a mortal without any specific degree on array handling myself, in the unlikely event that I find reverse() to be a bottleneck in my program, I'd rather write an assembly function which makes use of SSE2/AVX2 to get real speed-up (note that LLVM can't autovectorize that Rust code for you, that code needs a rewrite it you want vectorization).