How do you guys feel about variable shadowing?
I'm playing with implementing pull streams in #racket after talking to @punkmonk. I'm using a combination of reading the docs and the source to figure out how something works.
The source mentioned above is very terse:
module.exports = function filter (test) {
//regexp
test = tester(test)
return function (read) {
return function next (end, cb) {
var sync, loop = true
while(loop) {
loop = false
sync = true
read(end, function (end, data) {
if(!end && !test(data))
return sync ? loop = true : next(end, cb)
cb(end, data)
})
sync = false
}
}
}
}
Notice the variable shadowing where function next
has an argument called end
while the inner nameless function inside read()
also has an argument called end
that effectively shadows the previous one with the same name. This means that there are two separate variables with the same name in this function. I find it a bit harder to read when this happens, and often need to stop to think what end
I'm thinking about when trying to understand what is going on.
I don't think this is a pro or against situation, I just wanted to see if other people here find these shadows a bit confusing as well.