author profile
Bjørn Jarle Kvande

Use abstractions instead of comments

Instead of commenting what a piece of code does, create a function with a name that describes what it does.


The code below the comment might change without the comment, and in time, the comment will become outdated, possibly wrong, and end up as a lie.


// enable dragging and dropping of images window.addEventListener('dragover', preventDefault); window.addEventListener('dragenter', preventDefault); window.addEventListener('drop', files => controller.readDroppedFiles(files));
Instead you should create a function with a good descriptive name. function enableDragAndDropOfImagesFiles(controller) { window.addEventListener('dragover', preventDefault); window.addEventListener('dragenter', preventDefault); window.addEventListener('drop', files => controller.readDroppedFiles(files)); }
Then call that function. The comment is no longer needed. enableDragAndDropOfImagesFiles(controller);
© Bjørn Jarle Kvande | Trailguide AS | ObjectPlanet AS
1998 - 2021
All rights reserved