4 ms·
The fact that it works doesn't mean it's good code. A switch statement should not be used like that IMAO because every developer just like the author is confuse
by siempreb 7y ago
The fact that it works doesn't mean it's good code. A switch statement should not be used like that IMAO because every developer just like the author is confused by first sight. Readability is an extremely important part of good code.
Personally I would prefer somthing like this:
return (githubUrl)
? configGithub
: (twitterUrl)
? configTwitter
: configDefault;
- lsaferite 7y agoI personally find this _way_ less readable at a glance. Every argument you make against using switch statements I would make against doing this as well. When you consider the semantics of the statements, using switch statements for this makes more sense than chaining ternary statements. Chained ternary statements is just a less readable if/else chain. Personally, if one of my guys chained a ternary like this I would immediately fail the PR. IMHO at least.