arguments

PowerShell - How do I pass string parameters correctly?

Is there documentation or an article on the rules for passing strings into PowerShell functions? I just trying to do some string concatenation/formatting, but it's putting all the parameters into the first placeholder. Code function CreateAppPoolScript([string]$AppPoolName, [string]$AppPoolUser, [string]$AppPoolPass) { # Command to...

Passing switches to Xcode 3.1 user scripts

I have a user script that would be much more useful if it could dynamically change some of its execution dependent on what the user wanted. Passing simple switches would easily solve this problem but I don't see any way to do it. I also tried embedding a keyword in the script name, but Xcode copies the script to a guid-looking filename...

Is there a difference between foo(void) and foo() in C++ or C

Consider these two function definitions void foo(){} void foo(void){} Is there any difference between these two? If not, why is the void argument there? Aesthetic reasons? ...

What is the design pattern for processing command line arguments

If you are writing a program that is executable from the command line, you often want to offer the user several options or flags, along with possibly more than one argument. I have stumbled my way through this many times, but is there some sort of design pattern for looping through args and spinning off the appropriate functions? Consid...

C++ Passing Options To Executable

How do you pass options to an executable? Is there an easier way than making the options boolean arguments? EDIT: The last two answers have suggested using arguments. I know I can code a workable solution like that, but I'd rather have them be options. EDIT2: Per requests for clarification, I'll use this simple example: It's fairly ...

How can I pass an argument to a C# plug-in being loaded through Assembly.CreateInstance?

What I have now (which successfully loads the plug-in) is this: Assembly myDLL = Assembly.LoadFrom("my.dll"); IMyClass myPluginObject = myDLL.CreateInstance("MyCorp.IMyClass") as IMyClass; This only works for a class that has a constructor with no arguments. How do I pass in an argument to a constructor? ...

Is there a better way to do optional function parameters in Javascript?

I've always handled optional parameters in Javascript like this: function myFunc(requiredArg, optionalArg){ optionalArg = optionalArg || 'defaultValue'; //do stuff } Is there a better way to do it? Are there any cases where using || like that is going to fail? ...

Is there a way to handle a variable number of parameters in a template class?

I have a set of callback classes that I use for handling callbacks with variable numbers of parameters. Right now I have about 6 different instances of it to handle differing numbers of arguments. Is there a way to make one instance than can handle a variable number of arguments?? Ultimately I would love to have each parameter be a POD t...

What's the difference between an argument and a parameter?

When verbally talking about methods in C# during a code review or in pairing I'm never sure whether to use the word argument or parameter or something else. Either way the other people know what I mean but what's correct and what's the history of the terms? Would people use different terms in different languages? For the record I'm sel...

Customized command line parsing in Python

I'm writing a shell for a project of mine, which by design parses commands that looks like this: COMMAND_NAME ARG1="Long Value" ARG2=123 [email protected] My problem is that Python's command line parsing libraries (getopt and optparse) forces me to use '-' or '--' in front of the arguments. This behavior doesn't match my requirements. An...

Is there a way to pass arguments to a query in CodeIgniter *without* using ActiveRecord?

This is what I'd like to do, but it doesn't seem possible: (edit: changed single to double quotes) function get_archives($limit, $offset) { $query = $this->db->query(" SELECT archivalie.id, archivalie.signature, type_of_source.description AS type_of_source_description, med...

How do I parse command line arguments in bash?

Say I have a script that gets called with this line: ./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile or this one: ./myscript -v -f -d -o /fizz/someOtherFile ./foo/bar/someFile What's the accepted way of parsing this such that in each case (or some combination of the two) $v $f $d will all be set to true and $outFile will ...

Can you list the keyword arguments a Python function receives?

I have a dict, which I need to pass key/values as keyword arguments.. For example.. d_args = {'kw1': 'value1', 'kw2': 'value2'} example(**d_args) This works fine, but if there are values in the d_args dict that are not accepted by the example function, it obviously dies.. Say, if the example function is defined as def example(kw2): T...

Should I make sure arguments aren't null before using them in a function.

The title may not really explain what I'm really trying to get at, couldn't really think of a way to describe what I mean. I was wondering if it is good practice to check the arguments that a function accepts for nulls or empty before using them. I have this function which just wraps some hash creation like so. Public Shared Function G...

Passing a Class Object to a function (probably by pointer not reference) C++

So let's say I have two different functions. One is a part of the BST class, one is just a helper function that will call on that Class function. I will list them out here. sieve(BST<T>* t, int n); this function is called like this: sieve(t,n) the object is called BST t; I'm going to be using the class remove function within the...

Supplying an argument at Rails runtime

I'm looking for a way to supply an argument to a ruby on rails project at runtime. Essentially, our project uses public key cryptography to encrypt some sensitive client data and we want the ability to supply the password to the private key file at runtime. ...

Which exception should I raise on bad/illegal argument combinations in Python?

I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so: def import_to_orm(name, save=False, recurse=False): """ :param name: Name of some external entity to import. :param save: Save the ORM object before returning. ...

C++ compiler optimization of passed arguments

I'm using a logging module that can have reporting enabled/disabled at runtime. Calls generally go something like: WARN( "Danger Will Robinson! There are " + boost::lexical_cast<string>(minutes) + " minutes of oxygen left!" ); I'm using an inline function for WARN, but I'm curious as to how much optimization is going on...

unpacking an array of arguments in php

Python provides the "*" operator for unpacking a list of tuples and giving them to a function as arguments, like so: args = [3, 6] range(*args) # call with arguments unpacked from a list This is equivalent to: range(3, 6) Does anyone know if there is a way to achieve this in PHP? Some googling for variations of "PHP Unpa...

Generic list manipulation function in C?

What is a generic list manipulation function in C? (I saw this when I was going through some materials.) What is the difference between this function and a function which can accept elements of any kind? Are they same...? How can we implement them individually if they are not same? ...