Clean Code Tip - Consolidate Branching 🌿

preview_player
Показать описание
trust me, consolidating if's feels really good

👉 Try Rider
RD5K9-4TXXW-KMV3G-NYWSF-3ZSTP

#csharp #cleancode #programming
Рекомендации по теме
Комментарии
Автор

You should checkout the strategy pattern...

MrMarkRGray
Автор

Holy shit finally someone uses OOP for what it's strong at. Legitimate polymorphism to enhance performance by not repeating yourself.

You can do this on a smaller scale by setting a delegate once and using it. The overhead is the cost of a delegate.

AvenDonn
Автор

This does have a name, as far as I'm aware, "Replace conditional with polymorphism"

Of course, to be really viable, the construction of an instance should be abstracted away with either a Factory or similar service. Furthermore, it's very hard to justify for only 2 branches; this strategy really shines on 4 or more branches, with some of them having a "do nothing" case.

I did like how you explained the concept.

MatheusAugustoGames
Автор

Good video but i will appreciate it more if you reduce the pace of the video. I am not an AI being.

frankbanini
Автор

just a suggestion when explaining clean code please make sure naming of variables and functions is right

ZANO
Автор

*IContext
Interface names begins with an "I"

lolroflxd
Автор

Can you show specific example beside generalized version, it would be easier to understand. Thanks for the tip!

mgame
Автор

This is interesting, , I would be interested in a full course from you in writing clean code, I've been improving with some of your tips but I've got a long way to go, I often have very convoluted code where I have so many conditions to deal with edge cases it hurts my head. I also don't understand the code you ended up here if I'm honest... p.s. if anybody wants to share some good resources for writing clean code, I'd really appreciate it if you could share them with me! :)

BloodyEpicGmrZ
Автор

I'm thinking a more concrete example might clarify this point better. Based on what I'm seeing in this video you're just spreading logic over more area which can make code harder to maintain and reason about, especially for simple situations.

In this case I would STRONGLY prefer to just keep logic down to being 1 class with the 2 methods rather than 3 classes, 7 methods, and an interface; it just looks like you're in a much worse place than when you started and you don't gain anything for the extra bloat.

baka_baca
Автор

Solo less ifs... More functions & functions in functions. If you don't like creating new function names it's not really any difference. And ? : Is already there to use. More functional is great but only if you understand what you see. At my lvl I prefer clear natural human logic even in a bloated code than a compact confusing one. Clear sequential piping with well known functions helps but any space spread function nesting gives me a massive headache.

ebrelus
Автор

Not convinced this is just syntactic sugar coating

xamael