DEV Community

Discussion on: If Statement Golf: what's the longest one you've seen?

Collapse
 
jsn1nj4 profile image
Elliot Derhay

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)
Collapse
 
grmnsort profile image
German Rodriguez Ortiz

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 :)

Collapse
 
mohr023 profile image
Matheus Mohr

Holy jesus, have mercy on that dev...