News for hackers. Stuff that matters.
Re:1/0 = 0 by smallnamespace on Friday August 10, 2018 @06:34PM (#17737176)
Isn't a ternary here nicer?

  return (foo == 0) ? 0 : bar / foo
or even

  return bar / max(1, foo)
in the case where foo is integer or tiny foo would overflow your range anyway
Re:1/0 = 0 by KennyCason on Friday August 10, 2018 @06:53PM (#17737276)
I would say it doesn't really matter much as both are readable. I would prefer either the original if/else or the ternary solution over the last solution as I personally think the intent is not as immediately clear in your "max" form. I would optimize for readability over density, unless there is some reason to write it differently (e.g. performance).

just for fun, in kotlin (making use of expressions removes some verbosity):

    return where(den) { 
       0 -> 0 
       else -> num / den 
    }

    return if (den == 0) { 0 }  
           else { num / den }
Re:1/0 = 0 by Dylan16807 on Friday August 10, 2018 @07:30PM (#17737429)
Ternary doesn't really look any better. I'd do this in a language that supports it though:

  return foo && bar / foo