8 ms·
> writing "return condition" instead of "if condition then return true else return false end" > using the conditional-value ("ternary") operator in any capacit
by nousermane 3y ago
> writing "return condition" instead of "if condition then return true else return false end"
> using the conditional-value ("ternary") operator in any capacity
Looks like author of some code I had to comb through recently, maybe had that among guidelines. Said code was replete with:
if(function_that_returns_boolean()){
return true;
}else{
return false;
}
...and...
if(foo()){
return true;
}else{
if(bar()){
return true;
}else{
return false;
}
}
- ggambetta 3y agoThis to me screams "I don't understand boolean variables". Why stop there? switch (byte_value) { case 0: return 0; case 1: return 1; ... case 255: return 255; }
- hardware2win 3y agoVisualizing control flow from if ladder effort: minimal Doing the same for not tiny boolean expression: way more Just because you think it is cool cuz profs forced it on ya during college is not a argument
- ajuc 3y agoIt's personal taste. You can subdivide boolean expressions just as easily with if-then-elses as with boolean functions. What most people object to is leaving the last level of if-then-else and returning true or false, when you could have returned simpleBooleanExpression and do away with 1 level of nesting.
- pwdisswordfishc 3y agoIronically, I have had profs tell me to use nested ifs instead of breaking loops, so…
- HaroldBolt78 3y ago[flagged]
- drewcoo 3y agoIt's more about guard clauses. https://en.wikipedia.org/wiki/Guard_(computer_science) https://en.wikipedia.org/wiki/Guard_(computer_science)
- hayley-patton 3y agoMy high school computing exam (by government direction - VCE, graduated 2019) was filled with many such If a And b Then Return True Else Return False End If programs. Not sure why they were so scared of Return a And b. Apparently they got a new curriculum after I graduated; my teacher was very happy about it but I didn't get to see it myself.
- erik_seaberg 3y agoIn an intro class using Ada I’ve seen case Big_Expression_Here is when true => Do_Something; when others => Do_Something_Else; end case; and I found myself wondering whether they realize what this is.
- hayley-patton 3y agoWell, the 2019 final exam [0] lacks such questions; it must have been some other year. But the correct data type for an "AccountBalance" variable (section C, question 9) was a float, so I definitely lost marks on that question! The 2021 final exam (which is the most recent I can find) [1] somehow creates XML records for a SQL database (section C, question 7), and hints at using "data validation" to avoid an SQL injection (section C, question 11.c), which is quite exciting. And the 3.5 gigabit wireless connection (section A, question 13) is definitely not using an ISP-supplied router. [0] https://www.vcaa.vic.edu.au/Documents/exams/technology/2019/2019comp-softdev-w.pdf https://www.vcaa.vic.edu.au/Documents/exams/technology/2019/..., answers https://www.vcaa.vic.edu.au/Documents/exams/technology/2019/comp-softdev_examrep19.pdf https://www.vcaa.vic.edu.au/Documents/exams/technology/2019/... [1] https://www.vcaa.vic.edu.au/Documents/exams/appliedcomp/2021/2021AC-softdev-w.pdf https://www.vcaa.vic.edu.au/Documents/exams/appliedcomp/2021..., answers https://www.vcaa.vic.edu.au/Documents/exams/appliedcomp/2021/2021softwaredev-report.pdf https://www.vcaa.vic.edu.au/Documents/exams/appliedcomp/2021...
- cookieperson 3y agoIf a code reviewer pulls that on you, meet with them and explain why that's asinine. If that fails bring in someone more senior as a tie breaker. If that fails, find somewhere else to work...
- gizmo 3y agoIn C++ projects you see the verbose version a lot, because it's much faster to set a breakpoint on a statement than on a conditional expression. It's really annoying to repeatedly stop debugging, add the redundant return statements, and sit through a recompile cycle just because `return expr` looks nicer than `if (expr) return true else return false`.
- regularjack 3y agoAlternatively, you could use a debugger that supports conditional breakpoints.
- xxs 3y agoCond breakpoints require the code breaking each time and evaluate the statement which makes it runs like snail.