Functions with clearly communicated intent

It pays to meditate on whether your functions can make any sort of promise as to their outcome. That is, in this case we are talking about a promise as a clearly communicate intent toward an end result, not the JavaScript Promise API, although what we are going to talk about here could very well figure into an application that makes use of Promises.

If you were to have a conversation with a function in your app, would it be like a conversation with somebody you felt you could depend on? Or would it be like talking to someone who seemed a bit iffy? Maybe some borderline multiple personality complex issues? Maybe some overall wishy-washiness, and inability to commit (promise) as to their intent?

I would say, if you are not able to take a look at that function and get a real sense of what it's end result would be, you may be in for some nasty debugging surprises.

At one end of that extreme of being able to promise a predictable outcome we may have a function that returns a boolean based on its internal operation. That's a pretty well quantifiable outcome right?

At the other end we may have a function or lots of functions that return undefined and here we may start the head-scratching and trying to sort out side effects etc.

Here we may see a preference for pure functions whenever and wherever possible.

Small outcomes that can be predictably promised which compose into the larger app is where it's at!

Oh yeah and Promises (with a capital "P") are cool, too!