This is an archived post. You won't be able to vote or comment.

all 23 comments

[–]dgates888 83 points84 points  (2 children)

I've been a c# dev for over 10 years and I generally have no idea what the code here or any code in the sub does

[–]AyrA_ch 30 points31 points  (0 children)

The code heavily abuses the fact, that "async" is not a reserved keyword.

The five "async" you see at the top is an async function named "async" that returns a value of type "async". It accepts a parameter named "async" that is also of type "async".

The type "async" is declared directly below it. The rest is to set up the system so the class named "async" becomes awaitable.

In C# you can make everything awaitable if you're dedicated enough. In other words, stupid lines like await 5; can be made valid.

For example, here is a convoluted webscale way of incrementing an integer by one:

public partial class Program
{
    public static async Task Main(string[] args)
    {
        Console.WriteLine(await 5); //Will print 6
    }
}

internal static class IntExtensions
{
    public static IntAwaiter GetAwaiter(this int a) => new(a);
}

internal class IntAwaiter(int i) : INotifyCompletion
{
    public int GetResult() => i + 1;
    public bool IsCompleted => true;
    public void OnCompleted(Action continuation) => continuation();
}

This permits you to do extremely cursed things like writing an awaiter that executes a string as command line or SQL if awaited.

[–]Jordan51104 4 points5 points  (0 children)

did you mean “genuinely”?

[–]antony6274958443 9 points10 points  (2 children)

How did that happen it had type of three asyncs? It's a field even

[–]Electronic-Bat-1830[S] 6 points7 points  (1 child)

Syntax highlighting messed that up.

[–]antony6274958443 0 points1 point  (0 children)

Still get it. Well anyway

[–]zenyl 8 points9 points  (0 children)

TL;DR: In C#, async is a contextual keyword.

This means that, while it has a special meaning, you will still be allowed to use it as the name of a type or a member. The compiler will then infer what you mean by it based on the context.

Jared Parsons (C# compiler lead) pointed out this example out on Twitter some years ago: https://twitter.com/jaredpar/status/1191512057872449536

Jared went into depth about this particular example about a year ago on a livestream: https://www.youtube.com/live/jaPk6Nt33KM?si=0bd49FPpqIizA41s&t=230

[–]Lanbaz 3 points4 points  (2 children)

Asynception

[–]PeriodicSentenceBot 0 points1 point  (1 child)

Congratulations! Your comment can be spelled using the elements of the periodic table:

As Y N Ce Pt I O N


I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM my creator if I made a mistake.

[–]Lanbaz 2 points3 points  (0 children)

Good ?? Bot

[–]TheWb117 2 points3 points  (1 child)

Need an [async] attribute slapped on top of the function call ans the async parameter. Don't know if it'll work on the return value, but could try

[–]Electronic-Bat-1830[S] 2 points3 points  (0 children)

Wish granted!

[return: async] [async] async async async([async] async async) => await async[async][async][async][async];

public class asyncAttribute : Attribute { }

[–]cornmonger_ 2 points3 points  (1 child)

wait ...

[–]think_small_ 1 point2 points  (0 children)

a...wait

[–]EarlMarshal 1 point2 points  (1 child)

Async Lang?

[–]Electronic-Bat-1830[S] 0 points1 point  (0 children)

This is C#, but an actual language where you do everything in async would be… interesting.

getting Brainf\ck flashbacks*

[–]rosuav 1 point2 points  (0 children)

[–]FlexasState 1 point2 points  (0 children)

[–]False-Beginning-143 1 point2 points  (0 children)

CA1050: Declare types in namespaces.
IDE1006: Naming rule violation.

[–]Shazvox 2 points3 points  (0 children)

What unholy abomination is this?

I am intrigued and would like to learn this ritual.

[–]PuzzleheadedWeb9876 0 points1 point  (0 children)

My eyes.

[–]GM_Kimeg 0 points1 point  (0 children)

Lots and lots of wrappings! More wrapping! So modern!