Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
0answers
151 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
156 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
217 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
355 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
385 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 ...
27
votes
3answers
6k 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 ...
7
votes
2answers
746 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 ...
0
votes
0answers
103 views

How to implement strategy pattern in context of few key elements on every page?

This is my concern: I need to generate content for <title> <h1> and <meta name="description"> tags, that will affect ~ 100 000 pages. Basically, it is a SEO optimization. ...
1
vote
1answer
55 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
92 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
9k 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
244 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
692 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
158 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
633 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
52 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
156 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
2k 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
280 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
606 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
241 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
195 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
493 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
827 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
220 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
119 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;...
6
votes
2answers
3k 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
216 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
215 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
342 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
61 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. (...
205
votes
10answers
22k 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
416 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
952 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
934 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
1k 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
135 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
3k 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
173 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
585 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
331 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
1k 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
4k 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 ...
49
votes
10answers
8k views

Should we avoid custom objects as parameters?

Suppose I have a custom object, Student: public class Student{ public int _id; public String name; public int age; public float score; } And a class, Window, that is used to show ...
0
votes
1answer
164 views

How to handle extra arguments in a JavaScript library?

JavaScript is the only language I've come aross which allows variable-length argument lists by default. A case where it would be helpful to detect too many arguments would be Mozilla's Add-On SDK's ...
5
votes
2answers
455 views

Clean code deep parameter pass

So Clean Code says you should separate each task to a single function (and add these functions a correct name). I like the idea, but I've faced this problem so far: you receive a parameter which you ...
0
votes
1answer
68 views

Execution of cmd over SSH

In my current architecture, I connect from my local script to a server in SSH, and execute a .sh script. The purpose of the script is to execute an SQL query and to output the result in a file. My ....