2

Should one prefix Async in method names that is going to execute asynchronously. As in MS EF Core all methods that run async have async prefix. But they have sync methods as well without sync prefix.

what are suggestions where some methods are designed to run in parallel as well.

seeking suggestions.

Ammar Ali
  • 133
  • 3
  • 13
  • _[Async/Await - Best Practices in Asynchronous Programming](https://learn.microsoft.com/en-us/archive/msdn-magazine/2013/march/async-await-best-practices-in-asynchronous-programming)_ –  Nov 24 '19 at 04:34
  • _["You should add "Async" as the suffix of every async method name you write."](https://learn.microsoft.com/en-us/dotnet/csharp/async)_, _Asynchronous programming_, MSDN –  Nov 24 '19 at 05:05

1 Answers1

17

I assume you mean "suffix", not "prefix".

Microsoft uses the "Async" suffix because they are (often) adding asynchronous versions of methods that have already existed for a long time. So there is not much of a choice but to name them differently than the synchronous versions, so adding "Async" makes sense.

If you are creating new methods yourself, then this is what I do:

  • If you will have both asynchronous and synchronous versions of the methods, then name the asynchronous one with "Async".
  • If the only version of the method is asynchronous, then there really is no need to use the "Async" suffix, since the return type makes it clear that it's asynchronous.

In the end, it's up to you. It really makes no functional difference.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
  • 7
    _"...If the only version of the method is asynchronous, then there really is no need to use the "Async" suffix, since the return type..."_ - the 'Async suffix makes it obvious to readers that the method is async' _without_ having to look at the return type. Also, not naming it xxx'Async just because there are no synchronous alternatives will most likely just confuse readers of a new codebase as it is developed –  Nov 24 '19 at 04:46
  • @MickyD To each their own. In the end, like I said, it makes no functional difference. If you don't realize it's async and don't await it, you'll be warned. – Gabriel Luci Nov 24 '19 at 04:53
  • 5
    It is "up to you" but, these days, async-all-the-way-down might be the primary or only approach. Don't add a suffix for the sake of a suffix; add it because it distinguishes from the norm. – ChiefTwoPencils Nov 24 '19 at 06:48