today I’ve a design question, to have an easy to read code.
Should we mark a call by reference function?
Because when a new programmer see this line
funkyName($funkyVar);
he might think “oh, whats happen here? a function but it actually does nothing further, no assignments or anything else. I should delete it to keep the code clean…”
OK, this is hard! But it happens 😉
So, should we mark the function, are there ideas in the past? Maybee in other languages than PHP?
Or do you think call by reference sucks. And we should only do this on large datasets for performance reason?
I’m looking forward to your comments, netzaffin
In C and C++, a const-correct program will mark arguments to functions which do not effect changes upon them with
constas in:Which is a function which accepts a
voidpointer, whose value cannot be changed, and which points to memory which also cannot be changed.Therefore you can be assured calling this function and passing it memory, that the memory will not be changed.
C++’s
const_castkind of rains on this parade — allowing you to break const-correctness — but the concept (and general rule) remains.