5 ms·
The article is maybe overblown, but I think there's a good point there. A lot of functionality is one-off stuff that doesn't need to be re-used and won't be, an
by mkozlows 11y ago
The article is maybe overblown, but I think there's a good point there. A lot of functionality is one-off stuff that doesn't need to be re-used and won't be, and so trying to come up with a name for a little chunk of code just ends up making the program harder to understand.
So, sure, you can write:
function processData(err, data) {
//blah blah does stuff
}
db.getData(processData);
But it's actually a lot simpler and more understandable if you just write:
db.getData(function (err, data) {
//blah blah does stuff
});
If and when you ever need to break that function out into something re-usable, give it a name then, but don't bother with a name unless you need it.
- codygman 11y agoBut one of those functions processes data and the other gets data.
- Ma8ee 11y agoI hope that the very generic names you have chosen is just for the example, but otherwise that is exactly the type of names that make a codebase incomprehensible. How about something like function CalculateSalesBonus(err, salesmenEmployedByTheLastOfMonth) { // do stuff } which actually contains much more information than db.getSalesmenEmployedByTheLastOfMonth(function (err, data) { //blah blah does stuff });
- greenyoda 11y agoOnce you turn processData() into an anonymous function, how could you write a unit test for it?