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

learn more… | top users | synonyms

6
votes
3answers
183 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
192 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
88 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 ...
-2
votes
0answers
29 views

understand operator precedence [migrated]

Was fixing bug in our code and found this weird function that was misbehaving: ...
3
votes
2answers
86 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
181 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
54 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
324 views

Refactoring decision tree

Currently I have ...
3
votes
1answer
69 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
82 views

Simplify an if else construct with assignment before if and else

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

Inventory check with too many else-ifs

I am using if else statements: ...
5
votes
3answers
236 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
100 views

Simplifying if else statements in Python code snippet

How can I simplify and optimize this code? ...
1
vote
2answers
67 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
84 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 ...
1
vote
0answers
64 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
141 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
90 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
86 views

Refactoring the logic of a return value

In my method I have something like this: ...
1
vote
1answer
44 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
81 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. ...
6
votes
6answers
210 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
261 views
10
votes
4answers
862 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
239 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
97 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
39 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
167 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
2k 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
281 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
127 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
136 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 ...
7
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
181 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 ...
6
votes
2answers
79 views

Nested trial and error in if-else condition

Using Rails 3.2, I have the following: ...
3
votes
3answers
131 views

Cleaning if-statements in job applicant email system

I just wrote this and don't like how bulky it is, also given the fact I will have to add at least another if statement. I was going to switch it to a case ...
1
vote
2answers
76 views

Reducing cyclomatic complexity in a simple string concatenation

I have written the following function that takes an address object and builds a string using the object properties. It will later be used to display a tooltip ...
4
votes
2answers
104 views

Alternative to multiple if statements

I have a function that needs to evaluate some parameters to determine if they're valid or not. They all need to be evaluated individually, so I have some code like below. ...
2
votes
2answers
75 views

Conditional functions or multiple similar definitions?

In my program(C++), I'm going to use callback functions to process input from the keyboard and mouse and constantly draw a scene. How these functions process information will change depending on the ...
10
votes
2answers
366 views

Simplifying conditional statements for transaction code

I have below code in one function: ...
3
votes
1answer
40 views

Creating objects to be added to a list

When creating objects to be added to a list in Python, we can avoid the if statement by changing our create_object function to ...
5
votes
3answers
228 views

if statements or eval?

I'm wondering about the following code: ...