STL 专家在面试中应该回答哪些问题

发布于 2024-08-10 19:49:10 字数 733 浏览 2 评论 0原文

我最近在看一份招聘启事,其中一个要求是 STL 知识达到 9/10。

当我判断自己的技能时,对我来说,10 分是指撰写有关该主题的高级书籍的人,例如 Jon Skeet (C#)、John Resig (JavaScript) 或 Martin Odersky (Scala)。

所以,9/10 基本上就是 10,所以我不确定在这个水平上的预期是什么。

一些问题的示例可以在以下位置找到: http://discuss.joelonsoftware.com /default.asp?joel.3.414500.47

显然需要一些编码,但是应该记住所有内容,因为 STL 中有相当多的内容。

在某些情况下,Boost 库扩展了 STL,因此我也应该使用 Boost,因为我有时可能会混淆哪个函数来自两个库中的哪个。

我想知道我是否可以回答 STL 专家所期望的问题,尽管奇怪的是,成为 C++ 专家并不是必需的。

更新

在思考了我的问题的答案后,他们似乎正在寻找的是能够看到 STL 的局限性并扩展库的人,而这是我还没有做过的事情。我习惯于在 STL 和 Boost 给我的范围内思考并保持在界限之内。我可能需要开始考虑这是否太过限制,看看我是否可以跳出框框。我希望他们不像谷歌那样表示“9”。 :)

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. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吃素的狼 2024-08-17 19:49:10

有趣的是——我不认为自己在STL中是9/10(我曾经是,但现在有点生疏了),而且我完全同意@joshperry的重要术语区别(我经常记录在案)谴责滥用 STL 来表示“C++ 标准库中最初受到 SGI STL 启发的部分”!-),但我认为他的示例代码不是“最佳的 STL 风格”。我的意思是,对于给定的任务“将向量中的所有整数放入标准输出”,为什么有人曾经按照@joshperry的建议进行编码,

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

而不是显而易见的:

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

或类似的东西?!对我来说,这有点表明他们不了解 std::ostream_iterator ——尤其是如果他们应该展示他们的 STL 知识,为什么不这样做呢?他们不是在炫耀吗?-)

在我现在的雇主中,为了帮助应聘者对某项技术的能力进行自我评估,我们提供了一个有用的指南——“10:我发明了这项技术;9:我写了关于它的书”并且如此下去。举个例子,我在 Python 中的得分是 9/10 —— 只有我的同事和朋友 Guido 可以公平地说是 10/10。 STL 是一个有趣的案例:当 Stepanov 推动设计时,我的同事 Matt Austern 完成了第一个实现并且也写了关于它的“书”(这个) - 所以我认为他会声称,即使不是 10,也是 9.5。按照这个标准,如果我能花一个小时来刷新的话,我可能会在 7 到 8 之间(自定义分配器和特征总是很棘手,或者至少我是这样回忆的!-)。

所以,如果你正在调查那些声称得分为 9 的人,请在真正困难的部分(例如自定义分配器和特征)上对他们进行拷问——想必他们不会错过所有容器、算法和特殊迭代器的节拍,所以不要’不要在这些上浪费太多面试时间(如果你正在探索 7 或 7.5,这将是关键)。也许要求他们提供一个真实的例子,其中他们使用了自定义特征和/或分配器,并对实现的所有细节以及一些示例使用进行了编码。

顺便说一句,如果您需要在高级水平上临时抱佛脚学习 C++ 标准库,知识渊博且不生疏的朋友告诉我 Josuttis 的 如今比我朋友 Matt 的书更有用(不幸的是,我从未深入读过 Josuttis,所以我无法证实或否认这一点- 我确实看到这本书在亚马逊上有五颗星,这令人印象深刻;-)。

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;-).

远昼 2024-08-17 19:49:10

这只是工作的一个愚蠢的要求。在招聘时,您首先需要一个优秀优秀的程序员,其次是具体知识。

在当今时代,期望了解/熟悉 STL 等是合理的。但除非工作是重新实现 STL,否则您不需要 9/10。即使这就是工作,您仍然只需要一位拥有丰富模板经验(制作而不仅仅是使用)的优秀程序员。

