Nesting "If Statements" Is Bad. Do This Instead.

Nesting "If Statements" Is Bad. Do This Instead.

Flutter Mapp

1 год назад

3,437,985 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Leumas Boy TV
Leumas Boy TV - 15.09.2023 09:42

What language is this

Ответить
Abishek Tamilan
Abishek Tamilan - 13.09.2023 17:51

And now nesting if becamed ai

Ответить
Jo JoJo
Jo JoJo - 10.09.2023 07:56

Tell this to the guy that reset 2500 azure accounts of my company instead of subcontractors

Ответить
TikToker FAV
TikToker FAV - 09.09.2023 15:46

Much cleaner

Ответить
VikingGeorge
VikingGeorge - 08.09.2023 12:29

void anyFunction() {
const bool canOpenPanel = wifi && login && admin;
if (canOpenPanel) seeAdminPanel();
else debugPrint("Error");
}

Ответить
VikingGeorge
VikingGeorge - 08.09.2023 12:25

void myFunction() {
seeAdminPanel (wifi && login && admin);
}

void seeAdminPanel (int permission) {
permission ? debugPrint (INSUFFICIENT_PERMISSION_MESSAGE) : showPanel();
}

Ответить
breezeless gaming
breezeless gaming - 05.09.2023 17:02

Thanks bro Ithelped me a lot to make i simpler

Ответить
Shadrik Easton
Shadrik Easton - 05.09.2023 13:32

I know it makes the code more readable ... but using returns makes me twitch. Reminds me of gosubs.

Ответить
Jacob Sutter
Jacob Sutter - 04.09.2023 04:41

If i can read it and it works then its up to someone else to read it, idgaf

Ответить
ripstikgod
ripstikgod - 30.08.2023 02:18

Tell me you don't code without telling me you don't code.

Ответить
l̸I̸l̸ʷI̸l̸l̸I̸I̸I̸ ,..- (ˡⁱˡᴡ𝙸𝚕𝚕 𝙸𝙸𝙸)
l̸I̸l̸ʷI̸l̸l̸I̸I̸I̸ ,..- (ˡⁱˡᴡ𝙸𝚕𝚕 𝙸𝙸𝙸) - 29.08.2023 05:09

I prefer lambda *,**:mod(,)

Ответить
Eddie Villamor
Eddie Villamor - 28.08.2023 08:39

The amount of times people have missed the ! in the beginning of the predicate makes it worth not following this.
Writing clearer code is much better than inversing your predicates!! Better to encourage BUG AVOIDING tactics instead of just less indents... What's the point of a one liner if everyone keeps reading it wrong? How about using pure methods that only focus on one thing at a time.

Ответить
Nikola Grigorov
Nikola Grigorov - 27.08.2023 11:55

Can it work on a mobile phone ie. Android OS?
-'>If you are really knowledgeable, please help me to write a record in a text file from Html and js when there is no Wi-Fi?

Ответить
Pramod Kumar Saxena
Pramod Kumar Saxena - 27.08.2023 07:07

The "OR" operator has left the chat

Ответить
William Bennett
William Bennett - 25.08.2023 20:10

Naked returns are horrible and makes logic/flow hard to read.

Ответить
Youssef Ahmedw
Youssef Ahmedw - 22.08.2023 19:14

Is this python??

Ответить
Joey
Joey - 22.08.2023 18:50

What about switch statements ?

Ответить
Nick Tibbits
Nick Tibbits - 17.08.2023 08:21

Or why not get rid of the statements altogether and go branchless and just use arithmetic.

Ответить
Radek R
Radek R - 16.08.2023 23:41

It was understandable at first. Then i got no idea what happened

Ответить
Valentin
Valentin - 16.08.2023 23:27

Switch case and voila, easier to read, understand and everything. But it’s similar to the later option he used with return, yeah. case a, b, c for debugs and default for accessing admin panel

Ответить
Neal Marlin
Neal Marlin - 12.08.2023 17:43

We commonly call it protective programing. The language like Swift even makes it as language feature.

Ответить
Shyam Mahanta
Shyam Mahanta - 12.08.2023 17:33

if (!wifi || !login) can be adjusted together

Ответить
Shobia V
Shobia V - 11.08.2023 18:41

Yes, i have been using this guard clauses technique a lot in my code. It makes the code look less confusing and more readable.

But after watching this video only i know the name is guard clauses techique.

Ответить
واحد من الناس
واحد من الناس - 09.08.2023 23:38

