Prev: Templates rejected on non-dependent parameters before deduction in C++0X?
Next: Templates rejected on non-dependent parameters before deduction in C++0X?
From: PolarPeter on 10 Jun 2010 10:22 One of many questions I typically ask candidates who come to interview with me is this one: class A { public: A() : y(2), x(y * 2) {} ~A() {} private: int x; int y; }; int main() { A a; return 0; } I ask them what the value of a.x and a.y will be after 'a' has been constructed. Clearly, the issue here is that x is constructed first, and uses the uninitialized value of y. However, a lot of candidates miss the order issue, and think that a.y is 2, and a.x is 4. I think this question is pretty fundamental, given how often MILs are used. I think people who say they have 10+ years professional experience should be able either to see the issue, or at least talk through why it works the way it works if they don't initially see it but are then shown. I'd like to know what you think - is it reasonable to expect candidates who claim they have 10 years+ 'advanced' C++ experience to know this? Thank you for your time. Peter. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Hakusa on 10 Jun 2010 19:49 On Jun 10, 9:22 pm, PolarPeter <polarpeterb...(a)gmail.com> wrote: > class A > { > public: > A() : y(2), x(y * 2) {} > ~A() {} > > private: > int x; > int y; > > }; > I'd like to know what you think - is it reasonable to expect > candidates who claim they have 10 years+ 'advanced' C++ experience to > know this? I can't be an authority on that, but i can say that even if one didn't know about the order of initialization, the compiler should be able to warn about it. Compiling your example with g++ didn't produce a warning until i compiled with -Wall. So, in my mind, the question is not should a one know this, but is one able to use the compiler to identify the problem, even without being aware of such a problem. I wonder if many compile their programs without warnings because they find them annoying instead of helpful, but if because of that they couldn't find the problem, that's unacceptable, right? BTW: I've only been using C++ for two years, but this is something i know and feels pretty trite. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Martin B. on 10 Jun 2010 20:34 PolarPeter wrote: > One of many questions I typically ask candidates who come to interview > with me is this one: > > class A > { > public: > A() : y(2), x(y * 2) {} > ~A() {} > > private: > int x; > int y; > }; > > int main() > { > A a; > return 0; > } > > I ask them what the value of a.x and a.y will be after 'a' has been > constructed. > > Clearly, the issue here is that x is constructed first, and uses the > uninitialized value of y. However, a lot of candidates miss the order > issue, and think that a.y is 2, and a.x is 4. > Under MSVC 2005 this give the result of y=2 and x=4. (With Language extensions disabled and with /W4 which doesn't give any warnings.) The constructing order of the specific constructor is relevant, and *not* the declaration order of the members. (Or so I thought.) cheers, Martin -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: eca on 10 Jun 2010 20:34 On Jun 11, 3:22 am, PolarPeter <polarpeterb...(a)gmail.com> wrote: > I think this question is pretty fundamental, given how often MILs are > used. I think people who say they have 10+ years professional > experience should be able either to see the issue, or at least talk > through why it works the way it works if they don't initially see it > but are then shown. Personally, I think that people who say they have 10+ years professional experience in C++ should know how to keep far from quicksands. > I'd like to know what you think - is it reasonable to expect > candidates who claim they have 10 years+ 'advanced' C++ experience to > know this? > IMHO, it is reasonable to expect candidates to ask for whys and hows and find more maintainable, reasonable and robust solutions to the real problem (where any). C++ is not the land of enigmistics, for me it is the land of the variety of solutions. The value of a C++ experienced programmer/analyst is in his/her ability of finding, in the plethora of possible solutions, the most robust, *maintainable*, self-documenting and efficient one. I would not submit this kind of tests to experienced programmers. I prefer to estimate their attitude to teamwork and problem solving. Deep knowledge of C++ is important but not in terms of gotchas, rather in terms of acquaintance with bullet-proof practices and well-known traps and pitfalls - of course, taking an over-mean technical skill as granted. > Thank you for your time. Thank you for giving us the possibility of sharing our opinions on the subject. eca -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Nick Hounsome on 11 Jun 2010 07:35
On 11 June, 12:34, eca <enrico.ecam...(a)gmail.com> wrote: > On Jun 11, 3:22 am, PolarPeter <polarpeterb...(a)gmail.com> wrote: > > > I think this question is pretty fundamental, given how often MILs are > > used. I think people who say they have 10+ years professional > > experience should be able either to see the issue, or at least talk > > through why it works the way it works if they don't initially see it > > but are then shown. > > Personally, I think that people who say they have 10+ years > professional > experience in C++ should know how to keep far from quicksands. > I agree. A good C++ programmer just knows that "There be dragons" and avoids this sort of thing. You don't necessarily remember what sort of dragon or how it behaves you just know that it's a bad idea to go there. In fact it is generally a mistake to assume that an expert in anything can necessarily articulate why things are better done or not done a certain way. I have many books on C++ that don't tell me anything I don't already know but I buy them just to allow me to better explain some of my designs to less experienced people. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |