code4nothing/singlepath — pull request #1 by arialdomartini (2014-07-21 14:48:25+00:00)
Title: if-then-else necessary in order to return a different output depending on a service response

This is an example of a (Java) snippet of code where an ```if-then-else``` seems pretty natural.

We have an imaginary ```Formatter``` class with a method (```doTheJob(String)```) performing a trivial feature (it takes a string and it outputs the same string repeated twice).

Now, the class performs differently based on the output of its only dependence, ```Service.askForPermission()```

| ```Service.askForPermission()``` | ```Formatter.doTheJob("foo")``` |
| ------------- |:-------------:|
| ```"OK"``` | ```"foofoo"``` |
| ```"FAIL"``` | ```"error"``` |
| any other result | ```""``` |

Apparently, the code is awful. Not only is the ```Service``` API awful (```askForPermission```) could return a ```boolean``` rather than a ```String```. What's worst, the ```Formatter.doTheJob()``` code is a huge ```if-then-else``` snippet.

This is one of the (extreme?) cases where I think a conditional is pretty hard to remove. Or, at least, where I think the removal could produce a code more awful than the original one.

Can you prove me wrong?