Tagged Questions

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

learn more… | top users | synonyms

-1
votes
1answer
47 views
3
votes
2answers
46 views

Hide / Show panels depending of value of a dropdown

According to the value of a dropdown menu I have to show/hide two panels. For option 'derive' and 'reject' I should show the comment panel, and just for the 'derive' panel I should also show a ...
5
votes
2answers
59 views

Finding the Greatest Integer and Ties

I'm trying to find the greatest integer of four integers and its ties. I used the following code. Is there anyway to simplify this more effectively? ...
6
votes
2answers
510 views

Javascript condition optimization

Can the following condition be optimized/simplified ? ...
7
votes
1answer
83 views

Multiplayer bowling in Ruby (follow-up: injection, single responsibility)

This is a multiplayer bowling simulator in Ruby. It allows for variable skill levels, and produces weighted random results for each player's rolls based on those skill settings. This is a complete ...
12
votes
1answer
93 views

Multiplayer bowling in Ruby, with variable skill

This is a multiplayer bowling simulator in Ruby. It allows for variable skill levels, and produces weighted random results for each roll based on those skill settings. The methods are grouped in four ...
2
votes
1answer
49 views

Conditional statements with doctor and patient information

I'm focusing on trying to write clean, modular Python 2.7.5 code. ...
15
votes
3answers
2k views

Beastly if statement, adding a course to one of 8 periods

I have this rather ghastly if statement and I'm sure there is a way to condense it, but I don't really know how. I was told a ...
1
vote
1answer
62 views

How do I bind a symbol in a conditional in Clojure? [closed]

In Ruby (on Rails) I would do this in a controller action to provide authentication: ...
11
votes
4answers
776 views

Writing null-safe code to set form values

I will ask my question using the following example: HTML ...
1
vote
1answer
65 views

Conditional AND statement- which is more readable?

Does this function automationStatusIsSuccessful = (data) -> data.Automation.Status isnt "FAILED" and data.Automation.Status isnt "COMPLETEDWITHERROR"` ...
3
votes
1answer
54 views

Complex Conditionals in a Strategy Game

I have been looking at this method for a long time and I have finally refactored it into something that I believe is much more readable. I am not totally happy with it though so I would like to get ...
2
votes
5answers
224 views

Avoiding multiple if conditions in a Car class

In this dummy structure, we have a race car manager class. this class contains a method named execute(). There is a List which contains all participating racing ...
10
votes
7answers
2k views

How to simplify this if else statement?

How would you simplify/improve the readability of this code? Because even after my attempt to improve the readability I think it still looks messy. ...
12
votes
2answers
858 views

Using large amounts of if-else statements for playing card numbers

I have a method that uses a bunch of if-else statements, and I am thinking how I could simplify it. ...
4
votes
2answers
165 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
76 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
723 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
872 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: ...
10
votes
6answers
1k 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. ...
18
votes
7answers
4k views

Find min of 3 numbers hardcoded

...
5
votes
4answers
148 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
63 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
206 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
228 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
115 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
97 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
227 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
62 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 ...
2
votes
0answers
30 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 ...
7
votes
3answers
358 views

Refactoring decision tree

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

Simplify an if else construct with assignment before if and else

I want to simplify an if: .. else: .. construct: ...
2
votes
1answer
408 views
6
votes
2answers
108 views

Inventory check with too many else-ifs

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

Simplifying if else statements in Python code snippet

How can I simplify and optimize this code? ...
2
votes
2answers
80 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 ...
4
votes
4answers
116 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
225 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
118 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
103 views

Refactoring the logic of a return value

In my method I have something like this: ...
1
vote
1answer
54 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
85 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
220 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
274 views
10
votes
4answers
902 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: ...