This seems like a klunky way of getting a value from getbufvar().
let attach_to = {}
if len( getbufvar( bufnr, 'attach_to' ) ) > 0
let attach_to = getbufvar( bufnr, 'attach_to' )
endif
if len( attach_to ) > 0
If I simply use
let attach_to = {}
let attach_to = getbufvar( bufnr, 'attach_to' )
if len( attach_to ) > 0
.......
it will fail on variable type when the target for getbufvar(), i.e.
b:attach_to doesn't exist. Fortunately, len() is smart enough to
take different types, so there is a workaround.
I don't know if there's a good way around this without easing up on
the variable type-checking, and [re-]initialize variables to the
correct type upon assignment. This would make life soooooo much
easier with Vim 7 script.