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
2answers
100 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
118 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
67 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
136 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
171 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
209 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
424 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
360 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 ...
0
votes
3answers
1k 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
9k 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
1k 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
56 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
95 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
245 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
708 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
163 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
765 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
55 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
175 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
303 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
939 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
202 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
637 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
247 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
130 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
95 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;...
9
votes
2answers
6k 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
370 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
93 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
258 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: ...
4
votes
1answer
409 views

Making parameters required by using a function call as a default value in JavaScript

ECMAScript 6 introduced default parameters. The default value can be any expression, so you can use it to make a function throw an error when a parameter is not supplied: const mandatory = (name) =&...
1
vote
1answer
63 views

How to preserve parameter names when using bind to define new methods

I'm writing javascript object that wraps REST requests. For every operation on the server there is a method that accepts the parameters for the request and a callback that will receive the results. (...
208
votes
10answers
23k views

Is there a name for the (anti- ) pattern of passing parameters that will only be used several levels deep in the call chain?

I was trying to find alternatives to the use of global variable in some legacy code. But this question is not about the technical alternatives, I'm mainly concerned about the terminology. The ...
4
votes
2answers
2k views

REST Webservices (post / put) : which type of parameter should I choose, and when?

On a POST (or PUT) webservice, I know can use three different type of parameters, I can send my parameters in the path of the URL /objects/{path_param}, after a question mark in the URL /objects?{...
-2
votes
1answer
1k views

Global variable or parameter?

Is it correct that homeitem should be declared inside the OnLoad method and overgiven to all the render methods instead of just declaring it as a global variable and accessing it by all the render ...
0
votes
3answers
1k views

Is it bad practice to ignore some parameters while implementing a method of a interface?

Should an interface method implemented by a class always use all parameters? By interface I do not necessarily mean actual interfaces, these could be other (abstract) classes which are extended, too. ...
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 ...
3
votes
1answer
138 views

How full pass-by-name is implemented?

When you consider Scala and its pass-by-name you could (if I am not mistaken) pack the argument to lambda and pass it by value to the function. Internally the function would use pass-by-name parameter ...
4
votes
1answer
4k views

Does a message in a UML sequence diagram have parameters or arguments? [duplicate]

I recently took an exam for the introductory course on Computer Science. One question was about sequence diagrams (very simple example, boiled down to its essentials): The Bank object sends a ...
0
votes
2answers
175 views

Is it bad practice to verify arguments passed to a function? [duplicate]

I find myself writing a lot of functions whereby the first few lines "verify" the arguments, that is, they typecast, check falseness, range, etc. before doing any work. The main reasoning for this is ...
10
votes
2answers
591 views

Is it bad to create classes whose sole purpose is to be converted to another class implicitly?

Imagine a situation where we're using a library that allows you to create Circle objects, where you can specify the radius and the center of the circle to define it. However, for some reason, it also ...
-2
votes
2answers
421 views

Java Ellipses Signature for Multiple Parmeters

Firstly, I am studying function with new type of signature and body, and in this code, I want to know, what type of object is values? It doesn't appear to be an array of strings based on my ...
5
votes
2answers
2k views

Unused function parameters and polymorphism

I had a discussion with a co-worker about interface members having parameters that some implementations don't use. Say I have an interface interface IDoctor { string GetMedicalOpinion(Age age, ...
7
votes
3answers
6k views

In C++, why shouldn't all function parameters be references?

I am currently learning C++ from the C++ Primer 5th edition. The book's chapter on functions states that only large objects (large being relative as standard library strings count, but "primitive ...