If you're going to make non-trivial changes to someone else's code you really shouldn't edit their answer. If they just left off a parenthesis or semicolon then feel free to edit it in, but if you're going to re-structure it, change the coding style, or "improve" it in any way that you feel is meaningful, (and the post isn't already community wiki) then an edit would be in appropriate. If you just want to point out that something won't work, or that it could be improved, then a comment would be fine. If the changes are significant enough that it couldn't reasonably fit into a comment, then chances are it's significant enough that you should be posting another answer. Make sure that if you're posting an answer that's based on someone else's code you link to that answer and attribute the original author as appropriate.