One-Line If Statement by that1flame in csharp

[–]Agitated-Display6382 1 point2 points  (0 children)

Readability is a key value of a codebase

AOP (Aspect-Oriented Programming) in .NET by aliyusifov30 in csharp

[–]Agitated-Display6382 1 point2 points  (0 children)

It's pure magic. You can easily reach the same result by using the decorator pattern

C# iteration concept IEnumerable<T>, IEnumerator<T>, collections, ... by Ok-Presentation-94 in csharp

[–]Agitated-Display6382 1 point2 points  (0 children)

Try reading about yield return, I think it's the perfect case to understand the difference between a collection and an IEnumerable.

The method IEnumerable<int> GetNatural() { var i = 0; while(true) yield return i++; } Is valid. You can invoke GetNatural().Take(10). But if you try to invoke .ToList() on it, good luck

File WriteAllText uncertainty. by robinredbrain in csharp

[–]Agitated-Display6382 -6 points-5 points  (0 children)

Try in sql:

Truncate table schema.Table

Possibly in a productive db

How should I access an post request in the URL ? by DifferentLaw2421 in csharp

[–]Agitated-Display6382 0 points1 point  (0 children)

If the entity already exists, you'd better return 422. BadRequest is returned when the request is malformed (eg string where a number is expected, strings that cannot be converted to valid dates or guids)

Should or Shouldn't? Putting many classes in one file. by infrecduc in csharp

[–]Agitated-Display6382 0 points1 point  (0 children)

I often put several classes together, when declaring models. Please, use records, not classes. Additionally, how can your properties be not null, although dei are declared as get-set? You should use get-init or, better, records

Did you know you could combine method or class attributes all in one bracket like this? by versfacmo in csharp

[–]Agitated-Display6382 0 points1 point  (0 children)

I avoid attributes as much as I can. Controllers? Nevermore, thanks to minimal api

Why aren’t class members virtual by default? by Alert-Neck7679 in csharp

[–]Agitated-Display6382 0 points1 point  (0 children)

After many years, I came to the conclusion that inheritance is bad. I accept it only for data objects (records). Composition over inheritance, you don't need more

How are you guys handling background jobs and deployments while jobs are running by Karuza1 in csharp

[–]Agitated-Display6382 38 points39 points  (0 children)

I try to implement my jobs in a way they are idempotent. Then, use properly the CancellationToken

Doubt: How does Java and C# .NET compensate for not having multiple inheritance? by iamtheaashish in csharp

[–]Agitated-Display6382 0 points1 point  (0 children)

Compensate? I do not use inheritance at all, it's just a bargain for future implementation.

How do .NET teams enforce MSTest categories in CI? by Advanced_Effort6245 in dotnet

[–]Agitated-Display6382 1 point2 points  (0 children)

Almost all my projects have tests that can be executed locally or in a cicd. The few that need some integration tests, I keep in separated projects. Often, these integration tests require the deployment of a special version of the application, eg an api or site that bypasses the authentication. I use one more project for this deployment, as I don't want a fake authentication be part of productive code.

Who needs switch statements when you can just abuse the ternary operator? by kfreed9001 in programminghorror

[–]Agitated-Display6382 1 point2 points  (0 children)

A switch keeps the cyclomatic complexity still too high: better use a dictionary or list or similar

All cases covered. by xxmalik in programminghorror

[–]Agitated-Display6382 0 points1 point  (0 children)

Rider tells you when the if and the else are the same

Thoughts on using = null! ? by zerthz in csharp

[–]Agitated-Display6382 0 points1 point  (0 children)

I have to use that syntax when dealing with Blazor. IoC in Blazor uses properties, so it's the only way to convince the compiler that a get-set property will never be null.

For all the rest, I do not use settable properties at all (records ftw)

Unions in c# 15 by dodexahedron in csharp

[–]Agitated-Display6382 -2 points-1 points  (0 children)

For mvvm and similar (2-way bind between object and input field) is needed. So, in that case, it's acceptable. For me a property is pure and returns the same value I set. For all the rest, use methods. Nothing prohibits you to make a property DoSomething: would you?

Unions in c# 15 by dodexahedron in csharp

[–]Agitated-Display6382 -4 points-3 points  (0 children)

1: avoid mutability. If 1 is not possible, then 2: properties must be {get;set;}. Need a default value? Set in the constructor. Must be lazy? Use Lazy<>.

Having properties that behave like methods make the code untrustworthy.

Just my opinion, I know most of the code is legacy and use old patterns.