r/cpp • • Mar 04 '22

Is it unreasonable to ask basic compiler questions in a C++ developer interview?

I interviewed a guy today who listed C++ on his resume, so I assumed it would be safe to ask a bit about compilers. My team works on hardware simulation, so he's not going to be expected to write a compiler himself, but he'll obviously be required to use one and to write code that the compiler can optimize well. My question was "what sorts of optimizations does a compiler perform?" Even when I rephrased it in terms of -O0 vs. -O3, the best he could do was talk about "removing comments" and the preprocessor. I started out thinking a guy with a masters in CS might be able to talk about register allocation, loop unrolling, instruction reordering, peephole optimizations, that sort of thing, but by the time I rephrased the question for the third time, I would have been happy to hear the word "parser."

There were other reasons I recommended no-hire as well, but I felt kind of bad for asking him a compiler question when he didn't have that specifically on his resume. At the same time, I feel like basic knowledge of what a compiler does is important when working professionally in a compiled language.

Was it an unreasonable question given his resume? If you work with C++ professionally, would you be caught off guard by such a question?

335 Upvotes

335 comments sorted by

View all comments

Show parent comments

1

u/CocktailPerson Mar 04 '22

I don't think compiler optimisation is a commonly taught subject in universities

It's usually part of a class about compilers themselves. Did your university offer a compilers course?

If it's important for the role, then it's reasonable to ask about it in "bonus if know this" sense.

That's definitely the way I tried to approach it. The bulk of the interview was spent determining that he had no idea how to refactor a small function in C++. If he'd nailed that, I definitely still would have recommended him. If he'd struggled with the refactoring, but knew about compiler optimizations, I might still have recommended him.

If you need a programmer who is highly skilled at writing optimised code

No, just someone who's aware of what a compiler can and can't do.

Writing code that compiler can optimise well isn't something that's really taught anywhere as far as I know. It's something that one learns on the job, and only if they are actually optimising the code.

Well, that's the thing. If you know what sorts of optimizations a compiler can and can't do, understanding how to write code the compiler can optimize well is a natural consequence.

3

u/Supadoplex Mar 04 '22 edited Mar 04 '22

Did your university offer a compilers course?

It wasn't offered during the time I was there 2005-2011 - Could maybe have been offered during early years when I wouldn't have checked the advanced courses.

I checked their study guide now, and there is a reference to "advanced course on compilers", so it has been there at some point. "Past executions" (I'm not sure if that's a good translation) is empty and I found no other mentions online, so I'm guessing that it's not been offered recently.

Well, that's the thing. If you know what sorts of optimizations a compiler can and can't do, understanding how to write code the compiler can optimize well is a natural consequence.

My point is that people learn about those things when they are optimising their code at a low level - which is something that most computer science students have no experience of. Not all professional C++ programmers would have experience of it either. It's a niche skill.

If you're hiring a junior dev, then in all likelihood you're going to have to train them on this. If you're hiring a senior dev, then it's OK to hope for relevant skills, but it will be much harder to find a fitting candidate if you consider it to be a requirement. And I would expect education to have little effect on the quality of the candidate in this regard.

High level optimisation is all about data structures, algorithms, N+1 problem and parallelisation which require little to no knowledge of the compiler.