What is “pass-by-name” and how does it work exactly?

I found a good explanation at Pass-By-Name Parameter Passing. Essentially, the body of a function is interpreted at call time after textually substituting the actual parameters into the function body. In this sense the evaluation method is similar to that of C preprocessor macros. By substituting the actual parameters into the function body, the function … Read more

What does ** (double star/asterisk) and * (star/asterisk) do for parameters?

The *args and **kwargs is a common idiom to allow arbitrary number of arguments to functions as described in the section more on defining functions in the Python documentation. The *args will give you all function parameters as a tuple: The **kwargs will give you all keyword arguments except for those corresponding to a formal parameter as a dictionary. Both idioms can be mixed with normal arguments to … Read more

Is Java “pass-by-reference” or “pass-by-value”?

Java is always pass-by-value. Unfortunately, when we deal with objects we are really dealing with object-handles called references which are passed-by-value as well. This terminology and semantics easily confuse many beginners. It goes like this: In the example above aDog.getName() will still return “Max”. The value aDog within main is not changed in the function foo with the Dog “Fifi” as the object reference is passed by value. If it … Read more