AspNetCore.Proxy icon indicating copy to clipboard operation
AspNetCore.Proxy copied to clipboard

Unreadable code

Open Neutrino-Sunset opened this issue 5 years ago • 2 comments

This is just painful to look at.

public IHttpProxyBuilder WithEndpoint(string endpoint) => this.WithEndpoint((context, args) => new ValueTask<string>(endpoint));

A method implemented as a lambda, multiple lambdas at that, one implementation delegating to something that reads almost like an overload (WithEndpoint -> WithEndpoints). All on a single line. This kind of thing is programmer trolling.

Neutrino-Sunset avatar Dec 08 '20 14:12 Neutrino-Sunset

The method isn't a lambda, it is a expression-bodied method. The body itself is a lambda. I am used to working with the => operator pervasively. I think I'd split this into two lines, but that's all I'd change. Just my opinion.

szalapski avatar Dec 08 '20 18:12 szalapski

public IHttpProxyBuilder WithEndpoint(string endpoint) => 
    this.WithEndpoint((context, args) => new ValueTask<string>(endpoint));

or, in C#9:

public IHttpProxyBuilder WithEndpoint(string endpoint) => 
    this.WithEndpoint((_, _) => new ValueTask<string>(endpoint));

szalapski avatar Dec 08 '20 18:12 szalapski