Linked Questions
34 questions linked to/from How to tackle a 'branched' arrow head anti-pattern?
56
votes
11
answers
155k
views
How would you refactor nested IF Statements? [duplicate]
I was cruising around the programming blogosphere when I happened upon this post about GOTO's:
http://giuliozambon.blogspot.com/2010/12/programmers-tabu.html
Here the writer talks about how "one ...
31
votes
4
answers
10k
views
Style for control flow with validation checks
I find myself writing a lot of code like this:
int myFunction(Person* person) {
int personIsValid = !(person==NULL);
if (personIsValid) {
// do some stuff; might be lengthy
int myresult ...
31
votes
3
answers
62k
views
Approaches for checking multiple conditions? [duplicate]
What is the best practice for checking multiple conditions, in no particular order?
The example in question needs to check four distinct conditions, in any order, and fail showing the correct error ...
0
votes
3
answers
1k
views
Eliminate duplicate code in nested IFs without creating a function [duplicate]
Let's say we have two ifs that depend on each other:
if var exists {
if var is array {
//Do stuff with var
} else {
//Resolve the problem
}
} else {
//Resolve the ...
-2
votes
1
answer
2k
views
How to clean a refactor Java for-if-try-catch-else kind of messy code [duplicate]
Often I came across situations like this, how to write this code in a neat and clean way.
One more issue I find here is performance as I am iteration a list and then it's properties.
Edit : - while ...
2
votes
1
answer
960
views
Proper way to refactor multiple if based conditions [duplicate]
I took over a large legacy code base. It has a code like this:
if ($route == 'login' || $route == 'logout' || $route == 'forgot-password') {
return;
}
if ($loggedInUser == false && $...
-1
votes
5
answers
357
views
How can I efficiently write a complex if or switch condition that depends on a combination of two (or more) variables? [duplicate]
In my current case, I've got two variables. Let's call them action and status for ease of use. They can have any value between 1 and 9. Depending on business logic, I've to either call subActionA() or ...
-1
votes
1
answer
877
views
rails, how to refactor nest if statements? [duplicate]
I'm working a project where I found another developer wrote a method as you see it below.
How would I clean those IF statements and refactor this method.
Also is it ok ti set a variable to nil ?
def ...
0
votes
1
answer
826
views
Better pattern than large if/else if/else for checking conditionals [duplicate]
I've got a fairly large set of booleans I'm checking in javascript, and then using them to alter the state of a layout in my React app. The whole thing is unwieldy, difficult to read, inelegant, and ...
1
vote
1
answer
198
views
Obsessed with filling hashmaps instead of using else if cascades or switch statements [duplicate]
Whenever I feel like choosing from a list of implementations I always prefer to fill a map first and then call whatever I need based on a parameter, instead of using switch or else if statements.
...
2
votes
4
answers
253
views
is it worth rearrange if else structures to shorter form [duplicate]
In our project there are deep and lengthy if-else structures which can be significantly shortened by a simple rearrangement. To me the shorter version would be easier to understand also.
As an ...
3
votes
0
answers
103
views
Refactoring nested if-else statement [duplicate]
I have an app where every object is checked based on various types of business rules. For this, i used multiple nested if-else statement which was done in one class. I am not happy with this situation ...
218
votes
14
answers
109k
views
"Never do in code what you can get the SQL server to do well for you" - Is this a recipe for a bad design?
It's an idea I've heard repeated in a handful of places. Some more or less acknowledging that once trying to solve a problem purely in SQL exceeds a certain level of complexity you should indeed be ...
175
votes
24
answers
118k
views
Elegant ways to handle if(if else) else
This is a minor niggle, but every time I have to code something like this, the repetition bothers me, but I'm not sure that any of the solutions aren't worse.
if(FileExists(file))
{
contents = ...
51
votes
6
answers
104k
views
Clarification of "avoid if-else" advice [duplicate]
The experts in clean code advise not to use if/else since it's creating an unreadable code. They suggest rather using IF and not to wait till the end of a method without real need.
Now, this if/else ...