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.

learn more… | top users | synonyms

1
vote
3answers
92 views

When is an object passed to a function?

Trying to clearly state the semantics of a function call. In calling a function, are the arguments passed to the function the ones the calling code initially gives or the ones the function ...
2
votes
1answer
39 views

Should I be taking these as arguments or define them in a sub class?

So I am making a mario clone in pygame and I have a base class Character and two sub classes, Mario and Luigi. The methods that the Character class defines require a significant amount of attributes ...
0
votes
0answers
17 views

Should a SPA have a route URL visible in address bar?

I am developing a Angular SPA using angular-ui-route. We are in a confusion of should we have the route visible for User in the address bar or just have index.html (or home page) always ? Is there a ...
21
votes
6answers
3k views

Should a method be forgiving with the arguments that are passed in? [closed]

Suppose we have a method foo(String bar) that only operates on strings that meet certain criteria; for example, it must be lowercase, must not be empty or have only whitespace, and must match the ...
15
votes
4answers
2k views

Why does C# have both out and ref?

C# has the out and ref keywords. Why are these two required? Disclaimer: I don't have deep knowledge of C#.
2
votes
2answers
40 views

How to handle large number of configuration parameters across a program conceptually?

Imagine a software system where you have like 100 parameters, each of which is sensible to change (in my case this is a reasearch system for machine learning). The obvious solution is to store all ...
5
votes
2answers
151 views

Identifier vs domain object as a method parameter

Are there any objective arguments for or against using objects vs unique ID as method/function parameters? (and members of other objects?). Specially in the context of statically typed languages ...
36
votes
2answers
2k views

Why do methods that take an unlimited amount of parameters often define overloads with fewer parameters?

