Is “pass by reference” bad design? [closed]

Object-oriented programming is done best if you structure your code into clean, understandable abstractions. Numbers, as an abstraction, are immutable and have no identity (i.e. a “five” is always a “five” and there is no such thing as “multiple instances of five”). What you’re trying to invent is a “mutable number” which is mutable and … Read more

Pass empty variable in bash

On the first case you call the script with testFunct param2. Hence, it understands param2 as the first parameter. It is always recommendable to pass parameters within quotes to avoid this (and to be honest, for me it is cleaner this way). So you can call it testFunct “$param1” “$param2” So to pass an empty … Read more

How to pass arguments to the __code__ of a function?

I am completely against this use of __code__. Although I am a curious person, and this is what someone theoretically could do: code # This is your code object that you want to execute def new_func(eggs): pass new_func.__code__ = code new_func(‘eggs’) Again, I never want to see this used, ever. You might want to look … Read more

Optional argument in PL/pgSQL function

Since PostgreSQL 8.4 (which you seem to be running), there are default values for function parameters. If you put your parameter last and provide a default, you can simply omit it from the call: CREATE OR REPLACE FUNCTION foofunc(_param1 integer , _param2 date , _ids int[] DEFAULT ‘{}’) RETURNS SETOF foobar — declare return type! … Read more

Java pass by reference

Java always passes arguments by value NOT by reference. Let me explain this through an example: public class Main { public static void main(String[] args) { Foo f = new Foo(“f”); changeReference(f); // It won’t change the reference! modifyReference(f); // It will modify the object that the reference variable “f” refers to! } public static … Read more

How are C++11 lambdas represented and passed?

Disclaimer: my answer is somewhat simplified compared to the reality (I put some details aside) but the big picture is here. Also, the Standard does not fully specify how lambdas or std::function must be implemented internally (the implementation has some freedom) so, like any discussion on implementation details, your compiler may or may not do … Read more