3 ms·
A lot of code editors (Xcode doesn't by default, but you can easily configure it to) have a keyboard shortcut for duplicating the current line. I have plenty of
by mistercow 13y ago
A lot of code editors (Xcode doesn't by default, but you can easily configure it to) have a keyboard shortcut for duplicating the current line. I have plenty of times accidentally made changes at the wrong place in a file because I was mistaken about where the cursor was.
The lesson is to always make sure to look at your diffs before you commit your changes.
- Cthulhu_ 13y agoAnd to have someone else look at your diffs and sign off on them before it's merged into master. Google / Chrome does this, and so should everyone else, even more so if they're dealing with security.
- mistercow 13y agoThat's a good measure too, although I think with a mistake like this, the person writing the code might be more likely to spot the mistake than someone else. It also makes me wonder if the diff display shouldn't have a specific notation for duplicated lines, since they are a special case that can easily be mistaken for a trivial change to a line with the way diffs are typically shown.
- bakhy 13y agoStrongly agree with the lesson. I got burned once, produced a security hole by merging a messy config file. The problem was quickly detected, but I have not checked in a single commit after that without first going through all the diffs. Plus, I sometimes notice possible improvements during such a review. It's very helpful.