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
2
votes
2answers
74 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 ...
-5
votes
0answers
48 views

Parameters optimization role in industry or academia?

I have a question about the role/advantages of parameters optimization in various domains? For example, if we have to work on ML algorithms, so if we optimize the parameters of these ML algorithms via ...
-2
votes
1answer
77 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 ...
-3
votes
2answers
39 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 ...
-3
votes
1answer
39 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
0
votes
3answers
148 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-...
0
votes
1answer
73 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 ...
1
vote
2answers
88 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 ...
7
votes
4answers
681 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 ...
1
vote
2answers
160 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 ...
3
votes
3answers
448 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 ...
0
votes
8answers
1k 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 ...
2
votes
2answers
174 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 ...
2
votes
2answers
85 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, ...
2
votes
2answers
130 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 ...
1
vote
3answers
129 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 ...
-2
votes
1answer
71 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 ...
15
votes
5answers
4k 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 ...
2
votes
2answers
150 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 ...
2
votes
0answers
207 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 ...
1
vote
2answers
691 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. ...
2
votes
3answers
614 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 ...
1
vote
3answers
384 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 ...
1
vote
3answers
2k 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 ...
43
votes
7answers
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 ...
28
votes
3answers
12k 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 ...
8
votes
2answers
2k 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 ...
1
vote
1answer
57 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:...
1
vote
1answer
98 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) { ...
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 ...
3
votes
1answer
247 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: ...
5
votes
6answers
735 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: ...
0
votes
1answer
167 views

How to best pass along global configurations such as login data?

I have a code base consisting of multiple scripts and many functions. Everything is controlled from one master script (master.txt, let's say). I have a lot of "global" configuration files, for ...
0
votes
3answers
1k views

Why are no parameters better than few parameter methods?

In Clean Code, Robert C. Martin states that no parameter methods are better than those with very few parameters. I'm kind of confused as no parameter methods are usually harder to unit test and tend ...
0
votes
0answers
59 views

Is making method parameters final a worthy endeavour? [duplicate]

It is generally a good idea to restrict access to your variables as much as reasonably possible. For example make things private instead of publicand make variables final if they aren't supposed to ...
-1
votes
1answer
189 views

Enable access to objects via Introduce Parameter Object or interface

I am working with multiple commands that are executed in order (and possibly have sub commands as well) which can be desribed like this: interface ICommand { void Execute(); } abstract class ...
0
votes
1answer
3k views

Object constructors with dynamic parameter lists

I had a quick question and I was hoping someone could help me figure this out. I'm new to Java and I'm trying to learn about classes and objects and I see you can call parameters in the constructor of ...
1
vote
3answers
318 views

Is “pass objects instead of required variables only” contradict with “avoid global variables”?

As I know, on one hand, the main stream opinion about global variable is, it is eval because it may make the program unpredictable : some unknown class or functions can change the value of the global ...
1
vote
2answers
2k views

Best practices for storing c++ program parameters

I'm currently developing a project which has multiple c++ programs communicating over IPC to each other. Each of these programs will rely on some parameters to run and these may be common to several ...
0
votes
3answers
244 views

Should a function which takes dimensions/coordinates take them as multiple parameters, or one object? [duplicate]

I'm mainly thinking of x,y coordinates but I guess 3D coordinates and higher also apply. Let's say I'm writing a function to return the center of a rectangle given its width and height. Which is the ...
1
vote
2answers
212 views

Declaring a function without named parameters that accepts at least 1 argument

Say I have a function whose first parameter is used differently depending on how many arguments are passed. In this case, it is easier to just process the arguments object as a whole within the ...
5
votes
3answers
732 views

Should parameters of a method be in the same namespace as the class?

Suppose you have this: namespace Project.Services { public class ClientService { public IEnumerable<Clients> Query(Project.Models.Builders.ClientQueryBuilder builder) { ...
2
votes
6answers
1k views

How to avoid changing the signature on a well-used method?

The Existing Code I have a C# project with about 45000 lines of code. It has a utility/helper class which contains static methods which make it easier for my code to work with PDFSharp/Migradoc to ...
1
vote
5answers
289 views

Dedicated method vs method with parameter

Suppose we've a permissionManager which tell us if user has some privileges to some action or not. We've quite a lot of them(dozen, maybe more). I see two ways to implement checks for a user, like a: ...
0
votes
1answer
160 views

What kind of parameter coupling is the least taxing for the caller when data needs to be mapped?

I'm creating a math library that will deal with points as function inputs (as shown below). public struct Point { public int X; public int Y; } public static class MyLib { public static float ...
0
votes
2answers
96 views

Is there a common guideline for sending an entire object as an argument versus just sending relevant properties?

Let's say I have a Person class: class Person { public string FirstName { get; set; } public string LastName { get; set; } public string IdCard { get; set; } public string Phone { get;...
10
votes
2answers
9k views

Parametrize methods vs global variables

I have a very simple question that has been haunting me for a while when my code starts growing. Should parameters be replaced by global variables when they go through long routes of nested function ...
1
vote
1answer
501 views

Should callbacks be called with named or positional arguments?

The question is asked in the context of Python, but it is also relevant for any languages with named parameters support. If some entity in my code (e.g. a pubsub implementation) or even a simple ...
4
votes
1answer
98 views

After assigning a parameter to a field, use the parameter or the field?

If I have a method that receives a value as parameter and stores it in a field for later usage, but then goes on to use that value - why would I use the parameter instead of the field? private ...
3
votes
1answer
275 views

Is it an anti-pattern for Swift functions that take in a sender to have a label for that parameter?

This is something I see all over Cocoa: func someAction(_ sender: Any) which is called like: someAction(someObject) This can be very confusing to me. The infamous example is in NSView subclasses: ...