views:

1366

answers:

5

I was looking at a job posting recently and one of the requirements was that a person be a 9/10 in their knowledge of STL.

When I judge my skills, to me a 10 is someone that writes advanced books on the subject, such as Jon Skeet (C#), John Resig (JavaScript) or Martin Odersky (Scala).

So, a 9/10 is basically a 10, so I am not certain what would be expected at that level.

An example of some questions would be found at: http://discuss.joelonsoftware.com/default.asp?joel.3.414500.47

Obviously some coding will be needed, but should everything be expected to be memorized, as there is quite a bit in STL.

In some cases Boost libraries extend STL, so should it be expected that I would be using Boost also, as I may sometimes confuse which function came from which of the two libraries.

I am trying to get an idea if I can answer questions that would be expected of a STL expert, though it is odd that being a C++ expert wasn't a requirement.

UPDATE

After reflecting on the answers to my question it appears that what they may be looking for is someone that can see the limits of STL and extend the library, which is something I haven't done. I am used to thinking within the limits of what STL and Boost give me and staying within the lines. I may need to start looking at whether that has been too limiting and see if I can go outside the box. I hope they don't mean a 9 as Google does. :)

+1  A: 

Well, you could walk into the interview and say "I noticed that your posting asked for someone knowledgeable in STL but that term is sometimes used to mean: (1) C++ standard library; (2) the library Stepanov designed at HP; (3) the parts of [1] based on [2]; (4) specific vendor implementations of either [1], [2], or [3]; (5) the underlying principles of [2]. As such, the term is highly ambiguous, and must be used with extreme caution. If you meant [1] and insist on abbreviating, "stdlib" is a far better choice."*

Honestly though since it is a library it is somewhat finite and probably not composeable to nauseating infinitum like a language proper. So I would say any question that had them use some of the stdlib algorithms would be effective to see if they knew them well.

With iterators being an integral part of the stdlib I would also maybe ask them to "Put all the integers in a vector to standard out." I would expect something like:

// thanks to onebyone
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " ");

If they write something like the following they probably aren't very familiar with iterators:

for(int i = 0; i < vec.size(); ++i)
    std::cout << vec[i];

Also one interesting thing to look for is if they do using namespace std at the top of their code file. Ask them why, and if they don't say something along the lines of "I use that for short demo code only" or if they put it in a header file, thank them for coming in and send them out the door.

Another aspect of the stdlib is it's heavy use of templates, the person should have a good understanding of basic template programing for type substitution. Maybe ask them to "Write a function that will write all of items of any stdlib container to standard out". I would expect to see something like:

template<typename InputIter>
void Output(InputIter it, InputIter end) {
    while(it != end)
        std::cout << *it++;
}

These are probably not 9/10 questions but interesting ones I think a 2-3/10 should know.

One 9/10 difficulty I would say is to write a derived iostream properly without using the boost stream base classes. But there is probably quite a difference between using the stdlib and extending it...

*(thanks to nolyc on freenode ##C++ for the quote)

joshperry
nolyc is a bot, so thanks to whoever put that quote into the bot...
joshperry
"Put all the integers in a vector to standard out." I would expect `std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " ");`. In STL one-upmanship, writing a loop is a sign of weakness ;-)
Steve Jessop
lol, I was just waiting for alternate answers to my questions :) I do love output iterators, and they are definitely a sign of a 6-7+/10!
joshperry
The funny thing is that the most concise code, and certainly the least likely to require a future maintenance programmer to look anything up, is the "naive"/"wrong" loop with integer index. So if you get that, it's worth checking whether the programmer is unfamiliar with iterators, or is entirely familiar with them but prefers to write the most obvious thing which works. And then slap them for not using `vector<int>::size_type`.
Steve Jessop
OK fine, maybe that wasn't a great example, you could just downvote the answer and put me out of my misery...
joshperry
Wait, you wouldn't expect `std::copy(it, end, std::ostream_iterator<typename std::iterator_traits<InputIter>::value_type>(std::cout));` ? ;)
UncleBens
@joshperry: I like the example, actually, since with a bit of discussion it tells you (a) whether the candidate knows the STL, and (b) whether the candidate cares about using the "pure STL" approach, or is is a bit more pragmatic. IMO coherently arguing the pros and cons of the three bits of code you list, is way more important than which one you personally prefer. Plus it tells the candidate the same things about the interviewer, and hence tells them both (c) whether they're going to end up having a lot of arguments about coding style. Agreed though this doesn't reach "9/10".
Steve Jessop
+7  A: 

