Some scientists believe that there should be only one return statement at the end of a function. They believe that the multiple return statement makes the code somehow unclean.
However, most language developers and professional programmers disagree with this purist view. Multiple return statements can be confusing if your method is long and complex (but if so, you have more problems than multiple return statements). But often, multiple return statements can make the code more readable.
Your code is fine except for one change I would make: use default .
switch(val) { case 0: return 's'; case 1: return 'c'; case 2: return 'h'; case 3: return 'd'; default: return 'h'; }
Mark byers
source share