Naming convention for Promise.
See original GitHub issueI’m so confused. In general case, we name the function like ‘verb-what’ like getItem
, setQuantity
, request
, etc.
On case of GET functions, we can guess what type or what kind of values will return.
How about the function which return promise witch will return some other values? Or, a just Promise. How should I name that?
For example, there are a promise which will query the user’s name from database, should the promise name be getName
? or getNamePromise
?
In first case(getName), other co-worker could misguess that this function will return name synchronously, so he could directly assign the variables value, like this,
const name = getName();
console.log(name) // Promise {[[PromiseStatus]]: "pending"....}
it doesn’t seem good to add ‘Async’ suffix (getNameAsync
).
adding prefix ‘promise’ ( promiseGetName
) neither.
promiseGettingName
gettingName
…
hmm…
Any good idea for this?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:10
- Comments:7
Top GitHub Comments
I was searching for something like this: A naming convention to let my code readers know instantly that the variable is a promise. How about prepending when?
I thought of the word when because of the ff reasons:
Do the verbs, like ‘fetch’ or ‘load’, look like return promise? Because when I use Fetch API, it was ok for name of ‘fetch’ which return promise.
if were, using ‘loadName’ instead ‘getName’ could be a solution, I think.