A
Aaron Watters
Hi. I've been teaching C# and I'm tired of students
telling me that they passed ints by ref when they don't
need to because it's "more efficient". I've seen this myth
repeated in many textbooks, but it's completely wrong
in C# (and it's always wrong for ints in any language).
In the case of C++ if you are passing arrays (if I recall)
it can be pretty important to pass by ref and not by
value because otherwise the whole (3GB) array gets
copied onto the call stack.
However, in the case of C# all arrays
are reference types, so you always actually copy a
reference to the array object even if you don't say "ref",
so there is no imperative to pass by ref unless you want
to change the binding of the variable naming the array.
For all common value types the size of a reference to the
value is about the same size as the size of the value itself,
and you are adding an additional level of indirection
-- so you are not saving anything in space or time by passing
by ref when you don't have to.
The only exception is "structs" which can hypothetically
be large, but they are only used for special purposes
and should be avoided in most vanilla programming.
Please correct me if I'm wrong, or if not, please
*stop* *confusing* *my* *students* who should always
pass by value unless it's absolutely necessary to pass
by ref.
Annoyed: -- Aaron (Stagnant) Watters
===
http://www.xfeedme.com/nucular/gut.py/go?FREETEXT=immoral+english
telling me that they passed ints by ref when they don't
need to because it's "more efficient". I've seen this myth
repeated in many textbooks, but it's completely wrong
in C# (and it's always wrong for ints in any language).
In the case of C++ if you are passing arrays (if I recall)
it can be pretty important to pass by ref and not by
value because otherwise the whole (3GB) array gets
copied onto the call stack.
However, in the case of C# all arrays
are reference types, so you always actually copy a
reference to the array object even if you don't say "ref",
so there is no imperative to pass by ref unless you want
to change the binding of the variable naming the array.
For all common value types the size of a reference to the
value is about the same size as the size of the value itself,
and you are adding an additional level of indirection
-- so you are not saving anything in space or time by passing
by ref when you don't have to.
The only exception is "structs" which can hypothetically
be large, but they are only used for special purposes
and should be avoided in most vanilla programming.
Please correct me if I'm wrong, or if not, please
*stop* *confusing* *my* *students* who should always
pass by value unless it's absolutely necessary to pass
by ref.
Annoyed: -- Aaron (Stagnant) Watters
===
http://www.xfeedme.com/nucular/gut.py/go?FREETEXT=immoral+english