Clean Code Tip - avoid pyramids △ and ladders 📐

preview_player
Показать описание
people still write these 👨‍💻

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

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

I appreciate this. I started to do this on my own to avoid nested if-statements but I wasn't sure if it was a proper thing to do. Keep em coming 👌

krobbalt
Автор

I believe Shorts are awesome for quick tips and short span attention audience. 💪

mmitza
Автор

multiple returns in the function is considered to be the bad practice. what do you suggest?

MuhammadAdam-komy
Автор

Simply avoid passing boolean parameters along with other parameters in the method. Create two methods instead.

linuxtutorialshindi
Автор

I never nest if statements. I don't even use else (most of the time). If you find yourself in the situation where you need an else statement that can't be rearranged with an return/break/continue rethink the function. It's likely to big already.

redcrafterlppa
Автор

I feel like you should focus on the solution more in shorts. The quickest explanation is write for the early return by focusing on what causes an early return first, and lastly focusing on the main action. These are also called guard clauses. The explanation with inverting if statements and excluding all the negative possibilities is very ambiguous.

PaulSebastianM
Автор

The real question is how did he write ≤ in IDE. Is it Visual Studio?

Max_Jacoby
Автор

This is not a tip sometimes it is hard to think the opposite of if statement.

rohit
Автор

Guard clauses are good for some solutions and bad for others, you shouldn't have to use only one everytime

Also, if you need nested statements you probably can abstract it into a new function. That way you can avoid the complexity of guard clauses and still have clean code

cet_
Автор

Use a switch-case statement instead of multiple if-statements.

NoFailer
Автор

Accepting boolean as a parameter is a bad practice imo. You can create two function and not pass boolean. Execute one of them respect to booleans value

baranacikgoz
Автор

Shit hes actually right. Fuck the happy path

JorgeEscobarMX
Автор

bruh you didn't even remove the blocks in the if starements

electricengine
Автор

Why is everyone thinking that guardstatements will be new to anyone at this point. Every programming tips and tricks or guides contains it

benceszke
Автор

if (...)
....

{} are optional for 1 LoC

ari_archer
Автор

Your code won't be ugly if you don't code

coderwithoutpfp
Автор

Beginners

Do not follow this until you fully understand the nature if if-else blocks and guard statements which includes negation

In some cases, it is genuinely hard if not inefficient to think of the negation for an if condition when a proper if-else with nested if is more efficient and readable.

Readability is key, I typically hate to read Code that has the negation guard but returns -1 inside...like why?!, but I digress

Seriously

Readability, efficiency, 2 of the most important factors in terms of debugging and writing

Do NOT do this unless you absolutely know the concept

uuu
Автор

a switch statement looks nicer in m opinion

neo_uwuowo
Автор

Bad example. No one writes code like that.

CookiePepper
Автор

JetBrains IDEs be like Pls, noob, convert this bs to normal code

IvanRandomDude