Linked Questions

1
vote
0answers
65 views

Is using a non-compile-time-constant value as a default parameter a code smell? [duplicate]

I'm trying to use App.config and Configuration Manager for the first time. I wanted to use some values in App.config as default parameters for some methods, but this results in an error (not a compile ...
64
votes
12answers
10k views

Having a flag to indicate if we should throw errors

I recently started working at a place with some much older developers (around 50+ years old). They have worked on critical applications dealing with aviation where the system could not go down. As a ...
5
votes
2answers
277 views

Is it wrong to use any type of parameter to determine behavior?

According to Is it wrong to use a boolean parameter to determine behavior?, I should not use a boolean parameter to switch behavior inside a function. How about other types of parameters? For example,...
39
votes
13answers
10k views

Is it wrong to use a boolean parameter to determine values?

According to Is it wrong to use a boolean parameter to determine behavior?, I know the importance of avoid using boolean parameters to determine a behaviour, eg: original version public void ...
5
votes
6answers
706 views

How to eliminate a if-else block which is used to determine behaviour according to a boolean input?

According to Is it wrong to use a boolean parameter to determine behavior?, I know it is bad: public void myFunction(boolean b){ if(b){ }else{ } } and it should have separate function: ...
1
vote
4answers
2k views

Are all boolean arguments flag arguments, and thus a code smell?

Martin Fowler describes the Flag Argument code smell as a "kind of function argument that tells the function to carry out a different operation depending on its value". Answers to Is it wrong to use ...
25
votes
7answers
10k views

Specify optional parameter names even though not required?

Consider the following method: public List<Guid> ReturnEmployeeIds(bool includeManagement = false) { } And the following call: var ids = ReturnEmployeeIds(true); For a developer new to the ...
5
votes
3answers
783 views

Should conditional logic be always coded via type system where possible?

I have a choice. Option 1: public class Sample { bool IsRelevant { get; set; } } Option 2: public class Sample { } public class RelevantSample : Sample { } Is there a clear well-known rule ...
1
vote
1answer
81 views

Use a setStatus($arg) function or have separate enable() and disable() functions?

I've got two functions at the moment: suspendGroupsAndUsers($groupId){} enableGroupsAndUsers($groupId) {} But the difference between the two is one variable/string. Should I just have: ...
2
votes
3answers
823 views

Should I combine similar functions even though they are slightly different?

On an application I've been working on I have a function, connecting to a virtual machine, that can be performed two ways. The user can either select a machine from a list and click the "Connect" ...
9
votes
6answers
1k views

Is it better to have one method that takes a bool as a parameter or two methods with different names? [duplicate]

I'm writing a factory class for a Selenium Web Driver and I came across a choice that I couldn't figure out which is cleaner. Having two methods with the same parameter. GetWebDriver(string browser) ...