The tag has no usage guidance.

learn more… | top users | synonyms

17
votes
10answers
18k views

Should I use switch statements or long if…else chains?

Often when I hear about the switch statement, its put off as a way to replace long if...else chains. But it seems that when I use the switch statement I'm writing more code that I would be just ...
21
votes
6answers
8k views

Refactoring Switch Statements and is there any real use for Switch Statements at all?

I was reading this article and was wondering, do we get rid of all switch statements by replacing them with a Dictionary or a Factory so that there are no switch statements at all in my projects. ...
35
votes
14answers
12k views

Why use an OO approach instead of a giant “switch” statement?

I am working in a .Net, C# shop and I have a coworker that keeps insisting that we should use giant Switch statements in our code with lots of "Cases" rather than more object oriented approaches. His ...
18
votes
8answers
5k views

What is the benefit of switching on Strings in Java 7?

When I was starting to programme in Java, the fact that switch statements didn't take strings frustrated me. Then on using Enums, I realised the benefits that you get with them rather than passing ...
8
votes
5answers
2k views

If-Else V.S. Switch end of flow

I was wondering the if if-else statements, is like a switch statement that does have a break statement. if( boolean_expression_1 ) statement_1 else if( boolean_expression_2 ) statement_2 else ...
14
votes
2answers
1k views

Why don't languages use explicit fall-through on switch statements?

I was reading Why do we have to use break in switch?, and it led me to wonder why implicit fall-through is allowed in some languages (such as PHP and JavaScript), while there is no support (AFAIK) for ...