Archive

Posts Tagged ‘Conditionals’

Coding Helpers – Add Else Statement

August 15th, 2012 Comments off

The Add Else Statement code provider performs the operation its name implies – it generates the ‘else’ statement of the current conditional statement. The ‘else’ statement is required when you want to execute a piece of code if a condition is not met. In other words, the ‘else’ is useful when an alternative case is required on the ‘if’ statement.

Read more…

Refactoring multi-conditional statements: the switch statement and the “if-else-if” ladder

April 30th, 2012 Comments off

There are two methods for multi-conditional processing: the “if-else-if” ladder and the switch statement. The If-Else-If ladder is a combination of ‘if’ and ‘else’ statements that is used to test a series of conditions. If the condition of the first ‘if’ statement is met, the code within the ‘if’ executes. Otherwise, the program flow is passed to the neighborhood ‘else’ statement, in which the next ‘if’ statement is located. This continues as a series of ‘if’ statements nested within the previous ‘else’ statements until all conditions have been checked. A default branch or a code block may be executed in a final ‘else’ statement if no condition is previously met.

Read more…

Refactorings – Flatten Conditional

March 22nd, 2011 Comments off

This is one of the most powerful refactorings for conditionals – it helps you to simplify conditional statements by unindenting all or a portion of the conditional statement which improves the clarity of the code. This refactoring includes several different refactorings mentioned in Martin Fowler‘s book, and a few others. These refactorings are applied, depending on the conditional blocks you have inside the source code. Here they are:

Read more…