Thursday, July 19, 2012
At What point should you understand References
Understanding the difference between reference semantics and value semantics is crucial. It is fundamental to the design of the language and the type system. Understanding that references can be implemented with pointers is not particularly relevant for entry-level programmers; understanding the difference between copying by reference and copying by value is highly relevant. or that this question is not a real judge of ability.
Well that depends on what ability you were attempting to test. If the ability to rapidly and accurately predict the behaviour of trivial programs is relevant to your job then I'd say that it is a good test of ability.
If the abilities to determine when there's not enough information given to solve the problem, and to ask the right questions to elicit that information, are relevant, then yes, this is a judge of relevant abilities. (A good candidate would ask to see the implementations of type myObject and member Value rather than assuming that my Object is a class and Value is a mutable property of type string.)
I say that all those abilities are relevant, and that this is a reasonable first question for an entry-level position.Even if you don't use pointers and unsafe code, you definitely should understand the concept and know how to use it.
If you're gonna work in, I can forgive not knowing pointer arithmetic, because you most likely won't use it and most likely shouldn't use it.But pointers exist all around us even in the managed world.
string s = "abc"
int a = 3;
One of these two variables, is actually a pointer (Reference. Whatever. Same thing). Which one? Honestly, A person who doesn't know that needs to go get a job using C for a year, after that he'll understand this for sure.
Imagine this bloke having to write a function that takes a ref string. It is:
Immutable.
A reference to an immutable object.
A reference to a reference to an immutable object. (The immutability has nothing to do with the pointers. It will just be even more confusing if it's immutable )
The man is going to go insane trying to figure that out if he didn't lose his pointer virginity in C beforehand. Or even worse, imagine some critical part of your code uses a Dictionary containing some valuable information in a class, and this guy changes one of it's values, which changes the GetHashValue of the object, and causes you to "lose" the instance.
Even if sane developers don't use explicit pointers in their code, that doesn't mean pointers are not used implicitly.
Every good programmer needs to understand exactly what does their language abstract away, otherwise he won't ever be able to understand the language properly. To do properly, you need to know C, and to do C properly, you need to know assembler.
Also, your question - For all you know, your interviewee assumed myObject is a struct. He most likely didn't, but still.
Edit: Yes, references are not fixed, unlike pointers. But conceptually there's really no difference.
Honestly, I graduated from the full suit of Microsoft Courses about 2 months ago. Admittedly, I have been programming for a while longer than that, But I would say in I have been going for about 2 years.
I know for a fact, That these questions came up several times during my study, And it was absolutely, 100% critical that everyone in the class knew this. Infact I would think that the Microsoft Exam even has a few of these mixed in with it.
From a student's point of view (Albeit, a high level students point of view), everyone should know this. And if they don't then they do not know enough core programming (Or logic) to make it far in programming.
As a side note, My current job had a small test in the second interview. They made me write an app to test Prime Numbers, Factorials, Write my own LastIndexOf and one other that I can't remember off the top of my head.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment