Комментарии:
What language is this
ОтветитьAnd now nesting if becamed ai
ОтветитьTell this to the guy that reset 2500 azure accounts of my company instead of subcontractors
ОтветитьMuch cleaner
Ответитьvoid anyFunction() {
const bool canOpenPanel = wifi && login && admin;
if (canOpenPanel) seeAdminPanel();
else debugPrint("Error");
}
void myFunction() {
seeAdminPanel (wifi && login && admin);
}
void seeAdminPanel (int permission) {
permission ? debugPrint (INSUFFICIENT_PERMISSION_MESSAGE) : showPanel();
}
Thanks bro Ithelped me a lot to make i simpler
ОтветитьI know it makes the code more readable ... but using returns makes me twitch. Reminds me of gosubs.
ОтветитьIf i can read it and it works then its up to someone else to read it, idgaf
ОтветитьTell me you don't code without telling me you don't code.
ОтветитьI prefer lambda *,**:mod(,)
Ответить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.
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?
The "OR" operator has left the chat
ОтветитьNaked returns are horrible and makes logic/flow hard to read.
ОтветитьIs this python??
ОтветитьWhat about switch statements ?
ОтветитьOr why not get rid of the statements altogether and go branchless and just use arithmetic.
ОтветитьIt was understandable at first. Then i got no idea what happened
Ответить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
ОтветитьWe commonly call it protective programing. The language like Swift even makes it as language feature.
Ответитьif (!wifi || !login) can be adjusted together
Ответить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.
Still you need the old way in some cases when you still required to execute some code even if the statement is false
Ответить"all code is garbage"
ОтветитьUsing ! in cpp can be hard to read and thus dangerous. Instead, check if All conditions are met and do your stuff, otherwise printDebug...
Ответить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.
Just use and nigga
ОтветитьYou can also return the debungPrint() function ✅
ОтветитьNesting if statements is bad because why the heck are you putting the
if(){
}
instead of
if()
{
}
einfach &&
Ответитьwhy not
if(wifi && login && admin)
else if(wifi && login)
Bs. Early returns are no better then goto. Noob coder
Ответитьcould have just used an "and" statement in this example.
would be much more readable.
Very good explanation buddy very informative thank you for making life easy
ОтветитьFor some things you could use await too
ОтветитьReturn unless wifi
ОтветитьI'm not an expert , but the entire construct looks terrible.
Ответить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!
look the same for me. either LGTM.
ОтветитьIt's that python or Javascript ...
ОтветитьHi do you know this guy, "@HeisenbergFam".
Ответитьsave
Ответить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.
ОтветитьWhy not use "and"?
Ответить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.
Me who use switch ( ) 🗿
ОтветитьUaaau 😮
Ответитьwow looking at the comment section, this is actually inadvisable to new coders
ОтветитьThe default example was way more readable and easier to understand. :)
Ответить