Boolean expressions that can involve logical operators, used for branching execution paths, which increases cyclomatic complexity.

learn more… | top users | synonyms

4
votes
2answers
145 views

Writing a set of JavaScript conditionals more efficiently

There must be a better way to write this, maybe with a switch statement (which for some reason I can't get to work). Basically, if one of the conditionals is true then the class in the statement is ...
4
votes
4answers
65 views

Refactoring huge if..elif in __init__ how?

I have this huge __init__ method, which is readable I think, but still doesn't feel right after watching Clean Coders videos (content of Clean Code book by Robert ...
6
votes
3answers
693 views

Simplifying a series of type checks and casts in a generic method

The if/else statements below are not good. How can I improve this method? ...
8
votes
6answers
851 views

Is it possible to optimize the following boolean checks?

The following code works and it prints out only True as it is supposed to, for all the different cases: ...
0
votes
1answer
31 views

Checking for variable being passed in Python [closed]

I have a Python script which is littered with if statements which checks for whether a variable was passed. An example is some function like this: ...
8
votes
6answers
981 views

Reducing conditional statements to avoid cyclomatic complexity

Is there a better way to write the following code fragment? I can't have more than 10 conditional statement in my method as it gives cyclomatic complexity. ...
19
votes
7answers
3k views

Find min of 3 numbers hardcoded

...
5
votes
4answers
140 views

Add-to-cart method has too many conditions

I have a method that seems to be too much for one method. I might be validating programming methodology. I just don't know what to do with it. Would a switch statement be better? Should I break it up ...
2
votes
2answers
60 views

Multiple isset block going from more specific to more generic

I have a data structure that allows for inheritance of properties, in such a way that if a property is not defined within a context, the second most specific context is checked until said property is ...
7
votes
3answers
203 views

Refactor a selection validator

I have a data table and have to validate every field in it. I have refactor this code to this below, but the complexity is 15(!!) Should I make something like dictionary with ...
8
votes
1answer
206 views

Changing button colors based on user input

I am using C# to get the user's input of how many buttons to change the color of. The buttons are in rows that have 1-10 button in each. If the user enters 11, then the entire first row will be ...
5
votes
3answers
103 views

Simplifying logic of overlapping predicates

I have 3 simple predicates and 3 simple actions to be taken based on those predicates. In my actual application they are not based on integer arithmetic, and in fact are rather expensive to compute ...
3
votes
2answers
95 views

Formatting options for a long IF statement?

I have a somewhat unwieldy IF statement and am wondering if anyone has any suggestions on how to make it more readable. One one line it was all but impossible to understand, so I broke it up into ...
6
votes
2answers
188 views

Displaying content based on the current time

I'm new to PHP and just wrote a bunch of if statements to display content based on the current time. Is there a better way of writing the following block of code ...
4
votes
2answers
58 views

Conditional Branching Using Filter

I'm using multiple jQuery filter functions to affect the background color of select objects based on the selected option and it works, but it seems bulky/redundant. Does anyone know how these filter ...
1
vote
0answers
25 views

Avoiding boundaries if-cases when filtering image matrix

I have the following MATLAB Code which I want to optimize. It's related to an image matrix (2D) which I want to filter. Though it is MATLAB code, the same problem would arise in C code. The problem ...
6
votes
3answers
335 views

Refactoring decision tree

Currently I have ...
3
votes
1answer
70 views

Breaking after one of several string replaces occur

I have a script that matches a string against ~20 different regexs for the purpose of changing it. They are ordered and formed that the string will only ever match against one. How can I avoid ...
3
votes
2answers
83 views

Simplify an if else construct with assignment before if and else

I want to simplify an if: .. else: .. construct: ...
6
votes
2answers
99 views

Inventory check with too many else-ifs

I am using if else statements: ...
5
votes
3answers
241 views

Shorten code to perform search based on four slash-delimited parameters

How can I make this code more compact? It is a ASP.net WebForms project It is a SinglePageApplication for searching in list mode and map mode. I have many paths for a page. /Denmark ...
4
votes
1answer
108 views

Simplifying if else statements in Python code snippet

How can I simplify and optimize this code? ...
2
votes
2answers
73 views

Comparing if-else and case condition

I have a script used for installing few rpms depending on operating system type. Here in this example, the script will install packages on two system "centos" and "suse". The system names are listed ...
10
votes
6answers
2k views

Beehive numbers - using goto in C++

I understand that using goto in C++ code is strictly unadvised, but sometimes, it really reduces the number of lines of code like in the following case. This is my ...
3
votes
4answers
95 views

Helper function to return a string based on passed object and some defined rules

In my application, a notification should be displayed when a chat message arrives. There are some rules which decide what notification message is to be displayed. I have created a helper method ...
2
votes
0answers
67 views

Restructuring multiple conditionals

I'm trying to figure out a better way to structure some of my code so that I don't have a ton of conditionals here. I have a series of checkboxes that someone authors on the backend and if they are ...
4
votes
3answers
166 views

Changing the foreground and background colors of substrings based on ANSI escape codes

I am checking for particular keywords in a string, and then changing the foreground and background colors of substrings based on the keywords. Following is the snippet for checking the background ...
2
votes
2answers
96 views

Calculating golf score against course par

This PHP script will translate shots on 18 holes to a total under par or E which is 0. ...
-2
votes
2answers
93 views

Refactoring the logic of a return value

In my method I have something like this: ...
1
vote
1answer
49 views

Adding additional function if condition is met

Here's my scenario: In case the table has class 'trans' - run dataTable() and ...
3
votes
1answer
82 views

Shortening if-statements of displaying errors

Is it possible to shorten this piece of PHP code? Honestly, I think it does not look clean but like a mess. ...
7
votes
6answers
214 views

Conditional statements relating to hospital management

It works just fine, but is there any other way to write this shorter? Nurses are only available to intensive care patients (room I) and TV's and telephones are only available to non intensive care ...
5
votes
2answers
262 views
10
votes
4answers
880 views

Constructor to transform an Outlook contact into a Dynamics CRM contact

This is my constructor to transform an Outlook contact into a Dynamics CRM contact: ...
1
vote
2answers
34 views

What do you think about this custom syntax? [closed]

I'm making a programming language and I've got the basis of a virtual machine working. The next step to is design the actual syntax for the language. I'd just like to know if whether the example ...
7
votes
6answers
1k views

Shorter way to write multiple if-then-else-if

if($row['best']){ $id = $row['best']; } elseif($row['average']){ $id = $row['average']; } elseif($row['bad']){ $id = $row['bad']; } If ...
2
votes
3answers
241 views

Coding style preference if (aPtr), if (aPtr != NULL), or if (NULL != aPtr) [closed]

I understand that as far as the compiler is concerned, the following lines are equivalent. if (aPtr) {...} if (aPtr != NULL) {...} if (NULL != aPtr) {...} ...
2
votes
2answers
98 views

How to format embedded if statements in JavaScript

What would be the best way to format this code? It looks a bit messy to me in regards to indentation etc. ...
1
vote
1answer
41 views

Remove nodejs/browser specific code in library

I'm the maintainer of the following library on github: https://github.com/edi9999/docxtemplater/blob/master/coffee/docxgen.coffee I want to maintain a library that works on node and in the browser, ...
9
votes
3answers
174 views

Thinking outLoud conditional if statement vs. for statement

I have been working with java for a little more than a year. I recently have built a tic tac tow game as an assignment for my java class. After instructor graded it, he wrote a comment around my ...
16
votes
5answers
3k views

Tic Tac Toe computer AI

I am creating a TicTacToe game for my college project, and when I finished the code for computer AI, I ended up with a big chunk of code. It allows the computer to make the winning move, stopping the ...
6
votes
6answers
283 views

To update or to delete? That is the Query

I'm currently developing a method which performs an update of some data; much like the following simplified logic: ...
17
votes
6answers
2k views

Are the following IF statements acceptable?

I have the following code: ...
6
votes
5answers
1k views

Movement code from a game

Could you suggest ways of writing this code better? ...
3
votes
1answer
139 views

Use if/else/elif conditionals to write a basic Rock Paper Scissors game

I have the following code for the Rock, Paper, Scissor game. The code works fine in Python 2.7. Are there other more concise, more readable, or more pythonic ways of solving this problem in Python? ...
10
votes
3answers
145 views

Refactoring if-else structure with elements of dict

I have code which gets data from a POST request (request.form dict), compares with corresponding attribute in object ...
8
votes
4answers
1k views

Password checker in PHP

I have written a password checker using PHP, consisting of many if else statements. Is there any possible way to shorten this code? ...
4
votes
1answer
224 views

How can I reduce the number of nested if statements in this code?

The application I'm building can accept two types of updates: Application Update and Parameter Updates. If there is an application update, then parameter updates can be ignored. This is the code that ...
4
votes
1answer
63 views

Is there a way to shorten a set of conditionals like this?

I have a long set of IF statements that basically set a null object Value to 0, I feel that because i am doing the same action each time their has to be a simple ...