Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [parameters]

Parameters are important for any non trivial program, to help make it generic and data driven. Parameters are usually function arguments but can also be part of the configuration.

Filter by
Sorted by
Tagged with
0 votes
1 answer
108 views

Elegant way in C to store many parameters with default value and current value in embedded flash

I'm programming an embedded system that has a number of user configurable parameters, which are stored in flash memory. I have to store a default value for each parameter as well as the user settings. ...
jusaca's user avatar
  • 175
0 votes
1 answer
118 views

Should I "introduce parameter object" for the case that the parameter is originally already a whole object?

According to Should we avoid custom objects as parameters?, for example, if I have an object to show: public class Student{ public int _id; public String name; public int age; public ...
wcminipgasker2023's user avatar
0 votes
3 answers
196 views

Is "the boolean value is from dynamic loaded data (eg:user input, database)" a reason to use boolean parameter?

I know there are some questions about boolean flags: Is it wrong to use a boolean parameter to determine behavior?, Multiple boolean arguments - why is it bad? which indicates the following code is ...
wcminipgasker2023's user avatar
1 vote
2 answers
371 views

For more than one parameter, when NOT to introduce parameter object?

I know there are some questions about "Introduce parameter object", eg: Is "Introduce Parameter Object" actually a good pattern?, Should we avoid custom objects as parameters?, ...
wcminipgasker2023's user avatar
0 votes
1 answer
88 views

Why aren't mandatory options requested in the signature of ASP.NET Core "AddXXX" methods?

I've developing a .NET Core library meant to simplify the configuration of the authentication within our SSO system. It will expose two methods to be called in the Program.cs (or Startup.cs) of ASP....
Gua-naiko-che's user avatar
4 votes
2 answers
1k views

Should a method modifying object passed as a parameter return the modified object? [duplicate]

I have some incoming request - it's an instance of class generated from api specification - POJO with public getters/setters. I would like to normalize some values. For example dimensions (to use ...
Shaolin's user avatar
  • 43
1 vote
2 answers
477 views

Ordering keyword arguments in a function call

In some languages such as Python, the order of keyword arguments in function calls does not matter. But is there a best practice for it? For instance, suppose that a function's signature is def foo(...
Scarabee's user avatar
  • 121
10 votes
8 answers
4k views

What is the purpose of enclosing all return values and arguments of a method in separate classes?

I've seen such a convention. Whenever a public method is declared, two classes are also defined that enclose its return value and parameters like this: public MethodNameReturnDTO MethodName(...
gaazkam's user avatar
  • 4,459
5 votes
2 answers
548 views

How to propagate parameters through several architectural layers?

Overview I am tasked with designing a system that serves as an Interface between a User and one or more microcontrollers in different Variants. As an example, our Microcontrollers Type 1 are milk ...
UnbescholtenerBuerger's user avatar
0 votes
1 answer
1k views

Dynamic Variables from JSON Parameter File

I want to assign Python variables imported from a JSON file. This question had an interesting answer using a classmethod, but I couldn't get it to work and I'm not allowed to comment... So, let's ...
Liz Livingston's user avatar
0 votes
2 answers
890 views

Reassign parameter to local variable

On Stack Overflow I frequently see questions with code in the following style: function funcName(parameter) { let variable = parameter; // rest of function uses variable rather than parameter } ...
Barmar's user avatar
  • 344
0 votes
5 answers
190 views

Should I "modularize" my configuration file into different files?

I have a simulation in Python which reads its configuration from a toml file. Since I have tons of parameters, the toml file can grow quite large. This is an example file, similar in structure to my ...
jfaccioni's user avatar
  • 506
2 votes
2 answers
450 views

When, and why, to pass parameters by value?

For anything larger than a 64 bit integer, why would I want to pass by value? [Update] The question was closed, because it was not specific enough. One comment suggested that I specify a language. I ...
Mawg's user avatar
  • 4,226
14 votes
14 answers
8k views

Should I raise an exception/error when an optional argument is used but is not necessary?

Take this constructed example: def fetch_person(person_id, country_code=None): if is_fully_qualified(person_id): return person_source_1.fetch_person(person_id) else: return ...
André Christoffer Andersen's user avatar
2 votes
2 answers
1k views

Unit testing of classes with functions as parameters in C++

Let's say I have a function in a class with the following signature: int fun(int x, int y,std::function<int(int, int)> funArg) The output depends on the operations done in funArg. My question ...
Wballer3's user avatar
1 vote
0 answers
120 views

Is using C++ Classes to handle commonly used parameters a misuse of classes?

My team works on an HTTP web server in C++. The codebase has aged over time, and has a widespread problem of 12+ parameters being passed to every function. A fake example: We need to build a Car, but ...
DonutGaz's user avatar
  • 251
3 votes
3 answers
2k views

Using python context managers instead of passing arguments: Is it an anti pattern?

We have an input flag in our API which indicates whether we should keep the mid level resources involved in fulfilling current request or not. I've decided to use some context managers at interface ...
Mehraban's user avatar
  • 269
2 votes
1 answer
564 views

Is it an antipattern to pass an object that stores the application state from one function to another?

The program is written in JavaScript. To give you a rough idea what I am thinking of: function State() { return { color: 'green', size: 100, // ... there are other properties here } } ...
becomeocean's user avatar
0 votes
2 answers
244 views

Anti-pattern in which code blocks are indirectly used as parameters

I was recently trying to explain a particular anti-pattern to some novice programmers and found that it was hard to express without an overly-detailed example. I'm sure it has a name and that someone ...
nben's user avatar
  • 345
2 votes
2 answers
186 views

Better way than repeatedly passing the same parameters?

I have some methods in my code that essentially hide/show some Views, like showTitleHideBody(), showBodyHideTitle(), etc. They just change their Views' (tvTitle, tvBody) visibility. Initially those ...
did_attics's user avatar
-3 votes
1 answer
215 views

Best way to pass an optional parameter to a program

In a couple of my programs, the program needs to know an IP address and a port to which it should connect or send data to. The solution I have right is to ask for user input via the console - but ...
Sebastian DonnerWolfBach's user avatar
-3 votes
2 answers
45 views

Passing different sized parameters cost savings

I was wondering if there is some cost saving, either in time or space by passing and/or returning smaller arguments? char vs int. I have heard the compiler will optimize the code based on the type of ...
Christopher J. Holland's user avatar
-3 votes
1 answer
47 views

Is there a good set of heuristics around how/when to use optional parameters

using a python function signature as an example: def this_function_has_an_optional_parameter(x, y = 42): ... I'm wondering if there is an existing set of guidelines specifically for this
Most_Arduous_Journey's user avatar
0 votes
3 answers
215 views

Should the type of a parameter that holds the arguments for a function be named "argument" or "parameter"

For context, I'm writing TypeScript, but I believe the concept works for many languages. I have a function getFooParams(): FoodParams, that gets data that gets passed to foo later on. (It's a React-...
duckbrain's user avatar
  • 151
1 vote
1 answer
1k views

Design Patterns for Passing Large Quantity of Parameters in Machine Learning

I am looking to better understand best practices for handling large quantity of parameters. I am particularly interested in the types of parameters involved in machine learning code bases and ...
sccrthlt's user avatar
  • 127
1 vote
2 answers
274 views

const function parameters and default behavior

Say I have a C++ function /** * @param path If empty, the system default is used */ void foo(const std::string& path); And in my implementation I have a default handling for empty paths void ...
PhilLab's user avatar
  • 159
7 votes
4 answers
1k views

Are "in" parameter modifiers considered a code smell?

As of C# 7.2+, you can add a parameter modifier in before the parameter type to define a parameter as const, essentially. It is like the ref or out keywords, except that in arguments cannot be ...
Reap's user avatar
  • 183
1 vote
2 answers
2k views

How should a streamwriter be passed to an object considering OO and DI

I have an class named FileCreator which is used to write many strings to a stream. Basically, to achieve its job, the FileCreator needs two objects: a StreamWriter and the actual strings that will be ...
user1861857's user avatar
3 votes
5 answers
8k views

Java: Why not allow nulls in methods to represent optional parameters?

I wanted to follow up on this previous question I asked related to @Laive comment, but I couldn't think of an excellent way to do so without asking another question, so here we go. With the previous ...
Ertai87's user avatar
  • 187
1 vote
8 answers
3k views

Is there a use case for boolean parameters? [closed]

Most programmers (including me) believe that methods with a boolean flag parameter should be refactored into two methods without the flag parameter. Are there any use cases for a boolean parameter ...
CJ Dennis's user avatar
  • 659
2 votes
2 answers
199 views

Is there a guideline as to when I should pass a collection as an argument or return a new collection?

Suppose I have the following methods: def read(file: str) -> List[str]: temp = [] with open(file) as f_obj: for line in f_obj: temp.append(line) return temp def ...
user avatar
3 votes
2 answers
526 views

Best practices for testing settings file with many parameters in simulation code

I'm conflicted as to what is the best way to approach this problem. I am writing a simulation in Python, which is parametrized by ~ 50 parameters. I have a JSON file where these parameters are set, ...
jfaccioni's user avatar
  • 506
2 votes
2 answers
206 views

Is inline still necessary when using the Named Parameter Idiom?

The Named Parameter Idiom as described here mentions that there will be a performance impact when not using inline. Since each member function in the chain returns a reference, there is no ...
user342634's user avatar
1 vote
3 answers
145 views

What considerations should I mind when designing methods or functions that take in a lot of parameters?

What considerations should I mind when designing methods or functions that take in a lot of parameters? A lot meaning over 4 but less than 10. Example, I am debating whether to pass in an array like ...
Dennis's user avatar
  • 8,247
-2 votes
1 answer
87 views

method taking a class parameter

I have recently begun studying UML. All is going fine so far until I saw the following: This is a class Called Point2D It has 2 attributes which are x, type float and y, type float. It has 3 methods ...
CCG's user avatar
  • 183
15 votes
5 answers
5k views

Pass object twice to same method or consolidate with combined interface?

I have a method that creates a data file after talking to a digital board: CreateDataFile(IFileAccess boardFileAccess, IMeasurer boardMeasurer) Here boardFileAccess and boardMeasurer are the same ...
pavuxun's user avatar
  • 281
4 votes
3 answers
2k views

Best way to provide configuration parameters for objects far away from the starting point

We are developing complex application on the top of the ROS framework in C++ and recently ran into discussion how to provide parameters to the parts of code far away from the starting main(). The ...
h22's user avatar
  • 937
2 votes
0 answers
459 views

How to handle a large number of optional parameters

I am currently developing on a small library allowing to read and write Java .properties files while retaining all the formatting (comments, whitespace, etc.): https://github.com/hupfdule/apron This ...
radlan's user avatar
  • 129
1 vote
2 answers
3k views

Pass-Through parameters in recursive code

When writing large amounts of recursive code (for valid reasons), I have come across many parameters that are not used in specific functions, but are still needed for a subset of all of the functions. ...
Yurihaia's user avatar
3 votes
3 answers
1k views

Java String substring() and StringBuilder delete() methods

I've noticed that some methods like the String's substring(int beginIndex, int endIndex) and StringBuilder's delete(int beginIndex, int endIndex), use the second parameter to signify that the ...
Steven Mcdonald's user avatar
1 vote
3 answers
429 views

When to use Parameters and When Not to C#

I am have an application using MVVM pattern. It takes a user ID and returns a table with the user's bookmarks. I am trying to decided if it is better practice to include parameters in my model's ...
Mwspencer's user avatar
  • 157
1 vote
3 answers
3k views

Setter with one parameter and null default value

Which solution is most logical? The value can be null, but when not null it must be a string. This (First): function setValue(string $value = null); To me this is bad; since we can now call the ...
Stefan's user avatar
  • 87
43 votes
7 answers
6k views

Is using parameter names that differ from type names only by casing considered a bad practice in C#?

I see questions similar to this with regards to parameter names that match properties on the class, but I can't find anything regarding using a parameter name that is the same as the parameter type ...
Jason Tyler's user avatar
33 votes
3 answers
18k views

Optional parameters or overloaded constructors

I am implementing a DelegateCommand, and when I was about to implement the constructor(s), I came up with the following two design choices: 1: Having multiple overloaded constructors public ...
user avatar
9 votes
2 answers
4k views

Is "too many parameters" a visual or a logical issue?

according to Are there guidelines on how many parameters a function should accept?, a method should not have too many parameters. However, some answers suggest this issue can be solved by builder ...
ocomfd's user avatar
  • 5,712
1 vote
1 answer
556 views

Setting a parameter to null with two-parametered interface method

I have a couple of classes that are doing the same thing: filling a series of object using data sources passed as a parameter. As I need two distinct of them, my interface holds the following contract:...
Yassine Badache's user avatar
1 vote
1 answer
526 views

Can you explain the behavior of PHP in cases when a parent class variable is masked by the child variable of the same name? [closed]

See the comment inside ChildEntity ::__construct(): class ChildEntity extends ParentEntity { /** @var int */ protected $classParameter; function __construct(int $classParameter) { ...
Dennis's user avatar
  • 8,247
39 votes
13 answers
13k 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 ...
ocomfd's user avatar
  • 5,712
3 votes
1 answer
254 views

Built-in type AND value checking of parameters?

Does any programming language have a concept of checking the type and value of a given parameter without adding an explicit if (myParam < 0) { .. } within the function? A pseudocode example: ...
Juha Untinen's user avatar
5 votes
6 answers
873 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: ...
ocomfd's user avatar
  • 5,712