Skip to main content

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
-3 votes
1 answer
185 views

Is there a name for this anti-pattern? A reference to a class member is being passed to another class method, rather than having the class method set the class member directly. public class ...
Jeff Roe's user avatar
0 votes
2 answers
160 views

I’m designing a system where various “handlers” apply business rules to an object. Initially I had each handler receive the full domain object: // A large domain object with many properties and ...
nicke7117's user avatar
10 votes
7 answers
3k views

In the Python code base we inherited there are several functions that check parameter types and try to "accommodate" different types. Example: def process_data(arg): json_ = {} if ...
oliver's user avatar
  • 229
7 votes
8 answers
946 views

According to Is it wrong to use a boolean parameter to determine behavior?, I know using boolean parameters to decide the behaviour is bad, for example, when using boolean parameters as the following: ...
wcminipgasker2023's user avatar
3 votes
5 answers
815 views

According to Why should I use dependency injection?, "dependency injection" has some advantages, for example: "Non dependency injection" version: public class Client{ private ...
wcminipgasker2023's user avatar
12 votes
5 answers
4k views

According to https://softwareengineering.stackexchange.com/a/200092, as I know, "preserve whole object" is a refactor method that passes the whole object instead of required parameters only, ...
wcminipgasker2023's user avatar
7 votes
8 answers
5k views

According to Should we avoid custom objects as parameters?, I know I can group related parameters to improve readability of the function, eg: Original version: public void showSchedule(long startDate,...
wcminipgasker2023's user avatar
17 votes
8 answers
5k views

When is it better to pass data to a function in a parameter, and when is it better for the function to just fetch the data itself? Here's some simplified examples in PowerShell: Option 1 (give the ...
Nova's user avatar
  • 181
0 votes
1 answer
245 views

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
180 views

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
254 views

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
804 views

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
121 views

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
3k views

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
1k views

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

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,529
5 votes
2 answers
735 views

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
2k views

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
1k views

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
  • 346
0 votes
5 answers
341 views

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
  • 516
2 votes
2 answers
647 views

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,308
14 votes
14 answers
8k views

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

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
132 views

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
  • 281
3 votes
3 answers
2k views

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
668 views

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
279 views

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
500 views

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
269 views

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
64 views

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
56 views

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
326 views

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
2k views

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
459 views

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
2k views

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
3k views

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
12k views

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
4k views

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
  • 669
2 votes
2 answers
232 views

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
659 views

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
  • 516
2 votes
2 answers
227 views

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 copying ...
user342634's user avatar
1 vote
3 answers
151 views

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,267
-2 votes
1 answer
110 views

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
  • 193
15 votes
5 answers
5k views

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
5 votes
3 answers
3k views

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
  • 966
2 votes
0 answers
506 views

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

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
2k views

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
511 views

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
4k views

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