top | item 36112576

(no title)

nousermane | 2 years 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;
    }
  }

discuss

order

ggambetta|2 years ago

This 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|2 years ago

Visualizing 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

hayley-patton|2 years ago

My 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.

hayley-patton|2 years ago

Well, 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/..., answers https://www.vcaa.vic.edu.au/Documents/exams/technology/2019/...

[1] https://www.vcaa.vic.edu.au/Documents/exams/appliedcomp/2021..., answers https://www.vcaa.vic.edu.au/Documents/exams/appliedcomp/2021...

erik_seaberg|2 years ago

In 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.

cookieperson|2 years ago

If 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|2 years ago

In 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|2 years ago

Alternatively, you could use a debugger that supports conditional breakpoints.