Funny -- I don't consider myself a 9/10 in STL (I used to be, but I'm a bit rusty now), and I do fully agree with @joshperry's important terminological distinguo (I've often been on record as berating the abuse of STL to mean "the parts of the C++ standard library that were originally inspired by SGI's STL"!-), yet I consider his example code less than "optimally STL-ish". I mean, for the given task "Put all the integers in a vector to standard out.", why would anyone ever code, as @joshperry suggests,

for(std::vector<int>::iterator it = intVect.begin(); it != intVect.end(); ++i)
    std::cout << *it;

rather than the obvious:

std::copy(intVect.begin(), intVect.end(), std::ostream_iterator<int>(std::cout));

or the like?! To me, that would kind of suggest they don't know about std::ostream_iterator -- especially if they're supposed to be showing off their STL knowledge, why wouldn't they flaunt it?-)

At my current employer, to help candidates self-rate about competence in a technology, we provide a helpful guide -- "10: I invented that technology; 9: I wrote THE book about it" and so on down. So, for example, I'd be a 9/10 in Python -- only my colleague and friend Guido can fairly claim a 10/10 there. STL is an interesting case: while Stepanov drove the design, my colleague Matt Austern did the first implementation and wrote "the" book about it, too (this one) -- so I think he'd get to claim, if not a 10, a 9.5. By that standard, I could be somewhere between 7 and 8 if I could take an hour to refresh (custom allocators and traits are always tricky, or at least that's how I recall them!-).

So, if you're probing somebody who claims a 9, grill them over the really hard parts such as custom allocators and traits -- presumably they wouldn't miss a beat on all the containers, algorithms, and special iterators, so don't waste much interview time on those (which would be key if you were probing for a 7 or 7.5). Maybe ask them to give a real-life example where they used custom traits and/or allocators, and code all the details of the implementation as well as a few sample uses.

BTW, if you're the one needing to cram on C++'s standard library at an advanced level, I'm told by knowledgeable and non-rusty friends that Josuttis' book nowadays is even more useful than my friend Matt's (unfortunately, I've never read Josuttis in depth, so I can't confirm or deny that - I do see the book has five stars on Amazon, which is impressive;-).

Alex Martelli
So your understanding of 10 is higher than mine, which causes me more concern, but before applying, I guess the first question is to get an idea what the difference between a 9 and 10 are. I remember a company that had me rate myself on 3 pages of skills, from 0-5 but they actually had a key, with examples for each of them.
James Black
I didn't realize that answers were for bashing on other people's answers, I guess comments aren't obvious enough to really try to make them look bad. The whole idea behind my _sample_ was to ask a question that would get a feel for if the person knew how to use iterators properly. Sure if you were ONLY outputing a simple int then my construct is not the best solution. Even if your doing something more complex you might use for_each, but I don't think the for loop example I gave is useless in 0 cases. Only Sith deal in absolutes, as my friend Obi Wan used to say.
joshperry
@James, if the company you're interviewing for doesn't explain what they ratings mean, that's a bad sign and you're fully within your rights to do your interpretation -- it would be fully reasonable to interpret 10/10, bereft of interpretation guidelines from the interviewers/potential employers, to mean "in the top 10% of practitioners" which would easily span the range 8-10 in _my employer's_ interpretation, for example!
Alex Martelli
@joshperry, I'm surprised and saddened to see you took my answer as inimical to yours -- if a candidate's ready to mention ostream iterators _and_ defend their choice to **not** use them, that's worth listening to. BTW, in comments, I can't put decent formatting, so go flame on meta about that -- you can't demand I put stuff in a comment when it needs formatting or is just too long for a comment's ridiculous limits, and both criteria apply to my **answer**, which is why I never even thought of putting it into a comment -- SO's fault!-). (BTW, I haven't downvoted you -> I'm OK w/your answ!-).
Alex Martelli
Thanks for the clarification Alex, yes the comments really do leave a bit to be desired; as we interact here in blobs of text. Often the subtleties of communication are lost in online communications, as we struggle to convey meaning with only one mode of interaction. I for one can appreciate constructive criticism and I enjoyed your answer, I'm glad that you and others joined in!
joshperry
"I've often been on record as berating the abuse of STL" - that's a high-risk strategy. Prove that not only are you a 9/10 on STL, but that the interviewer is at best a 4 or 5 since they're mistaken as to what the STL actually is ;-)
Steve Jessop
@onebyone, you have a point -- assuming you're able to keep hiding your knowledge once you do get the job, because if a place won't hire you if you're too good in the interview, it may not keep you if you're too good on the job. Back when I was interviewing I did (gently and diplomatically as best I can;-) correct mistakes and often teach interviewers some thing or other that they didn't know -- if that meant no hire, that was for the best, as it was unlikely to be a firm I'd enjoy (and I'd probably get fired soon for showing off some ignoramus anyway;-).
Alex Martelli
I figure they'll learn to love you showing up ignorami, but it might take longer than the time available in the interview.
Steve Jessop
I think it's more of a question of the firm's general attitude: though I admit I have in some occasion somewhat changed the culture of some firms that had hired me, in the past, mostly you have to assume that the culture is ingrained. If truth is not valued above personalia, it's not going to be a nice place to work.
Alex Martelli
Sure, but there's truth and then there's lexicography. Natural language is defined by common usage, and all that. So really the only value I see in correcting the interviewer on this point is if you already don't want the job, but want to embarrass them for writing such an ambiguous requirement in the first place. "9/10" could mean just about anything. Arguing about them following common usage of the term "STL" is piling on the charges ;-)
Steve Jessop
STL is a proper noun and a trademark, so "common usage" doesn't apply (until a judge says so and decrees that the trademark status is lost;-). If the place's so sloppy as not to understand THAT (and not be willing to be put right), how tight and brilliant are they going to be at developing and shipping software? If they can take my correcting them in good grace, well then, I'm all for giving people a second chance; but I have no patience with people who are too proud to accept their mistakes;-).
Alex Martelli
Interesting question: does trademark law apply to job postings? Has SGI sued Meyers for "Effective STL", which nowadays is actually about the C++ library? Is their failure to protect the term by doing so, likely to undermine their claim to it in future cases? And does his abuse of the term imply that the technical advice in the book is non-brilliant? What, if anything, does Rackable say these days about how "STL" may be used? Should certainly provide plenty of debate to keep the interview moving along ;-)
Steve Jessop
I should disclose that I have written documentation in the past which had to correctly use The Java(TM) Trademark, and hence could not use "Java" as a noun, only as an adjective in full phrases ("the Java(TM) Programming Language", "the JVM", etc). I therefore have a lot more appreciation for the use of trademarked terms, than I do sympathy.
Steve Jessop
+1  A: 

