Skip to main content

Questions tagged [conditions]

Filter by
Sorted by
Tagged with
18 votes
7 answers
4k views

I'm preparing a lecture where I will start with a many-branched conditional statement and replace it with a table. For example, I could start with: function getMonthName(monthNumber) { if (...
Ellen Spertus's user avatar
19 votes
7 answers
5k views

I am working in small company, having a lead position in a group of 5. We are developing a C++ application. One requirement is that it needs to run fast. Today, I noticed one function, say f1(), and ...
Jason Cho's user avatar
  • 301
1 vote
1 answer
340 views

I'm trying to make a DFD for this scenario: after admission, the patient gets the service he needs. I've been trying to do it using this diagram (there are 3 available services): but I don't think it'...
Ahmad Ahmad's user avatar
5 votes
5 answers
1k views

I've set up a ternary operator in place of a pile of if-else's, the final expression being nullptr in order to finish the loop, like so: int menuSelect; std::string operation=""; (...
Hench's user avatar
  • 61
0 votes
4 answers
222 views

I have the existing code provided below: if (!$existing_records && !$has_required_field) { return 'Skip Update, no records found'; } elseif (!$existing_records && $...
Muhammad Dyas Yaskur's user avatar
0 votes
2 answers
179 views

In a library, there could exist three types of functions. The first are those which are visible to the user i.e. their declarations are installed in the library's include directory. The third are ...
Nitin Malapally's user avatar
0 votes
1 answer
216 views

I have the code but I want to be pseudo as possible so I learn from other ways as much as possible. So what I am building is web based tool and in one section we have a table. This table renders lines ...
Codemenot's user avatar
4 votes
2 answers
364 views

I have a class (as a protobuf) OrderChange, that represents when an order (imagine Amazon.com) changes: message OrderChange { Order old_order = 1; Order new_order = 2; } message Order { ...
onepiece's user avatar
  • 169
2 votes
1 answer
3k views

Often I find conditional statements such as: if (life_max < max): if (expand): do life_max = max else: if (life_max > max) and not (expand): do life_max = max; Although readable, ...
Chibueze Opata's user avatar
3 votes
4 answers
850 views

I am curious about it because I talked with a friend about the strategy pattern, and we diverge about when we have to use it. Our scenario is that I have to build a view component with 3 variants. All ...
ViTUu's user avatar
  • 139
2 votes
1 answer
299 views

We have a "workflow orchestration" system at work. It works something like this: You configure what to run (in a database table), such as: NameOfStepATHingToRun ="weather_data" ...
Neil McGuigan's user avatar
3 votes
0 answers
103 views

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 ...
Arife Kübra's user avatar
3 votes
1 answer
4k views

Stallings' Operating System book says about condition variable in Solaris, A condition variable is used to wait until a particular condition is true. Condition variables must be used in ...
Tim's user avatar
  • 5,565
-2 votes
1 answer
818 views

I have the below default method in an interface and it seems to be pretty complex because of the many if-else conditions. default void validate() { Application application = application().get(); ...
AnOldSoul's user avatar
  • 173
-2 votes
1 answer
985 views

I have an abstraction that defines something like a command pattern, interface Participant { void proceed(); } Participants are grouped in a collection and are called all together. But each ...
lucasvc's user avatar
  • 141
4 votes
5 answers
285 views

I am writing a function that I would not like to get called given a certain context and am wondering how best to convey that to possible users of the function. Assume, for exemplification, I am ...
Ganea Dan Andrei's user avatar
1 vote
3 answers
271 views

The following code works and is clear, but it's also verbose. I suspect that there's a way to make it more terse, so that it could be skimmed quickly and it'd be more obvious what's happening. // The ...
Ian Dunn's user avatar
  • 125
3 votes
5 answers
1k views

I commonly use a boolean condition/variable when it's something too big or complicated and takes too much space by itself inside ifs - basically to avoid repeatability and thus improve readability. E....
PascCase's user avatar
3 votes
1 answer
167 views

I want to choose between several options, and if the criteria I'm using for selection happen to be equal, I want one at random (reasonably so, so it's equal-chance each time, rather than arbitrary). ...
mattdm's user avatar
  • 149
-2 votes
2 answers
542 views

In Java, C, and C++ we have the following jump statements: break, continue, goto, and return. In C#, there is also throw. I'm not really familiar with either of these languages. This is simply what I ...
john c. j.'s user avatar
8 votes
5 answers
1k views

Is it bad practice to add false or ... or true and ... for the sake of promoting code genericness and/or ease of use? As in: SELECT * FROM table WHERE TRUE AND IsEnabled AND SomeField = some_value ...
Nae's user avatar
  • 197
3 votes
2 answers
330 views

Software libraries targetting resource constrained environments like embedded systems use conditional compilation to allow consumers to shave space and thus increase performance by removing unused ...
TZubiri's user avatar
  • 443
7 votes
2 answers
899 views

Software libraries targetting resource constrained environments like embedded systems use conditional compilation to allow consumers to shave space by removing unused features from the final binaries ...
TZubiri's user avatar
  • 443
0 votes
1 answer
71 views

Sorry for the bad title. Couldn't really think of a good name without an explanation. In our system (source is inside Oracle PL/SQL packages) we have quite a lot large SQL queries with a sh..load of ...
gobnepla's user avatar
  • 133
1 vote
1 answer
119 views

In Scheme, the general form of a procedure definition is: (define (<name> <parameters>) <body>) where <body> accepts a sequence of expressions, allowing this kind of procedure ...
Géry Ogam's user avatar
10 votes
5 answers
792 views

This is a thing I'm doing a lot lately. Example: setCircle(circle, i, { current }) { if (i == current) { circle.src = 'images/25CE.svg' circle.alt = 'Now picking' } else if (...
gaazkam's user avatar
  • 4,529
2 votes
4 answers
584 views

I would like to get your code thought and views on using conditional vs logical testing. For example: To test the conditions of truthness of all of the following variables, their currect status is ...
Mohsen Alyafei's user avatar
2 votes
2 answers
389 views

I have an API in which we expect a emailID and a certain deal data. The case is we want to keep the dealId and contactId(email) to be unique. Creating a deal requires data insertion in multiple ...
Ishan Arora's user avatar
2 votes
2 answers
3k views

A colleague, and frankly better software engineer that me, is telling me that this pattern let variable = someDefaultVariable(); if (some_boolean) { variable = someOtherValue(); } is better than ...
Joey Gough's user avatar
2 votes
3 answers
1k views

I am working on a Rails application which employs a classic MVC as its fundamental structure. In that structure the controller is supposed to be responsible for "which view to render when". Now after ...
ivanibash's user avatar
  • 143
2 votes
2 answers
202 views

For example, suppose I have 2 arrays: let arr1=[5,2,1]; let arr2=["abcde","ab","a"]; my work is simple : to check if length of strings in arr2 are larger than corresponding element with same index in ...
ocomfd's user avatar
  • 5,760
3 votes
5 answers
7k views

I have a function which returns the availability of a module, where the module is only available if multiple conditions are all met. The code looks like this: bool isShipAvailable() { bool ...
codehearts's user avatar
0 votes
3 answers
151 views

I encountered code like this below. I was told its fine, and boilerplate is not always better. I agree boilerplate might be bad, but I am not sure about something like this: if (entity....
wpazio's user avatar
  • 103
-1 votes
1 answer
182 views

I am designing a project where I have to enforce IF, ELSEIF and ELSE conditions on collection of objects. For example: public class Box { private List<Item> items; } I want to define IF ...
Kishor Prakash's user avatar
1 vote
1 answer
1k views

This is closely related to this question which asks about the complexity of the following: while (x > level) x = x – 1; x = 0 Using the graph method it has a Complexity = 2. Fred Swartz ...
Alexei's user avatar
  • 452
5 votes
6 answers
12k views

I have a class that handles the state of a response, called StockResponse. The code has multiple ifs to handle each state of the stock. Most of the cases has a default behaviour, but some conditions ...
X.Otano's user avatar
  • 622
4 votes
3 answers
2k views

I do a lot of coding in python and got a lot of if conditions without an else statement so to say partial branches. E.g.: # if a certain kwarg was passed to a function call if kwargs.get('a_option'):...
Igl3's user avatar
  • 149
0 votes
3 answers
4k views

I’m writing an asynchronous, Promise-returning function. In the processing I test some conditions, and if the conditions pass, the promise should be fulfilled (resolved), but if one fails, then the ...
chharvey's user avatar
  • 264
0 votes
1 answer
105 views

I have a function a plugin that is called whenever the WebAPI's "Plugin" endpoint is called in the main project, and that has to process the HTTP request. The request holds more information about what ...
Alexander's user avatar
  • 181
46 votes
13 answers
20k views

I'm trying to follow Uncle Bob's clean code suggestions and specifically to keep methods short. I find myself unable to shorten this logic though: if (checkCondition()) {addAlert(1);} else if (...
Ev0oD's user avatar
  • 559
4 votes
2 answers
16k views

Please refer the following two forms of the same code First: <?php if(some_condition){ ?> <li><a target="_blank" href="example.com/channel1/" class="xyz">If content</a>&...
kadamb's user avatar
  • 173
187 votes
15 answers
79k views

I have an acquaintance, a more seasoned developer than me. We were talking about programming practices and I was taken aback by his approach on 'if' statements. He insists on some practices regarding ...
Patsuan's user avatar
  • 1,647
2 votes
2 answers
3k views

Just wondering if there is a good way to do this? Currently i'm performing the method calls as if they were happening prior to the conditional block, then comparing what would be the result in "[...
ldmccartin's user avatar
1 vote
1 answer
202 views

I need a run-only-once method that when all the criteria are met, say A&B&C are true, run the codes once, but only once. So if later on all the criteria are met again (A&B&C are true ...
Qiulang 邱朗's user avatar
4 votes
2 answers
5k views

We have an application that allows users to enter conditionals in the form bound op x op bound2, we store this as a string, and then parse it at runtime to evaluate it. It is a decent amount of work, ...
soandos's user avatar
  • 313
20 votes
7 answers
3k views

I sometimes stumble upon code similar to the following example (what this function does exactly is out of the scope of this question): function doSomething(value) { if (check1(value)) { return -...
rhino's user avatar
  • 357
3 votes
3 answers
777 views

Consider a scenario, where A occurs frequently like 4 out 5 times, and B only in rare cases, we can write our conditional statement in two ways: if(A) //do something else // do something if B, only ...
The Law's user avatar
  • 255
9 votes
2 answers
11k views

Just saw a code snippet that used an array pop assignment in the while condition; was wondering if this is acceptable/good practice? var arr = [0,1,2,3,4,5]; var current; while (current = arr.pop()) {...
flewk's user avatar
  • 103
-2 votes
3 answers
3k views

Which way is better? -- Option 1------------- if ( condition1 ) { statement1 } else { exit program } if ( condition2 ) { statement2 } else { exit program } ----...
user1657661's user avatar
1 vote
5 answers
826 views

I am writing a program that looks for a solution of a diophantine equation. The program is cycling for (int d = 0; d <= max; d++) { for (int c = 0; c < d; c++) { boolean ...
sixtytrees's user avatar