Code, Nerdyness, and Nonsense...: Code Cleanup With The Ternary Operator

Every time I write a simple function to return a value, I almost always write the same code. It is usually along the lines of this:

 if(indexPath.section == 0) return 45; return 65;

And immediately after writing it, I scratch my head and go “What the heck am I thinking?”. That’s when I remember…

See more
This post has 13 notes
Tagged with cleancode, code,
Posted at 2:37 AM 23 July 2010
  1. jamaday said: Python junkies don’t for get we have a Ternary Operator too, but it looks a bit different. It would look like: return 45 if indexPath.section == 0 else 65
  2. gidogeek reblogged this from brandontreb
  3. brandontreb posted this
Bookmark and Share