Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here's me doing the HN thing and analyzing the code sample rather than the article itself. Sorry in advance.

But if you're going to do this trick and you use a code compiler of any sort, you'll need to assign the value of that clientLeft somewhere. Otherwise your compiler will notice it not doing anything and helpfully optimize it away. So your users in production will see your layout bug and you'll never be able to reproduce it in development.

JavaScript is awesome.

As to the article itself, I'd prefer to see a comment on a line as wacky as this one. It's one well-intentioned lop away from vanishing from that git blame entirely, and then six hours of debugging and research away from finding its way back into place.

Trying to sift through file history to understand what's going on is hard enough on code I wrote myself only a year ago. I wouldn't want to rely on it as the only way of digging into a large shared code base. Yikes.



> But if you're going to do this trick and you use a code compiler of any sort, you'll need to assign the value of that clientLeft somewhere. Otherwise your compiler will notice it not doing anything and helpfully optimize it away. So your users in production will see your layout bug and you'll never be able to reproduce it in development.

This optimization is only possible if the compiler is able to deduce this as a useless function call. In order to do that, the compiler has to deduce (i) that the result is not used, and (ii) that the function has no side effects. (ii) can be very, very hard to deduce.


I don't disagree. But I post this because it actually happened to me. Googles closure compiler to be specific. The only way to make it happy was to actually assign the value to the window scope, where it couldn't know whether the value was ever used.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: