Generally I tended to make jokes on Java and its long class, methods and variable names. The fact that there is a question on StackOverflow asking “When a Java method name is too long?” made it even more ridiculous for me.
However, after reading the Clean Code by Robert C. Martin my opinion on long names became more liberate. To the extent that now I promote using longer, descriptive names if their usage makes sense. They may come in handy while dubugging as well, which is the clue of this blog post.
Recently I’ve faced debugging a small piece of code that I found on SO:
It was meant to dismiss Bootstrap’s Popvers added with Angular UI’s directive on a click beyond their area.
It worked quite well, however it was possible to break things up in one particular case. My task was to figure out how to prevent it from happening which resulted in digging into the code and establishing a friendship with Dev Tools’ breakpoints and Step Over button for a couple of minutes.
Dealing with four conditions in a quite complex combination wasn’t fun to me at all. Each loop iteration I forgot what the
t.is(e.target) || t.has(e.target).length > 0 exactly is and had to decipher it one more time. The same went for other conditions as well.
But things got way better when I extracted the conditions into separate variables with quite long, descriptive names.
Then after putting a breakpoint in the line where the
if statement begins I was able to observe the human-friendly conditions’ descriptions with their values in the Local pane of the Dev Tools each time I pressed Continue.
Each time I proceeded to the next considered element, it saved me few seconds wasted on struggling with this unintuitive jQuery methods calls and prevented my brain from exploding.