For instance, the System.IO.Path.Combine method in .NET has the following overloads: Combine(params String[]) Combine(String, String) Combine(String, String, String) Combine(String, String, String, ...
4
votes
3answers
88 views

Sets of pair parameters

I have the following class, this class like many rely one parameters coming in as a pair. Originally for convenience, I set them as params Object[] values and check if there is an even number of them ...
2
votes
3answers
304 views

What is the difference between a variable and a parameter? [closed]

Its a conceptual question. But I would like to use the right term at the right place. That is why I would like to read some other views on this.
13
votes
3answers
674 views

What is the difference between ref and out in runtime?

C# provides the ref and the out keyword to make arguments to be passed by reference. The semantic of the two is very similar. The only difference is in the initialization of the flaged variable: ref ...
3
votes
2answers
114 views

Strategies for parameter wrapping

Methods with many parameters are often sometimes unavoidable. In my own experience I often find this is the case for program entry points and complex mathematical procedures - where refactoring is ...
4
votes
1answer
70 views

Should I use exceptions to control the range of parameters in Python?

For example for the following method signature: def genClusters(n_clusters, n_nodes, cluster_distribution): n_clusters should be an integer of more than 1. n_nodes should be an integer of more ...
0
votes
3answers
195 views

Understanding the concept of “arguments” and “parameters”

In the third last paragraph at page number 26 of the ebook "The C Programming Language" the author(s) say, "We will generally use parameter for a variable named in the parenthesized list in a ...
1
vote
1answer
274 views

OOP best practice: Optional referenced-type paremeter

I know in C#, by default, referenced type variables are passed by reference to a method. I have a function which sometimes I just need its return value and sometimes both return value and the changes ...
6
votes
3answers
351 views

Passing parameters that need to be copied by value or const reference

I have a basic (mathematical) vector class, which in my opinion benefits from C++'s operator overloading. Vector-scalar operations are defined as self-modifying functions in the class itself, class ...
3
votes
3answers
2k views

Best OOP Practice in C#: Passing the object as parameter VS creating a new instance of the object

First things first, I would like to know if passing an object as parameter is much better than creating another object AGAIN in a class that will use it again and second what are the pros and cons of ...
38
votes
9answers
6k views

Should I accept empty collections in my methods that iterate over them?

I have a method where all logic is performed inside a foreach loop that iterates over the method's parameter: public IEnumerable<TransformedNode> TransformNodes(IEnumerable<Node> nodes) { ...
3
votes
2answers
196 views

Defensive copy in the client class or in the service class?

I have one service method that receive parameters as a Map. I will need to add new attributes to this map inside the service. If I pass the original Map object to the parameter instead of a copy, the ...
0
votes
1answer
131 views

Method Parameters Ordering [closed]

I was recently changing a method to add in an additional parameter, and I couldn't help but wonder if there were "best practices" or "generally accepted rules" in deciding what order parameters of a ...
0
votes
2answers
134 views

Is there a way for Object 1 to call Object 2's enums in a function call?

For example, if I have two classes "Director" and "Follower". I want the Director to tell the follower where to go (ex: follower1.go(direction.LEFT)), and I want the Director to know what directions ...
2
votes
3answers
121 views

Is there a name for the technique of converting method parameters into a unified form to simplify further processing? [closed]

When working with methods which accept a parameter in various forms (e.g. nil, a single string, a single string containing multiple data or an array of strings) I tend to unify them - splitting, ...
3
votes
4answers
329 views

Is a long list of parameter checks an anti-pattern?

Background: I'm working on an application that will manage backup generators. These generators need to be able to be "linked" together. For example, Generator B might serve as a backup for ...
14
votes
7answers
2k views

Function only returns unchanged parameter, useless?

I just found this function in the project I'm working at: -- Just returns the text unchanged. -- Note: <text> may be nil, function must return nil in that case! function Widget:wtr(text) ...
3
votes
2answers
192 views

Should I throw guard exceptions that will be thrown by internal methods anyway? [duplicate]

I have some fairly simple code (C#): /// <summary> /// Truncates a string to a maximum length. /// </summary> /// <param name="value"> The string to truncate. ...
3
votes
2answers
373 views

Parameterized Java Types (Generics)

Consider this "legacy" code: public interface IPersistentCollection { IPersistentCollection cons(Object o); } Genericized in Java, it could become something like this: public interface ...
0
votes
1answer
151 views

Good practice to pass this information through URL parameter

Basically, let's suppose an application that manage some user's meetings. I have a filtering zone on a page that aims to specify the category of items I need to specifically return. ...
1
vote
1answer
105 views

Replaceable parameter syntax meaning

Replaceable parameter syntax for the console object in C#. I am taking the O'Reilly C# Course 1 and it is asking for a replaceable parameter syntax and it is not very clear on what that means. ...
4
votes
6answers
903 views

Is it bad practice to resolve null arguments to default static variables?

First, let me show you an example (written in ActionScript 3.0): class GameObject { public static function MakeFromName( pName:String, pAtlas:TextureAtlas ...
1
vote
3answers
445 views

Setting global parameters: is this a reasonable use of const_cast and volatile?

I have a program that I run repeatedly with various parameter sets. Different parameters are used in different parts of the program (including different source files). The same parameter may also be ...
0
votes
1answer
102 views

Constructors, Ignore Arguments

Is it possible to have a constructor in a class, that you can ignore certain arguments/parameters? For example, I have this constructor Car(color, make, model, wheels, type, doors) Could I call ...
30
votes
9answers
3k views

How to name a method that both performs a task and returns a boolean as a status?

If there is a method bool DoStuff() { try { // doing stuff... return true; } catch (SomeSpecificException ex) { return false; } } should it rather be called ...
1
vote
1answer
452 views

Should I omit the parameter “e” when using EventHandler<EventArgs>?

Whenever I am defining my own events, I use a pattern such as the following (which I believe is how the MSDN recommends doing it): public class MyEventClass { private bool _value; // Backing ...
0
votes
2answers
300 views

Design Pattern: Algorithm varies according to the input arguments

I will give a simple example to help you understand my question. Suppose we have a rectangle and a Utility class with a method that creates a buffer arround a shape. The .createBuffer method has ...
0
votes
1answer
598 views

How to encapsulate method parameters in Java?

An HTTP query can be parametrized to a list of pairs like name=value that can be encapsulated in general as Map<String, String> since an HTTP GET query is string pairs. I could need something ...
1
vote
2answers
296 views

How to deliver 3 different parameters to class in one method (2 of 3 are optional)

I need your help how to implement it nice and well. It's quite a simple problem. I can solve it but I need help on how to do that better. My class has logic working using three parameters. It gets ...
3
votes
2answers
138 views

Inform caller or just let them deal with exception?

I'm not sure how to proceed in the following situation. say we have a function as so: def runsATask(codes): myDicts = [helperFunc(code) for code in codes] for item in myDicts: # some ...
17
votes
3answers
2k views

Why not annotate function parameters?

To make this question answerable, let's assume that the cost of ambiguity in the mind of a programmer is much more expensive then a few extra keystrokes. Given that, why would I allow my teammates to ...
0
votes
4answers
130 views

Understanding parameters

I have read this statement: "A parameter is used as a sort of temporary messenger, carrying data originating from outside the constructor or method and making it available inside it." So, does that ...
3
votes
3answers
699 views

Is it better to have constructors with or without parameters?

Is it better to have constructors with or without parameters and why? public NewClass( String a, String b, int c) throws IOException { //something } OR public NewClass() { //something } ...
5
votes
2answers
4k views

Ruby - when to use instance variables vs parameters between methods?

I'm writing several methods that call other methods. To pass the information I have a couple of choices: Pass the information as parameters Set instance variables so that other methods can access ...
13
votes
5answers
5k views

Multiple arguments in function call vs single array

I have a function that takes in a set of parameters, then applies to them as conditions to an SQL query. However, while I favored a single argument array containing the conditions themselves: ...
2
votes
1answer
292 views

Best practices for refactoring parameter file structure in multiple environments

Background info and what I've tried Within each of two mostly distinct environments, say 'Research' and 'Production', there is a need for a structured parameter file. The file contains things like ...
6
votes
6answers
450 views

Fields vs method arguments [closed]

I just started writing some new class and it occurred to me that I was adding a lot of method arguments that are not strictly needed. This is following a habit to avoid having state in classes that is ...
0
votes
2answers
197 views

Factory for arrays of objects in python

Ok, the title might be a little misleading. I have a Window class that draws widgets inside itself in the constructor. The widgets are all of the same type. So I pass a list of dictionaries, which ...
5
votes
7answers
2k views

Passing an object into a method which changes the object, is it a common (anti-) pattern?

I am reading about common code smells in Martin Fowler's Refactoring book. In that context, I was wondering about a pattern I am seeing in a code base, and wether one could objectively consider it an ...
2
votes
3answers
3k views

UML representation of type being passed as a parameter

I want to draw a UML diagram of my program. Class Barney has a method Yabadaba(Doo d) which takes a parameter of type Doo. How do I represent that class Doo is used in class Barney in my UML diagram? ...
0
votes
1answer
148 views

Overloading to support multiple related types (especially pointers)

Problem I was just trying to debug a set of file-manipulation routines I wrote for a program I am working on. One of them kept returning an INVALID_HANDLE error. Explanation I figured out what the ...
0
votes
1answer
296 views

Generic params table design

We have a generic parameter table whose important attributes are : id number auto increment not null domain varchar (200) not null classification varchar (200) not null param_name varchar (200) not ...