re: If Statement Golf: what's the longest one you've seen? VIEW POST

FULL DISCUSSION
 

My entry: 18 conditions and 619 characters long.

I'm also including the actual statement, for anyone curious. I've added line breaks in some places to make it somewhat easier to read, but it was originally all on 1 line.

if ($FBtype == 'status' && $FBmessage == '' && $FBstory == ''
  || $FBtype == 'event'
  || $FBtype == 'event' && strpos($FBstory, 'shared their event') !== false
  || $FBtype == 'status' && strpos($FBstory, 'changed the name of the event to') !== false
  || $FBtype == 'status' && strpos($FBstory, 'changed the privacy setting') !== false
  || $FBtype == 'status' && strpos($FBstory, 'an admin of the group') !== false
  || $FBtype == 'status' && strpos($FBstory, 'created the group') !== false
  || $FBtype == 'status' && strpos($FBstory, 'added an event') !== false
  || $FBtype == 'event' && strpos($FBstory, 'added an event') !== false)
 

The first version of my if statement looked very similar to that, until I started to combine some of the comparisons into single variables, made it less intimidating almost instantly :)

 
code of conduct - report abuse