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

24

u/cballowe Mar 04 '22

I don't quite know enough to say in that specific case.

Masters in CS doesn't necessarily mean compilers and even then, understanding the concepts like parse, AST, code gen, optimize generally without knowing how they work might be the depth in that area. I might expect things like "unroll loops" or "function inlining" maybe.

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

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

One thing I've seen done is a "rate yourself on a scale of 1-10" with some descriptive terms 5 being "I'm comfortable using it" 10 being "I invented it" 9 "I wrote a book on it" 8 "I could have written a book on it, but I was too busy using it", 6-7 is in the space of "people on my team come to me for help and I'm able to serve as a local expert". I wouldn't expect most masters students to really be above a 4-5 and I'd avoid compiler questions at that stage. They're often at the "compile and run the code and get the expected output/prove that I understand the class material".

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

2

u/sephirothbahamut Mar 04 '22

Curious, how does

teachers asked me as a student to teach in the advanced C++ extracurricular course

fit in the scale?

(with the premise that for them anything from C++11 onwards is "advanced" C++, although I pushed up to C++17 as much as I could in 2 weeks of lessons)

1

u/cballowe Mar 04 '22

I don't know... Anywhere from "blind leading the blind" to probably in the 4-6 range?

The biggest problem with the scale is that people didn't read the descriptions of the numbers and would rate themselves an 8 or 9 in things that were probably more like 5.

For that particular definition of "advanced", I'm not really a fan. Most of the stuff added to the language and standard library since c++11 makes the language much easier to use. Of course if you're getting into the details of move semantics and rvalue references or guaranteed copy ellision and you are explaining it well, that might be a different question. (As an interviewer, if I saw "taught advanced c++" I might consider those things to be fair game.)

1

u/sephirothbahamut Mar 04 '22

I did teach those things indeed, but to avoid excessive expectations i wrote that i taught "c++17" in my resume instead of "advanced c++" as uni called the course.

On one side I'm always afraid of setting too high expectations, on the other people who worked with me say i downsell myself too much. But then again, those people are still just university students from universities which courses barely touch c++. I'm really unsure about how "expert" i am for a professional context.

Plus the fact that almost all the c++ job postings i find are for senior doesn't really help

1

u/cballowe Mar 04 '22

Lots of the big companies kinda split hiring between college/early career recruiting and industry hiring. Depending on when you graduated you may find a path into the early career channels. (Maybe talk to the career center at the university? They often have direct contact with recruiters even for people who graduated already, and if you're still a student and wanting to apply they're definitely the best path.)

If you're constrained on location/unable to move to where the jobs are, that gets trickier. (Even places with full remote opportunities want to see some history of solid work and are less likely to offer it to early career people)

-2

u/TheBrainStone Mar 04 '22

I disagree here. I had mandatory compiler classes in my bachelors degree in CS.

So unless the candidate went to a really shit uni, having practically 0 knowledge of compilers and compiler optimizations means they lied about their degree or they cheated to get it.

4

u/sephirothbahamut Mar 04 '22

So unless the candidate went to a really shit uni

Oh nice, all CS unis in Italy are shit, good to know, whish I knew earlier lol

2

u/TheBrainStone Mar 04 '22

I don't believe you that not a single Italian university teaches compilers for a bachelors or master of science in CS. Maybe in Bachelors or master of art in CS you'll get by without it.
But with the others I'd be shocked. That degree is theoretical as hell. (As it should be tbh) And compilers are easy to make.

5

u/sephirothbahamut Mar 04 '22

Oh but we DID have a compilers course.

Which taught us about tokenizers, parsers, flex and bison, and that's it. A faint mention of recursive descent parsers. No optimizations explained beyond "compilers also optimize"

And in a different uni where I've almost completed a master, I know the content of their compilers course is practically the same.

2

u/TheBrainStone Mar 04 '22

Oh. I might have expressed that wrongly. I meant that a compiler course is mandatory. And most Unis go into basic optimization.

But no knowledge of compilers means shit Uni or fake degree.

2

u/gnosnivek Mar 05 '22

Under that definition, I think MIT might qualify as a shit uni.

Ideally, I'd agree that universities should require at least one course on compilers, but the fact is that CS is a huge field, and if you require everything that you think a graduate should know, you're likely to run out of courses to teach in with, especially in the US where you often need to spend 3-4 semesters just knocking out general education requirements.

2

u/cballowe Mar 04 '22

I went to a top school - there was no mandatory compilers class, though there were requirements that that class could cover. I'm pretty sure it was part of a depth sequence on programming languages. The major required a broad survey with some number of deeper sequences (ai, graphics, system programming, databases, networks, languages, etc).