Anonymous functions

10 views
Skip to first unread message

Phillip Senn

unread,
Jun 24, 2014, 2:04:28 PM6/24/14
to js-drip-d...@googlegroups.com
I think that naming your functions is a way to have your programs document themselves.
So often naming is the hardest part, but by coming up with a concise name for a function, you are forcing yourself to think "What am I trying to accomplish here".

Instead of
setTimeout(function() {}),1000)

It's more self-documenting if the program is written as:
setTimeout(myFunction,1000)

function myFunction() {}

In addition, I think it's a little more clear, particularly with callbacks that the function is going to be called at a later time, even though you are defining it right here, right now.

Dave Aronson

unread,
Jun 24, 2014, 2:14:37 PM6/24/14
to js-drip-d...@googlegroups.com
On Tue, Jun 24, 2014 at 2:04 PM, Phillip Senn <phill...@gmail.com> wrote:

> I think that naming your functions is a way to have your programs document
> themselves.

Amen! It very much helps avoid Callback Hell -- maybe not in the
execution, but at least in trying to grok what is calling what to do
what when.

> So often naming is the hardest part,

Yup. As the old saying goes, there are only two hard things in
computer science: cache invalidation, naming things, and off-by-one
errors. ;-)

-Dave

--
Dave Aronson, freelance software developer (details @ www.Codosaur.us);
see also www.PullRequestRoulette.com, Blog.Codosaur.us, www.Dare2XL.com
Reply all
Reply to author
Forward
0 new messages