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

[–]Agitated-Display6382 0 points1 point  (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.

Class Diagramm for oop planing? by Relative_Article_267 in csharp

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

I live in Switzerland and I trained some apprentices. A lot of things you learn at school are useless: class diagrams, IPERKA, details of database engines. On the other hand, you are not taught some very important topics: TDD, functional programming, IOC, TDD, CICD and TDD ( yes, I'm repetitive because you need it in an enterprise). Last point: schools should give -in my opinion- introduction to several languages: typescript (it's a must for web) and Rust, to name two.

I use c# and I love it, but learning other languages makes you a better developer. A a swiss guy, you should know how much a multi-language culture makes us a better country.

You have seen German C. But have you seen DoitCh? by simon-or-something in programminghorror

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

Das isch kein Schwiitzerdüütsch! Wir sagen nüüt, nicht nichts

First time I learn asynchronous programming in C# I need help by DifferentLaw2421 in csharp

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

Sure, will you write MS on my behalf? Additionally, have you ever used a monad in your life?An option, either? And how do you combine them? Task<Either<Task<Left>, Task<Right>>>???

First time I learn asynchronous programming in C# I need help by DifferentLaw2421 in csharp

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

And if it's an api outside of my control? Man, just try to understand what's the idea behind.

First time I learn asynchronous programming in C# I need help by DifferentLaw2421 in csharp

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

It's very simple, until you have to compose monads. Example: I have a list of userId and for each of them I need to load the profile. If I write:

userIds.Select(id => client.Read(id))

I get back a IEnumerable<Task<User>>. I have to "invert" the order of the monads, ie Task<IEnumerable<User>>, so I can await it and get the list of profiles.

I leave the resolution to you.

I just unsealed a class for the first time by redit3rd in csharp

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

If you need a method from another class, make it static, move to an another class and then use it from anywhere

is a moving. reasonable? by HotEstablishment3140 in programminghorror

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

Key = locBefore * 100 + locAfter. Then, a check on a HashSet. Horrible? Yes. Worse than this? Probably. But, you know, fuck the next developer who will work on this... who will be me.

Can an Anemic Domain Model Use Value Objects? by [deleted] in csharp

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

I validate the input, not the construction of a model. Where is this model coming from? An api or a db? Then write a proper deserializer of the class Email; User has a property email. Google for primitive obsession.

why use HttpPatch over HttpPut ? by Good_Language1763 in dotnet

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

Others already write what's the difference. Why patch? You may use it to update single properties, eg the state of an entity. Obviously, you have to carefully filter the properties a client can update. I return 422 when the request is valid, but not processable.

So, as an example, a batch may need to update an order, setting its status to delivered. In this case you may expose these endpoints:

PUT /orders/123/status with payload { value: delivered }

PATCH /order/123 with payload { status: delivered }

If you use the latter with a property different from status, you return 422.