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

12

u/CocktailPerson Mar 04 '22

The answers about "removing comments" don't seem to show good understanding so that's a bit of a negative.

Yeah, that one did bother me.

On a daily basis, I rarely think about the specific optimizations, though I do sometimes think "does this abstraction generate code that is as good as writing code without it".

Yeah, okay, that's exactly the skill and intuition I wanted to make sure he had. It's hard to turn that into a concise question, though.

6

u/cballowe Mar 04 '22

That skill is hard to check for, though you could write up some sort of critical loop in a way that's a bit ... Verbose ... Explain what it claims to do and ask them to review the code. Explaining that it's a performance critical section. What I really want is some discussion of benchmarking (maybe not specifically writing the benchmark as those get complicated), some correctness checks, and then some discussion of the expressivity of the code/rewriting parts that are hard to understand or fail to express intent.

3

u/tjientavara HikoWorks developer Mar 04 '22

> The answers about "removing comments" don't seem to show good

> understanding so that's a bit of a negative.

Yeah, that one did bother me.

I was thinking about it, how a programmer would think this.

Running the non-default optimize flag on Python will remove the __doc__ comments (comments that are attached to functions and classes), to reduce byte-code size of a compiled module

https://docs.python.org/3/tutorial/modules.html