News for hackers. Stuff that matters.
Re:Recombine to avoid naming when naming is hard by mkozlows on Monday July 06, 2015 @11:46AM (#9839933)
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.
Re:Recombine to avoid naming when naming is hard by Ma8ee on Monday July 06, 2015 @12:32PM (#9840265)
I 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
  });
Re:Recombine to avoid naming when naming is hard by greenyoda on Monday July 06, 2015 @03:01PM (#9841407)
Once you turn processData() into an anonymous function, how could you write a unit test for it?
Re:Recombine to avoid naming when naming is hard by codygman on Monday July 06, 2015 @12:16PM (#9840184)
But one of those functions processes data and the other gets data.