例如,对于“输出向量的整数”的所有答案,可能会生成完全相同的代码。只有已模板化以处理任何项目的任何容器的版本才会显示“很棒”与“好”的提示(只是提示)。即抽象能力。

不管怎样,就去吧。准备好使用 STL 来帮助解决其他问题。而已。

(事实上​​,对于我参加过的大多数面试,要求是不使用 STL。即 - 编写一个反转字符串的函数。我的第一个答案是 std lib 中可能有一些东西可以做到这一点然后他们说,当然,但是如果你必须自己写怎么办......)

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...)

許願樹丅啲祈禱 2024-08-17 19:49:10

我应该在序言中指出,我认为相同的标准不仅应该适用于 STL(无论您喜欢哪种定义),而且还应该适用于许多其他类型的事物。

从我的角度来看,仅仅了解现有的 STL 组件并能够很好地应用它们可能不应该成为 9/10。相反,我认为该水平约为 7/10。 8/10 是指人们能够通过提供遵循其理念并自然而轻松地与现有组件配合的新组件来扩展 STL。

到 9/10,我希望看到有人不仅能够提供组件,而且能够改进一些现有组件,例如 Boost::bind。对于 10/10,我希望看到这超出了 9/10 的临时、本地化改进,并转向更多的架构级别,例如使用范围而不是单独的迭代器。举一个具体的例子,考虑 Boost 的范围和 Andrei Alexandrescu 的范围想法之间的差异。 Boost 的范围方便、有用且方便,但它们改变的是您键入的内容,而不是您的想法。 Andre 的范围版本更加全面——一种架构解决方案,它改变了您设计和思考代码的方式,而不仅仅是您键入代码的方式。

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.

如歌彻婉言 2024-08-17 19:49:10

好吧,你可以走进面试并说“我注意到你的帖子要求熟悉 STL 的人,但这个术语有时用来表示:(1) C++ 标准库;(2) 在 HP 设计的 Stepanov 库;(3 ) [1] 的部分基于 [2]; (4) [1]、[2] 或 [3] 的特定供应商实现; (5) [2] 的基本原则。非常不明确,并且必须极其谨慎地使用,如果您的意思是 [1] 并坚持缩写,“stdlib”是一个更好的选择。”*

老实说,因为它是一个库,所以它有些有限,可能无法组合。就像语言本身一样令人作呕。所以我想说,任何让他们使用某些 stdlib 算法的问题都可以有效地看出他们是否很了解它们。

由于迭代器是 stdlib 的一个组成部分,我可能还会要求他们“将向量中的所有整数放入标准输出”。我期望类似的东西:

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

如果他们写了类似下面的东西,他们可能对迭代器不太熟悉:

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

另外一件值得寻找的有趣的事情是他们是否在代码顶部使用using namespace std文件。询问他们为什么,如果他们没有说出“我仅将其用于简短的演示代码”之类的内容,或者如果他们将其放入头文件中,请感谢他们的加入并将他们送出门。

stdlib 的另一个方面是它大量使用模板,人们应该对类型替换的基本模板编程有很好的理解。也许要求他们“编写一个函数,将任何 stdlib 容器的所有项目写入标准输出”。我希望看到类似这样的内容:

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

这些可能不是 9/10 的问题,而是我认为 2-3/10 应该知道的有趣问题。

我想说的一个 9/10 困难是在不使用 boost 流基类的情况下正确编写派生 iostream。但是使用 stdlib 和扩展它之间可能有很大的区别...

*(感谢 freenode ##C++ 上的 nolyc 的引用)

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)

酒解孤独 2024-08-17 19:49:10

9/10 是相当主观的。有人问我有关 STL 的好问题。这些是示例:

  • 何时应使用双端队列与向量(了解它们的内部实现方式会很有帮助)
  • 识别使用无效引用或最终可能使用无效引用的 STL 代码。
  • 在不同的容器上实现简单的操作,并知道何时何地使用 std::algorithm 与容器的成员函数。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文