It is just a dumb requirement for a job. When hiring you want a good great programmer first, specific knowledge second.

It would be reasonable, at this day and age, to expect knowledge/familiarity/etc with the STL. But unless the job is to reimplement the STL, you don't need 9/10. Even if that is the job, you still just need a great programmer that has lots of experience with templates (making not just using).

For example, for all the answers to "output the integers of a vector", probably the exact same code is generated. Only the version that has been templated to handle any container of any items shows a hint of 'great' vs good (just a hint). ie the ability to abstract.

Anyhow, just go for it. Be ready to use the STL to help solve other problems. Nothing more.

(In fact, for most of the interviews I've been in, the requirement was to NOT use the STL. ie - write a function that reverses a string. My first answer is that there is probably something in the std lib that would do that. Then they say, right, of course, but what if you had to write it yourself...)

tony
It seems that they have a tech test that uses STL heavily, and it appears that their judgement is that if you are an expert in STL then you must be in C++. So an expert may be someone that know C++ enough to reimplement STL from scratch, but can use STL when needed, perhaps.
James Black
+2  A: 

I should preface this by noting that I think the same criteria should be applied not only to STL (regardless of which definition you prefer for that), but to many other types of things as well.

From my perspective, simply knowing the existing STL components and being able to apply them well probably should not qualify as a 9/10. Rather, I'd consider that level about 7/10. 8/10 is when the person is able to extend the STL by providing new components that follow its philosophy and fit with existing components naturally and easily.

By 9/10, I'd expect to see somebody who can not only provide new components, but is able to improve some of the existing ones, such as Boost::bind. For 10/10, I'd expect to see this go beyond the rather ad hoc, localized improvements of a 9/10, and moving toward looking at a more architectural level, such as using ranges instead of individual iterators. For a concrete example, consider the difference between Boost's ranges and Andrei Alexandrescu's ideas for ranges. Boost's ranges are handy, useful and convenient, but they change what you type, not how you think. Andre's version of ranges is much more all-encompassing -- an architectural solution that changes how you design and think about code, not just how you type it.

Jerry Coffin
+1  A: 

9/10 is quite subjective. I have been asked good questions about STL. These are examples:

  • When should you use a deque vs a vector (knowledge of how they are internally implemented is helpful)
  • Recognize STL code that uses invalid references, or can end up using invalid references.
  • Implement simple operations on different containers, and know where and when to use std::algorithm vs member functions of a container.
navigator
These seem fairly basic though, something easily answered in the first chapter of Essential STL, for the first two, but even the third is in that book. But thank you for the questions.
James Black