-
Notifications
You must be signed in to change notification settings - Fork 2
Description
This is the code
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 terrible. Not only is the Service API awful (askForPermission could return a boolean rather than a String), but the Formatter.doTheJob() code itself is a huge if-then-else snippet.
This is one of the 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?