Is there a definitive naming convention for methods returning IAsyncEnumerable?

convert ienumerable to iasyncenumerable
iasyncenumerable linq
asyncenumerator c#

After C# 5 introduced the async and await model for asynchronous programming, the C# community arrived at a naming convention to add an "Async" suffix to methods returning an awaitable type, like this:

interface Foo
{
   Task BarAsync();
}

Many static code analyzers (both Roslyn-based and non-Roslyn-based) have since been written to depend on this naming convention when detecting code smell around asynchronous programming.

Now that C# 8 has introduced the concept of asynchronous enumerables, which themselves are not awaitable but can be used in conjunction with await foreach, there seems to be two options for naming methods returning IAsyncEnumerable:

interface Foo
{
    // No "Async" suffix, indicating that the return value is not awaitable.
    IAsyncEnumerable<T> Bar<T>();
}

or

interface Foo
{
    // With "Async" suffix, indicating that the overall logic is asynchronous.
    IAsyncEnumerable<T> BarAsync<T>();
}

Has there been a definitive naming convention guideline (from the C# language team, the .NET Foundation, or other authorities) regarding the options above, like how the C# 5 naming convention was unambiguously standardized and not left to opinion-based judgement of programmers?

Naming convention: Async as suffix to Interfaces? : csharp, Is there a definitive naming convention for methods returning IAsyncEnumerable ? After C# 5 introduced the async and await model for asynchronous� Typical use: Table instance method. initParm. Used for methods that set member variables. If the method only sets some of the variables, indicate this in a prefix to the name, for example initParmVersDate. is* A Boolean method that will check some condition. If the condition is not fulfilled, it must return false. is* cannot change the method.

It’s not an async method, so the name shouldn’t end in ‘Async’. That method suffix is a convention to make it obvious that the method should be awaited, or the result handled as a Task.

I think a normal collection-returning name is appropriate. GetFoos(), or similar.

Naming Conventions | Cloud APIs, It's needed because C# does not allow "return type overloading", i.e. you can have multiple overloads of the same method name, with different parameters, but � 11 Is there a definitive naming convention for methods returning IAsyncEnumerable? Dec 21 '19. 4 How to Disable UWP App Suspension? Nov 16 '17.

Async suffix and even keyword async is just boilerplate, it is meaningless other than some backward compatability arguments. C# has all information to distinct those functions just like it distincts yield in methods which return IEnumerable, as you know you don't need to add anything like enumerable or some other keyword on such methods.

You need to add Async suffix just because C# will complain about overloads, so essentially those two are identical and they do same thing by all rules of polymorphism (if we are not taking human factor of intentially corrupting behavior into account):

public interface IMyContract
{
    Task<int> Add(int a, int b);
    int Add(int a, int b);
}

But you can't write it like this because compilator will complain. But, hey! It will swallow this one monstrosity:

public interface IMyContract : IEnumerable<int>, IEnumerable<long>
{
}

and even this:

public interface IMyContractAsync
{
    Task<int> Add(int a, int b);
}

public interface IMyContract : IMyContractAsync
{
    int Add(int a, int b);
}

So this is it. You add Async just to stop compiler to complain. Not to clarify things. Not to make them better. If there is no complain - no reason to add it, so in your case I will avoid this, unless it becomes Task<IAsyncEnumerable>.

PS: Just for better of understanding of entire picture here - if sometime in future someone add in C# quantum-computer method extensions (fantazy, huh) which will operate in different paradigm, we probably will need another suffix like Quant or something, because C# will complain otherwise. It will be exact same method but it will do it's work another way. Just like polymorphism do. Just like interfaces do.

Concurrency in C# Cookbook: Asynchronous, Parallel, and , There is no definitive list of names to avoid, as every name must be evaluated in the The method names should follow the naming convention of If an API supports filtering of resources returned by the List method, the field� This section discusses the following aspects of method naming: General Rules. Here are a few general guidelines to keep in mind when naming methods: Start the name with a lowercase letter and capitalize the first letter of embedded words. Don’t use prefixes. See Typographic Conventions. There are two specific exceptions to these guidelines.

C# convention: Methods should be named according to their , 8.1 Async Wrappers for “Async” Methods with “Completed” Events 11.3 Async Construction: The Asynchronous Initialization Pattern In addition, an async method may return IAsyncEnumerable or IAsyncEnumerator if it returns multiple val‐ Here the convention is to name the TAP method OperationTaskAsync (e.g. ,� Java Naming conventions. Java naming convention is a rule to follow as you decide what to name your identifiers such as class, package, variable, constant, method, etc. But, it is not forced to follow. So, it is known as convention not rule. These conventions are suggested by several Java communities such as Sun Microsystems and Netscape.

Существует ли определенное соглашение об именах для , According to the Task-based Asynchronous Pattern (TAP), methods returning either do not return such Tasks should not have an "Async" suffix in their names. The convention method applies to any action named Find. A parameter named id is present on the Find action. Naming requirements. The [ApiConventionNameMatch] and [ApiConventionTypeMatch] attributes can be applied to the convention method that determines the actions to which they apply. For example:

Existe uma conven��o de nomenclatura definitiva para m�todos , interface Foo { // No "Async" suffix, indicating that the return value is not ReadAllAsync возвращает IAsyncEnumerable<T>; В EF Core 3 результаты� Ok, are there going to be examples to show how to do things like read from streams using IAsyncEnumerable? Questions that come to mind are things like should I use a StreamReader as per .Net Core 2.x and yield return, or should I derive from IAsyncEnumerable. Is there any public discussion around what will be added in future?

Comments
  • The option 2 sounds correct here, since your run this code asynchronously (mark method as async and use await inside), and msdn sample shows the same
  • In response to the closure of the question, I have edited the question to ask whether a definitive naming convention exists, and to give example of how a definitive naming convention in C#5 resulted in developments in static code analysis. Therefore having C#8 follow that pattern will result in measurable code quality improvements beyond opinion-based coding preferences.
  • .NET Core itself uses the Async suffix for methods that return IAsyncEnumerable, eg ChannelReader.ReadAllAsync. In other cases, eg in EF Core, AsAsyncEnumerable() is used which is already clear
  • Naming guidelines exist to make it easier for humans to understand the code. If the code's purpose isn't clear, add the suffix.
  • Thank you for pointing out the ChannelReader.ReadAllAsync example. Since this comes straight from the .NET team, it's hard to go wrong following suit.
  • Analyzer packages often come with a mix bag of style and non-style analyzers. For example, the Microsoft.VisualStudio.Threading.Analyzers package has a style analyzer that checks naming convention (VSTHRD200) and a non-style analyzer that detect hazardous situations that can potentially lead to deadlock (VSTHRD111). To reference the package to take advantage of VSTHRD111, a project would also end up with VSTHRD200.
  • All those are arguments for using the Async suffix. The suffix is used in .NET Core itself: ChannelReader.ReadAllAsync returns an IAsyncEnumerable. An IAsyncEnumerable has to be used with await foreach, so the suffix makes sense.
  • Sorry, but I feel I disagree, it's not really different approach of doing same thing - it;s more - it is expected to be called differently, and result to be collected differently. That is the most difference between async and non-async. I strongly believe adding the async is for clarity. I think this is also Microsoft's recommendation.
  • Yeah, I agree but disagree. Just like in List you have simple Sort function and not "QuickSort", "RadixSort", "BubbleSort", "MixOfSorts". They are different, used by scope but obviously doesn't need clarification other than for debugging purposes (I mean you only care for them when they make an impact on performance/resources). In this case DoThing and DoThingAsync is in same situation than any other templated algorithm, they don't need clarification, it is either supported or not, and usefull only for debugging.
  • Thats different, async means - heu caller make sure you handle this corrently. Fact of retirning Task is not enough to say that method is truly Async. Caller must know to await or use GetAwaiter().GetResilt() to get same oitput. That is different not how the things are done inside.
  • This is entirely purpose of code analyzers and compilator. IntellySense can easily point this out for you, no need to use developers brains for highlighting or even banishing using of sync method over async one in asynchronous code. From my experience when using Async I rarelly need to use GetResult(), but I frequently need to pollute entire code-base with Async.
  • As someone marked that - it is opinion. We can keep believe in what we believe and be happy :)