twitchax / AspNetCore.Proxy

ASP.NET Core Proxies made easy.
MIT License
505 stars 80 forks source link

Unreadable code #73

Open Neutrino-Sunset opened 3 years ago

Neutrino-Sunset commented 3 years ago

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.

szalapski commented 3 years ago

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 commented 3 years ago
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));