Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thoughts on using the *Async suffix for any functions that return a promise? #396

Closed
TradeArcher2020 opened this issue May 7, 2015 · 4 comments
Labels

Comments

@TradeArcher2020
Copy link

One thing I like to do in my JavaScript code is to add the word "Async" to the end of function names that return a promise. This improves readability and lets people know at a glance that it returns a promise when intellisense is showing you the function name.

Example:

function getDataFromThesServer() {}

Would be:

function getDataFromThesServerAsync() {}
@wardbell
Copy link
Contributor

wardbell commented May 7, 2015

That is the standard at Microsoft for .NET libraries. But I think they need it and we don't in JavaScript.

They need it because they have a boat load of synchronous methods with async alternatives. The suffix helps them convey the similarity of intent without inventing a new method name root.

But it smacks of Hungarian notation which became passe when editors/IDEs began providing API help.

More to the point, we don't have the same potential for competing async and sync signatures. It happens of course, but not as often because all cross-process communications in JS world have to be async; there are no competing sync alternatives. Therefore, I think we can do without the extra writing and reading.

Moreover, it's pretty obvious looking at a method in use whether it is async or not.

You may well disagree. But I think the style guide should only recommend proven practices that are widely used and widely accepted ... which this one is not.

The style guide shouldn't prohibit it either which leaves you free to add it to your group's standards if you wish.

@kylecordes
Copy link

Here is a boring practical note. I have found that, with increasing depth of understanding, a greater percentage of all functions return promises. Adding the word Async to a significant fraction of all function in an application does not seem like a victory.

@johnpapa
Copy link
Owner

johnpapa commented May 8, 2015

interesting discussion. to be clear, i dont do this and am not changing ... but I don't think its bad to do it. why? its a convention and if you think it reads better to you, give it a shot. but I bet after you get more and more code with this you may see what @kylecordes mentioned ... a lot of the fn's have it and you really dont need it.

I wont do it and I agree that its more common to see functions use promises than not, and practically everything is async :)

@flyingxu
Copy link

flyingxu commented Jan 19, 2018

I'm also from .Net and I guess another reason of adding *Async to async functions is to let the caller know that it's an async function and don't forget to use await.

Any good practice (or IDE support ) that can remind the caller that an await might be missing?

I'm using VSCode and WebStorm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants