Best way to name async method
Where is an API of, let’s say, one method: “DoSomething()”. There should be two versions of the method: asynchronous and synchronous. We should encourage API users to use async one so sync one probably should get more complicated and explicit name. So the problem is: how should we name this pair. To the date we’ve came up with:
- DoSomethingAndWaitForResult() / DoSomething()
- DoSomething() / DoSomethingAsync()
- DoSomethingSync() / DoSomething()
- DoSomething() / RequestSomething()
None of above schemes seems like o开发者_开发知识库ptimal for us. Any suggestion folks?
Update. BTW do not hesitate to post one of the above as an answer if it fit you.
If you want to encourage your user to use async ones over sync, then I'd go for this one : DoSomethingSync() / DoSomething()
However, tell your users loud and clear that all methods are async if not told otherwise.
Example : node.js uses this notation : fschmodSync
and fschmod
But the most important is to stick with the one you chose.
How about naming them the same and having a different signature to differentiate them (one with a callback function, one without)?
Otherwise, Adobe uses the "Async" suffix for ActionScript, which seems good enough too: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html
In the .NET framework, async methods start with "Begin": BeginDoSomething / DoSomething.
精彩评论