Still you need the old way in some cases when you still required to execute some code even if the statement is false

Ответить
Scott H Jackson
Scott H Jackson - 01.08.2023 02:10

"all code is garbage"

Ответить
Jaroslav Ševčík
Jaroslav Ševčík - 23.07.2023 23:38

Using ! in cpp can be hard to read and thus dangerous. Instead, check if All conditions are met and do your stuff, otherwise printDebug...

Ответить
ALL CAPS
ALL CAPS - 20.07.2023 19:28

var hasAccess = false
if(wifi && login && admin){
hasAccess = true
}
if(!hasAccess){
wifi ? return : debugPrint('no wifi')
login ? return : debugPrint('not logged in')
admin ? return : debugPrint('not admin')
}else{
seeAdminPanel();
}

looks like there's lots of lines of code, still, but this gives you the ultimate control because many things can affect the "hasAccess" variable... including variables that aren't show here... what if the cookie is expired? what if the session is broken some how.. this way if something sets "hasAccess" to false, assuming this code fires every time in the middleware somewhere... we'll be ok and can go to sleep comfortable knowing that we have a pretty guarded middleware.

Ответить
Akarshan Mishra
Akarshan Mishra - 19.07.2023 15:20

Just use and nigga

Ответить
Tony Bengué
Tony Bengué - 19.07.2023 13:15

You can also return the debungPrint() function ✅

Ответить
Minokawa
Minokawa - 18.07.2023 06:02

Nesting if statements is bad because why the heck are you putting the

if(){
}

instead of
if()
{
}

Ответить
Juliandyce
Juliandyce - 14.07.2023 20:37

einfach &&

Ответить
Space Fish Aviation
Space Fish Aviation - 14.07.2023 19:12

why not
if(wifi && login && admin)
else if(wifi && login)

Ответить
Ddktst
Ddktst - 14.07.2023 00:07

Bs. Early returns are no better then goto. Noob coder

Ответить
Owen Easter
Owen Easter - 12.07.2023 03:44

could have just used an "and" statement in this example.

would be much more readable.

Ответить
Gandam Raviteja
Gandam Raviteja - 09.07.2023 08:38

Very good explanation buddy very informative thank you for making life easy

Ответить
Enoq
Enoq - 08.07.2023 02:37

For some things you could use await too

Ответить
Henry Lopez Mego
Henry Lopez Mego - 07.07.2023 06:32

Return unless wifi

Ответить
kaan
kaan - 06.07.2023 19:32

I'm not an expert , but the entire construct looks terrible.

Ответить
Ratan Baba
Ratan Baba - 05.07.2023 09:46

this method is useless if you dont want to return immediately after IF condition.
Developers, please use nesting based on situation. Dont blindly follow this guy!

Ответить
Philadelfia Timothy
Philadelfia Timothy - 26.06.2023 02:59

look the same for me. either LGTM.

Ответить
Rawaf AlBahrini
Rawaf AlBahrini - 25.06.2023 12:25

It's that python or Javascript ...

Ответить
Aliyah Sulaiman
Aliyah Sulaiman - 22.06.2023 23:01

Hi do you know this guy, "@HeisenbergFam".

Ответить
Ez
Ez - 22.06.2023 17:26

save

Ответить
Mike Wright
Mike Wright - 18.06.2023 14:44

There are plenty who favor a single exit point in every function, too - and they can make strong arguments in favor of that approach. Do what makes sense in your particular circumstance ... but if three nested conditionals really confuse you, you need to turn your job over to ChatGPT.

Ответить
JracoMeter
JracoMeter - 17.06.2023 00:18

Why not use "and"?

Ответить
Aqwaa
Aqwaa - 16.06.2023 03:47

if(wifi && login && admin) seeAdminPanel();
else if (!wifi) debugPrint("no wifi");
else if (!login) debugPrint("not logged in");
else if (!admin) debugPrint("you’re not an admin");

Same code in only 4 lines.

Ответить
Mr parrot
Mr parrot - 15.06.2023 10:29

Me who use switch ( ) 🗿

Ответить
codigoperfeito
codigoperfeito - 15.06.2023 00:26

Uaaau 😮

Ответить
Mohammad Islam
Mohammad Islam - 14.06.2023 22:54

wow looking at the comment section, this is actually inadvisable to new coders

Ответить
WS
WS - 14.06.2023 13:28

The default example was way more readable and easier to understand. :)

Ответить