Why replace if statements with Objects

  Рет қаралды 7,824

Raw Coding

Raw Coding

Күн бұрын

Examples of when replacing if statements with objects yields better software.
Support my Work 🤝 / raw_coding
Buy my Courses 📚 learning.raw-coding.dev
Buy my Merch 🛒 shop.raw-coding.dev
Join the Community 💬 / discord
Tweet Tweet 📣 / anton_t0shik
Tune in LIVE! 🎥 / raw_coding
#programming #csharp

Пікірлер: 26
@WookashWackomy
@WookashWackomy 5 ай бұрын
Thank you Moses. Please keep guiding me through the sea of programming.
@Fikusiklol
@Fikusiklol 5 ай бұрын
🤣
@carlosboyanosky8044
@carlosboyanosky8044 5 ай бұрын
hahahahahahha
@SnowtoadVRDev
@SnowtoadVRDev 4 ай бұрын
Mind blown. I had just never thought about it that way. Thanks.
@sunnypatel1045
@sunnypatel1045 4 ай бұрын
Love to see a video about injecting interfaces in DI with a bit of reflection or something smart with functional programming.
@pieDesert
@pieDesert 5 ай бұрын
This is good stuff
@isakoveugeneful
@isakoveugeneful 5 ай бұрын
Embedded interface. First time seeing this. Not sure what to think of it.
@RawCoding
@RawCoding 5 ай бұрын
Haha, yeah that was just a quick thing dont do that
@_grzehotnik
@_grzehotnik 5 ай бұрын
if you have an if with 2 options there's really no need to do that. Each class you create, each file you have to open increases cognitive load needed to read the code, and then instead of having one class with concise logic, you end up with 3 files that you have to open to understand the flow. Needless splittingof you code which doesn't give you much in return. Just stay with a simple if, don't overengineer.
@RawCoding
@RawCoding 5 ай бұрын
Mhmmm, so when you build an Api, you have 1 endpoint, call it for each parts of your application and then use if statements on the payload to determine which logic to execute further? (1 big file = no cognitive load?) No you split it up into manageable chunks. I explain that you want to split it up based on business functions admin/customer etc… as a symptom for a module doing too much is alot of if statements. Splitting it up is also safer because introducing a change wont break other parts of your application.
@_grzehotnik
@_grzehotnik 5 ай бұрын
@@RawCoding If you split up business logic within on flow, something that is logically cohesive, you introduce more congitive load than needed. >Mhmmm, so when you build an Api, you have 1 endpoint, call it for each parts of your application and then use if statements on the payload to determine which logic to execute further? Depends. If there's a totally different flow depending on the payload, i'd use differnt objects/functions to handle that or even use different endpoints. But the if would still be necessary, whether I'd check the payload, or make someone choose an endpoint or even use something like keyed services. If it's something like subset/superset, e.g. user who executes some action and we do additional stuff depending on whether they're an admin or not, I'd have a User.cs class with a flag and then handle that request with a specific user and check whether they have right or not. In an if.
@speakoutloud7293
@speakoutloud7293 5 ай бұрын
Great video, as it has become more likely like typescript.
@p4xx07
@p4xx07 5 ай бұрын
aaa white theme. I'm blind now
@giorgidgebuadze219
@giorgidgebuadze219 5 ай бұрын
Could you please make a video about autofac?
@AdamRichardz
@AdamRichardz Ай бұрын
Hot take, switch and ? are still if statements.
@fr0ntez
@fr0ntez 5 ай бұрын
Hi, it seems that discord link doesn't work anymore
@cocoscacao6102
@cocoscacao6102 5 ай бұрын
2nd example is kind of an overkill. I get the point, but in this case, passing a selector function as a parameter was enough.
@RawCoding
@RawCoding 5 ай бұрын
So you’re still replacing the if statement with an object, the downside of that is that you’re expecting the selector function to be the only thing that is different between the two.
@Sife-db
@Sife-db 5 ай бұрын
how to create problems out of thin air
@IronDoctorChris
@IronDoctorChris 5 ай бұрын
The first 2 examples are completely fair imo, I would almost never go for the 3rd one though
@RawCoding
@RawCoding 5 ай бұрын
Think of the 3rd example as a kin to Regex, where our expression was a tuple
@robertmrobo8954
@robertmrobo8954 5 ай бұрын
KISS
@stephenmooney1293
@stephenmooney1293 5 ай бұрын
@RawCoding this is just not necessary in most cases and in some cases it cannot be done. Even the founders of stack overflow have said they see no reason for it and prefer if statements
@tofu1687
@tofu1687 5 ай бұрын
I had to check if it was the first of april - but no
@aephyxen8437
@aephyxen8437 5 ай бұрын
😐
@bighat6501
@bighat6501 5 ай бұрын
My man DARK MODE please... at least a warning that viewer retinas are about to be scorched. 🫣
What you should know about Threads in .NET
14:52
Raw Coding
Рет қаралды 7 М.
C# Delegates & Lambdas Explained
32:43
Raw Coding
Рет қаралды 37 М.
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 36 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
Как бесплатно замутить iphone 15 pro max
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 8 МЛН
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 124 М.
Top 50 Most Asked JavaScript Logical Interview Questions || Must Watch🤯😱
1:09:02
How to escape Tutorial Hell, WITH PROOF!
27:29
Raw Coding
Рет қаралды 3,5 М.
Water powered timers hidden in public restrooms
13:12
Steve Mould
Рет қаралды 656 М.
Stop returning custom error responses from your API. Do this instead.
12:07
Amichai Mantinband
Рет қаралды 81 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 255 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 798 М.
Simple and Effective tool for .NET developers
7:26
Raw Coding
Рет қаралды 7 М.
Modern Python logging
21:32
mCoding
Рет қаралды 168 М.