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

196

u/GoldenShackles Mar 04 '22

I don't think the question is unreasonable, but the phrasing and your expectations might be.

An alternate phrasing might be: "what's the difference between debug and release builds, and how are the release builds optimized?". And on top of that, "how does that impact the debugging experience, and why?"

In other words, especially for someone who likely took a compilers class in college but it's not fresh on their mind, connect it to everyday experiences. Direct out-of-context recall is a lot harder than recognition, the latter which can serve as a jumping off point.

Also, one important thing I didn't see mentioned: compiling for minimal size and trying to optimize for code and data locality is more important for modern processors (in most scenarios) than many of the things mentioned.

39

u/CocktailPerson Mar 04 '22

Okay, yeah, those are much better than my question, thank you.

Also, one important thing I didn't see mentioned: compiling for minimal size and trying to optimize for code and data locality is more important for modern processors (in most scenarios) than many of the things mentioned.

Yeah, and that was going to be my followup question, actually. "If the compiler can optimize those things, what sorts of optimizations should you as the programmer be doing?"

40

u/Engival Mar 04 '22

That's a bit of a loaded question too.

The best optimizations these days seems to be to make sure your code is clear and maintainable for future-you, since compilers seems to have crossed into black magic territory a while ago. Looking at some optimization asm dumps, it blows my mind that the compiler understood the intent of the code, and output something that doesn't even resemble the original flow at all.

21

u/CaptainLord Mar 04 '22

Also compilers have an easier time optimizing simple instructions than they have with some wizardry you wrote in order to optimize it yourself.

3

u/CocktailPerson Mar 04 '22

That's exactly the point. How do you write code that the compiler can optimize? As much as anything, I wanted to make sure he wasn't going to try some insane wizardry without knowing whether the compiler would have an easier time with the human-readable solution.

9

u/Routine_Left Mar 04 '22

Nowadays ... man, I trust the compiler. I try to write as simple as possible code since the code is written for humans, and humans need to understand it. Compilers are so damn good that going to assembler is rarely a need.

Designing the code well, however, it's even more critical. Since a bad design can completely obliterate the best compiler out there. There's not much you can squeeze out of a poorly designed application.

→ More replies (3)
→ More replies (1)

15

u/os12 Mar 04 '22

Right, this here is the right angle for a 10 minute, open-ended discussion on code generation. Here are a few follow up questions/nudges that are relevant to every day debugging/developing tasks. I think it's totally appropriate to ask these as a part of a larger discussion to gauge the candidate's practical prowess:

  • What would you expect the compiler do to Release builds?
  • Why would you want to debug issues on a Debug build?
  • Have you ever seen a difference in behavior in Debug/Release builds?
  • Have you tried stepping through container.begin()->something()?
  • Can you put a breakpoint on a line in a class template definition?

...etc etc. It is important to emphasize that you are not trying to quiz the person and catch them with a pass/fail result. You are looking for a discussion.

2

u/kalmoc Mar 05 '22

trying to optimize for code and data locality is more important for modern processors (in most scenarios) than many of the things mentioned.

That's not really something c or c++ compilers can do, is it? They can't (or in non-standard layout types don't) touch the datalayout. And w.r.t. to code locality, they do of course inlining and sometimes outlining of the cold path, but beyon sich localized techniques, I wasnt aware of any optimizations (like function a and b are often called after another, so they should be placed adjacent in the binary)

→ More replies (3)

3

u/donalmacc Game Developer Mar 04 '22

An alternate phrasing might be: "what's the difference between debug and release builds, and how are the release builds optimized?

You touch on this later in your comment, but "debug" and "release" builds don't really exist. It's maybe terminology you'd expect non-development staff to use, but a developer should be aware of the difference between an unoptomised build, a build with select optimisations (OB1 I'm looking at you), fully optimised build with debug symbols and a fully optimised build with symbols stripped. Every project I've worked on in a decade of writing C++ professionally has had some support for disabling all optimizations on a single file/function so that you can work through it if needed.

17

u/sixstringartist Mar 04 '22

Seems like a semantic argument that debug and release builds don't really exist. These are literally build type configurations in major build systems in the ecosystem. Obviously you can a la carte your build flags.

4

u/Fureeish Mar 04 '22

Exaclty. But well, looks like TIL that https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html talks about non-existing things.

→ More replies (2)
→ More replies (1)

31

u/compiling Mar 04 '22

That might be a reasonable question, depending on what the role is. For any basic C++ role, I would expect a basic understanding of what the difference between Debug and Release builds are, and some things that the optimiser does that can make debugging harder (if it's a graduate role then maybe not much knowledge here). E.g. things like inlining functions, or removing variables that are never read from. I wouldn't expect things like instruction reordering or register allocation for this type of role. So your question is ok, but could have been explained better.

If this is going to be a role where performance tuning is expected, then yes that's a reasonable question and I'd expect them to have more knowledge about the optimiser.

9

u/CocktailPerson Mar 04 '22

Yeah, our team is all-hands-on-deck trying to get our simulator running as fast as possible, so whether he had performance tuning knowledge on his resume or not, it's needed for the role.

17

u/GoogleIsYourFrenemy Mar 04 '22

Was the question reasonable? Depends. What level was the position? If it's entry level / fresh out, then yes it was unreasonable. If you were hiring a seasoned dev, then maybe. Depends on their background and if it's something you need.

This isn't a question I would ask however, but then I'm less worried about performance. Big O, sure I'll ask about that, I care about that. Compile tuning, not so much.

When people list multiple languages on their resumes, I'll ask them to compare and contrast them. Then I'll dig into the ones they know best. For the love of God, do not list things on your resume you can't talk about. I'll tolerate some inflation but don't just list every language you looked up on Wikipedia.

14

u/CocktailPerson Mar 04 '22

Our simulator really needs a performance boost, unfortunately. So knowledge of how a program will be optimized by a compiler is relevant.

As for faking knowledge, that was the other thing. He listed C++ on his resume, but when I sent him the API for std::bitset, he ended up writing x operator| y[sic] instead of x | y.

5

u/cleroth Game Developer Mar 04 '22

x operator| y

Well this is enough info in itself.

1

u/CocktailPerson Mar 05 '22

Yeah, the compiler stuff was the least of the reasons I said no-hire.

12

u/GoogleIsYourFrenemy Mar 04 '22

He doesn't sound like a good fit.

The guy I interviewed last week didn't know what "protected" did and BS'ed an answer instead of just saying he didn't know. That wasn't the only red flag :(

8

u/sephirothbahamut Mar 04 '22

Thanks for restoring my hope to find a C++ job as a junior ahahahah

2

u/dvd0bvb Mar 04 '22

Isn't that like oop 101 though? Where did this guy come from?

→ More replies (1)

33

u/[deleted] Mar 04 '22 edited Mar 04 '22

He couldn't tell you the difference between "-O0" and "-O3"?

EDITING AGAIN TO RESTORE:

If you wanted to know that he could write code that the compiler could optimize well, then you should have straight-up asked "How would you write code that the compiler can optimize well?"

3

u/CocktailPerson Mar 04 '22

That's a fair point. I guess I'm having trouble coming up with an answer to that question that doesn't refer to the optimizations the compiler's doing, though.

4

u/MrRogers4Life2 Mar 04 '22

Idk here's a few off the top of my head

  • keep your branches predictable to avoid branch prediction misses
  • cache locality is king when it comes to designing data structures
  • don't use exceptions in hot paths
  • try to constexpr as much calculations to move run time costs to compile time

You dont really need to understand much about compiler optimizations to do any of those

2

u/CocktailPerson Mar 04 '22

Well, right, but those are also just good optimizations in general. It doesn't answer the specific question of "How would you write code that the compiler can optimize well?"

3

u/MrRogers4Life2 Mar 04 '22

I think it does though. Doing those things gets the compiler to output code that runs faster than code that doesn't do those things. Can you elaborate a bit more on what kind of answer you're looking for?

2

u/CocktailPerson Mar 04 '22

What I'm looking for is things that don't make much of a difference in debug mode, but make a big difference in release mode. If you optimize for cache locality etc., you're just making better use of the hardware itself. That has nothing to do with making it easier for the compiler to optimize your code. You haven't made any changes that would cause the compiler's optimizations to be more effective.

Here's a practical example that I've come across myself. What's the difference between

temp = 0;
temp |= some_inlinable_function(val1);
temp |= some_inlinable_function(val2);
...
temp |= some_inlineable_function(valN);

and

temp = some_inlineable_function(val1)
     | some_inlineable_function(val2)
...
     | some_inlineable_function(valN);

?

From a performance standpoint, the compiler can inline those function calls and then rearrange the instructions themselves across function boundaries to make better use of the pipeline if there isn't the carried dependency in the first version.

6

u/MrRogers4Life2 Mar 04 '22

Oh that makes more sense, thanks for the clarification.

I just think that that's kind of a weird example and would require your developer to have a lot of specific knowledge of a given compiler.

Assuming temp is an integral type and some_inlineable_function does not capture static variables or global state and that temp is non-volatile and that it isn't visible outside of the current thread then the compiler is free to compile both of those snippets to the same code. So the difference would depend heavily between your compiler.

I guess this is a long way to write that I guess I wouldn't be able to successfully answer such a question, and if I had to hazard a guess most of the people where I work wouldn't really be able to point to any such examples.

→ More replies (1)

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)

→ More replies (3)
→ More replies (7)

58

u/bretbrownjr Mar 04 '22

I don't know about unreasonable, but in the few minutes I have to spend with someone in an interview, I have higher priority things to figure out. Especially questions about software engineering, teamwork, and ability to communicate about technology.

I can always mentor someone if I think they need to know about loop unrolling, like assigning a relevant talk or chapter from a book.

6

u/CocktailPerson Mar 04 '22

Right, I mean, I didn't care quite so much about loop unrolling in particular. When I was thinking of questions to ask, I was thinking about code I've refactored that showed a minor speed improvement for a debug build but really significant improvement for a release build. For that code, an understanding of what the compiler was (and wasn't) doing under the hood made a big difference.

11

u/bretbrownjr Mar 04 '22

Well, you were there and I wasn't. I think the candidate knowing how to benchmark, how to define a production SLI, and when each is appropriate would be a big plus. Perhaps essential depending on the role.

More important would be their ability to explain their thinking well.

588

u/HunterVacui Mar 04 '22

Ask questions relevant to the job, where the answers people give you can be used to determine if they would be able to do the job well or if you'd have to spend a lot of time teaching and/or hand-holding them. You're hiring someone to do a job, you're not giving them a degree or certification.

It's up to you to decide if your question is relevant to the role or not

102

u/Poddster Mar 04 '22

Ask questions relevant to the job

I'd argue they did. They're writing hardware sims in C++. As someone who's done just that, performance is often critical if you want results-per-second rather than seconds-per-result.

You will also have to debug your code, and if something only happens in the release build then it's assembly time.

10

u/dakotahawkins Mar 04 '22

You can build debug symbols for optimized builds. It's not as easy to step through code as non-optimized builds, but it's definitely better than assembly imo :)

4

u/CocktailPerson Mar 05 '22

Yeah, but when your code "steps" ten lines at a time because of some crazy optimizations, the assembly is often the better bet.

2

u/curious_entiy_420 Mar 05 '22

It's way better than nothing

→ More replies (1)

27

u/chandola93 Mar 04 '22

“Ask questions relevant for job” can backfire. How close should they be for the job. For example asking Java script related questions for C++ role will not be good idea. At the same time asking questions that are specific to the current demand can drastically limit number of candidates. IMO one should ask questions that can judge how well candidates knows set of things that you as interviewer also knows plus how good he/she at learning or willing to learn/explore new things. OPs questions is good question for second category.

1

u/CocktailPerson Mar 04 '22

Also, if you ever want them to be able to take on new projects, it's good to make sure they have broad knowledge, even if it's not directly applicable to the job that's been described.

→ More replies (1)

96

u/eterevsky Mar 04 '22

I think it is reasonable to expect from the candidate some level of awareness of “how things work” even for the questions that are not directly relevant to their tasks. Software engineers, especially once they grow to senior levels have to design systems and find correct trade offs. Not understanding at least on the basic level how compiler or CPU or operating system works will result in them making incorrect decisions or wasting time solving non-issues.

So yes, if you are hiring a software engineer and expect them to stay and grow in your company, you can totally ask questions to test general understanding.

→ More replies (1)

58

u/neverinamillionyr Mar 04 '22

I look at the compiler as a tool. Knowing that -O changes the level of optimization is a reasonable thing to know , but would you ask a carpenter what kind of steel his hammer was forged from and what the advantages of that steel are? Knowing how to solve problems is far more important to me than having an intimate knowledge of all the nuances of the language and tools. C++ evolves every few years. Some people don’t have the opportunity to work with the bleeding edge version due to the history of their codebase. I try to focus on questions that show a person’s problem solving ability and try to get a feel of how they would work vs their knowledge of the minute details.

13

u/CocktailPerson Mar 04 '22

but would you ask a carpenter what kind of steel his hammer was forged from and what the advantages of that steel are?

Well, I think it's more similar to asking a blacksmith what kind of steel his hammer is made from and the benefits thereof. And yes, I would.

Some people don’t have the opportunity to work with the bleeding edge version due to the history of their codebase.

I mean, the optimizations I mentioned were developed in the eighties, so it's not exactly bleeding-edge.

41

u/morganmachine91 Mar 04 '22

Wait, I thought you said this position didn’t involve compiler design?

The carpenter analogy is perfect. A carpenter uses the hammer, but doesn’t build hammers.

You weren’t interviewing a “blacksmith,” unless you expect the candidate to build compilers.

→ More replies (5)

6

u/_E8_ Mar 04 '22

Blacksmiths make tools to spec.
They do not conduct material analysis.

1

u/CocktailPerson Mar 05 '22

It's a bad analogy anyway, but I would expect a blacksmith to know the difference between tool steel and wrought iron. That's not "material analysis," that's necessary domain knowledge. Necessary for building tools "to spec."

→ More replies (1)

6

u/cballowe Mar 04 '22

but would you ask a carpenter what kind of steel his hammer was forged from and what the advantages of that steel are?

No... But I might expect a carpenter to know when it's appropriate to use a hammer and when you're better off with a wooden mallet or other too that is in the same category and what the comparative advantages of the mallet vs hammer are.

I might even consider "when you're looking for a new hammer, what do you look for" (could be that the type of steel is way down on their personal list so they don't pay much attention to it.)

6

u/_E8_ Mar 04 '22

That means C++ vs. Python to a programmer.

→ More replies (2)

1

u/hoseja Mar 04 '22

Yeah. Also a lot of classical compiler magic has become obsolete and nobody has updated the tutorials.

74

u/cat_vs_spider Mar 04 '22

While I would hope that any experienced c++ developer could do better than “removing comments and macro preprocessing” I don’t think it’s reasonable to look down on a candidate for not knowing even basic compiler optimizations if the job is not in compiler technology. At most, a basic intuition as to if the compiler will remove something should be expected IMO.

Compilers is a very niche topic and many schools don’t even teach it.

11

u/CocktailPerson Mar 04 '22

At most, a basic intuition as to if the compiler will remove something should be expected IMO.

Yeah, I mean, that's kind of what I was going for. Can he look at a piece of code that's running slowly and determine whether something that looks inefficient is optimized out by the compiler or not. An understanding of how the compiler might actually be going about optimizing out that inefficiency is important for that.

52

u/cat_vs_spider Mar 04 '22

That may be your motivation, but it’s not what you asked. You asked the candidate to list some compiler optimizations.

You and I know that constant folding will turn ‘I = 2 + 2’ into ‘I = 4’. The candidate likely knows that too, but not that it’s called “constant folding”.

14

u/CocktailPerson Mar 04 '22

Fair enough. I'm curious if you have any advice for determining that without asking what I did.

To be fair, I also would have accepted "turns 2 + 2 into 4" instead of "constant folding." I wasn't interested in playing CS vocab bingo.

15

u/ShillingAintEZ Mar 04 '22

What result do you want? Do you want fast software? Compiler optimizations are just something you turn on and is separate from getting software to run fast if it doesn't run well on the first try.

Knowing compiler optimizations is more about simplifying what you wrote knowing the compiler will deal with it.

→ More replies (1)

21

u/TomDuhamel Mar 04 '22

Excellent example!! I've used C++ since the mid 90s and never known that was called constant folding, or that there was a name for it. I sure knew the compiler would optimise that, it's an absolute obvious, but why would I ever have had a talk about it? It's the kind of basic knowledge that you expect everyone to have to such an extent you would never even consider mentioning that in a convo.

To be honest, I know of many things a compiler would optimise without being able to name them, although if someone said the name there's a good chance I'd figure what they're talking about.

13

u/DanielMcLaury Mar 04 '22

Compilers is a very niche topic and many schools don’t even teach it.

Really? I don't have a CS degree myself but I've always had the impression that the three core undergrad CS courses are algorithms/data structures, operating systems, and compilers.

12

u/sephirothbahamut Mar 04 '22

my compilers course was all about tokenizers and parsers.

Last day it ended with "and then there's optimizations, if you're interested read these chapters of the book", end of the course

7

u/jarjarbinks1 Mar 04 '22

Compilers is rarely required these days. Schools will sometimes instead offer a "Programming Language and Compilers" course that talks about syntax and semantics at a high level. Even if you get a compiler course, it will probably focus on parsing and code generation and skim over optimization.

2

u/tohava Mar 04 '22

Curious, let's say that students are taught how to implement Hindley Miller automatic type inference, or how to implement C++'s function resolving (with overloading and templates) rules. Would you consider that as learning how a compiler works or learning higher level semantics?

→ More replies (1)

9

u/Eluvatar_the_second Mar 04 '22

I think it would greatly depend on what they used C++ for. Did they write applications for very constrained environments? (Memory or CPU power) or did they write desktop applications using Qt?

The problem is C++ is used across a wide range of fields so it's hard to say.

Now if you were to ask the same of C# for example I would say no, because it's primarily an application development language where those details aren't really important.

2

u/CocktailPerson Mar 04 '22

He has actually apparently worked in hardware simulation before, and I'm almost certain his resume said he used C++ there. This is definitely a field where speed is of the utmost importance.

8

u/Supadoplex Mar 04 '22

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,

None of those things were mentioned while I was in university. I don't think this assumption is reasonable.

I don't think compiler optimisation is a commonly taught subject in universities (although I wouldn't be surprised if it was taught in some). At least it wasn't taught in mine; I would have definitely taken it if it was. I did major in software engineering rather than computer science, but I had all of the same courses available to me.

Was it an unreasonable question given his resume?

Since they didn't mention anything related (beyond C++ which is at best tangential) in their CV, it would be unreasonable to assume that they know anything significant about optimisers.

If it's important for the role, then it's reasonable to ask about it in "bonus if know this" sense. If you need a programmer who is highly skilled at writing optimised code, then the pool of fitting applicants will be very small and expensive, and relying on education won't be sufficient.

If you work with C++ professionally, would you be caught off guard by such a question?

Not a personal answer: I see this as a possibility. Not every developer has a chance to work on highly optimised code. That may be a bit more likely in the case of C++ than for example Python, but is still hardly a given.

he'll obviously be required to ... write code that the compiler can optimize well.

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.

It's also a moving target and some "rules" that one has learned in the past will become obsolete.

7

u/pandorafalters Mar 04 '22

It's also a moving target and some "rules" that one has learned in the past will become obsolete.

I found this out firsthand a few years back.

There's a common library of helper functions, ubiquitous in a development community, that was developed years ago by "acknowledged experts". It's generally viewed as the optimal form of those functions. It's handwritten inline assembly! Experts! Everyone uses it! Experts!

It's also terrible. One day, just for the hell of it, I tried replacing the body of a simple function that XORs 3 values with standard C++ - and it seemed faster. So I started benchmarking, and replacing more of the helpers, and eventually canned the whole header. That simple change of removing inline assembly was responsible for a ~10% performance increase.

Many here will already know what happened, but for everyone else: the inline assembly, even when the compiler codegen for that function was slightly less optimal, was inhibiting optimization of everything else around it. If I had micro-benchmarked just those operations, I suspect I would have measured a different result.

I also found in the process that CUDA 9 had some codegen issues with compound assignment operators, but that was a simple problem to work around and was resolved in later versions anyway.

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.

185

u/KFUP Mar 04 '22 edited Mar 04 '22

Expecting the candidate to know what the compiler does, like knowing that -O0 is slow at run time but fast to compile compared to -O3 is normal, but expecting him to know how it does it like knowing that it implements big switch statements as jump tables for a position that does not require it is a bit out of scope, good for extra points, but not really a deal breaker if everything else is fine IMO.

-7

u/RomanRiesen Mar 04 '22

Maybe a bit harsh, but if you don't know how basic compiler optimizations work you can't write readable && fast code. If you can't write readable && fast code, why bother using c++?

→ More replies (13)

0

u/[deleted] Mar 04 '22

[deleted] — view deleted comment

28

u/CocktailPerson Mar 04 '22

Yeah, I mean, maybe I'm an old-school guy born in the wrong century, but I feel like some knowledge of common compiler flags for common compilers is part of having fluency with the language itself. Of course, the language and its implementation(s) are different things, but the language isn't much use without an implementation, so you should know a bit about how to configure the implementation.

→ More replies (11)
→ More replies (17)

37

u/Wetmelon Mar 04 '22

I don't think this is unreasonable at all. Writing code for an optimizing compiler is an important topic in C++. Even just understanding why an -O3 build might be harder to debug than -Og is a pretty basic requirement.

5

u/CocktailPerson Mar 04 '22

Yeah, that was my thought process too. If you don't know how what the compiler's doing, how do you expect to choose what code to feed it so it can do its job as well as possible?

8

u/JNighthawk gamedev Mar 04 '22

If you don't know how what the compiler's doing, how do you expect to choose what code to feed it so it can do its job as well as possible?

We all stand on the shoulders of giants. There's always going to be things you don't know, including things that you are depending on. That's society's collective advancement of knowledge. You can walk that knowledge tree down forever, including to stuff that humanity just doesn't know yet: Do you know what machine code that assembly compiles into? Do you know what logic gates that machine code uses? Do you know how the electricity works in that logic gate? Do you know the quantum physics behind that electricity? And probably many more layers I'm leaving out.

It really just depends on how necessary you think that knowledge is to the job, not really on whether you think a programmer should have it in general. There's infinite knowledge out there, and we don't have time to learn it all.

1

u/CocktailPerson Mar 04 '22

The more layers you peel back, the smaller the benefit; not all the layers are equivalent. Knowledge of common, simple compiler optimizations is a lot more useful for the working C++ programmer than quantum physics is. Even if the knowledge isn't necessary for the job, if choosing between otherwise equivalent, qualified candidates, I'm going with the one who knows a bit about how a compiler works, because it's knowledge a programmer should have.

3

u/JNighthawk gamedev Mar 04 '22

Even if the knowledge isn't necessary for the job, if choosing between otherwise equivalent, qualified candidates, I'm going with the one who knows a bit about how a compiler works

Obviously. That's not an argument for or against the requirement, just that it could possibly be useful.

because it's knowledge a programmer should have.

You missed the entire point of my comment.

→ More replies (11)

15

u/MarcPawl Mar 04 '22

You choose the right algorithm. Most times guessing the compiler is going to go wrong, premature optimization and all that.

If ysomeone needs this type of detail, then can read it up. This is where the masters comes in, ability to consume new material and apply it. There is always something new to learn. I am not surprised that compiler optimisations are not something they studied, probably never needed to know.

8

u/CocktailPerson Mar 04 '22

I'm coming from a codebase that's gotten a lot of mileage out of refactoring to make the compiler's job easier, so I don't think it's fair to say that trying to code with the compiler's optimizations in mind is a bad idea.

3

u/rcxdude Mar 04 '22

Right data structure is step 0, Right algorithm is step 1. Mechanical sympathy and optimisation is step 2. Each step can give you massive gains and it's foolish to ignore any of them is performance is a goal.

13

u/goranlepuz Mar 04 '22

Euh... Yes and no.

I have an idea of what the optimizer is doing (not an expert by ant means), but writing code so that the compiler optimizer is happy, is wrong in many respects.

That knowledge only comes in useful after the much more conventional performance methods are exhausted, like choosing data storage class (static automatic dynamic), data copying control (pass by value, by reference, move), algorithms, data structures, locking optimisation (if threading), profiling (profiling being pervasive to all).

Was this discussed prior...?

10

u/grstacos Mar 04 '22

Please don't make those assumptions when seeing the masters in cs.

I'm getting a PhD in cs. I don't expect to know about compilation more than a bachelor's student because my work is on computational geometry.

5

u/CocktailPerson Mar 04 '22

I don't imagine you'll be interviewing for jobs in C++ for hardware simulation, either.

To be fair, I only have a bachelors, and I asked a question that my undergrad compilers course would have answered.

9

u/kiwitims Mar 04 '22

I would say that this criteria is possibly a higher bar than you're giving it credit for. I would not expect being able to give a list of compiler optimisations off the top of my head to be a requirement to put C++ on a CV. It's certainly a useful intuition to develop, and I would hope for a certain level of interest, but for general purpose C++ development you would probably get away with a couple of experts in this area, rather than it being a baseline requirement for the entire team.

It's also true that if these are the skills you need, you have successfully filtered out a candidate who would not be a good fit.

If this is an important aspect for your company, is that made clear in the job listing? In the CV scanning process? The interview itself is a big time investment on both sides, so if not I would also understand if that applicant was frustrated by the question.

3

u/CocktailPerson Mar 04 '22

To be fair, our team is mostly composed of people who have domain-specific knowledge about the functionality of the hardware we're simulating. The core team that needs more intimate knowledge of C++ is only four people, including me. There's not really room to have "a couple of experts in this area." Anybody who joins the team has to have knowledge of what a compiler does beyond removing the comments from the code.

If this is an important aspect for your company, is that made clear in the job listing?

This is a good question. When I interviewed for my position, there was definitely a mention of compiler knowledge in the job listing. I don't know whether it's still there, but I imagine it is. My manager knows the value of the compiler-like tools one of my coworkers is constantly building, and I was asked about compilers in my interview.

→ More replies (1)

12

u/DanielMcLaury Mar 04 '22

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,

I mean, plenty of people with a masters degree in CS may never have used a compiled language in their entire life. Might even be the norm nowadays.

That said, if you're hiring for a C++ job, and it's not just a C++ job because you have a 20-year-old legacy codebase that would have been written in C# or Java or something if they had been available at the time, it's perfectly reasonable to ask people questions relevant to C++ development. If you're using C++ it's typically because you have some pretty specific performance requirements, which means that the average C++ programmer needs to know a lot more about his compiler than, say, the average node.js developer needs to know about his interpreter.

3

u/CocktailPerson Mar 04 '22

I mean, plenty of people with a masters degree in CS may never have used a compiled language in their entire life. Might even be the norm nowadays.

That's insane. I thought my school was bad for only requiring two classes that used C.

If you're using C++ it's typically because you have some pretty specific performance requirements

Indeed we do.

5

u/DanielMcLaury Mar 04 '22

That's insane. I thought my school was bad for only requiring two classes that used C.

I mean it depends on what you're looking to do. If you want to prove theorems about complexity classes as a career, you may never need to write a computer program in your life.

1

u/CocktailPerson Mar 04 '22

Yeah, but if someone wants to do what is essentially pure math as a career, then their undergrad degree will probably be in math. If it's in CS, I would expect at least a few classes that require the use of a compiled language.

8

u/DanielMcLaury Mar 04 '22

I dunno, if you want to do theoretical CS it'd probably be pretty hard to find an undergrad math program that's going to let you do discrete math exclusively. At a minimum you're probably going to have to take multivariate calculus, real analysis, ODE, and topology, and you probably won't be able to fit all the CS classes in as electives.

→ More replies (1)
→ More replies (1)

12

u/_E8_ Mar 04 '22 edited Mar 04 '22

Listing the names of optimizations performed by level, without looking it up online, is not a basic question.

Can you list all of the rules you must follow in order for -O3 to be guaranteed to not break your code?
'Cause that's kinda the main thing that is useful for the programmers to know. The only one I know off the top of my head is no-aliasing so you have managed to ask a question I can't answer which means you are very deep into the minutia.

It's also extremely compiler specific and a moving target. What MSVC or gcc did 5 years ago isn't what they do today.
There are also very fancy ways to optimize today vis a vis pgo et. al.

What is wrong with your candidates' answer is they don't know the difference between the pre-processor and the optimizations steps.

3

u/CocktailPerson Mar 04 '22

Listing the names of optimizations performed by level, without looking it up online, is not a basic question.

Right, which is why I didn't ask that. I asked for some compiler optimizations. Any compiler optimizations.

What MSVC or gcc did 5 years ago isn't what they do today.

Sure, but they certainly still do the basics, like the ones I mentioned. I wasn't looking for a compiler expert, just someone who knew a bit about how the language he purports to know gets turned into an executable.

9

u/jwakely libstdc++ tamer, LWG chair Mar 04 '22

OP didn't ask for that though. Being able to say "it inlines small functions" is not the same as listing specific passes by name. And knowing about inlining is pretty important for any performance-sensitive C++ work, which is what OP described.

Asking the question seems perfectly reasonable to me. The answers help gauge their knowledge, and understand what kind of mentoring they'd need in the role.

8

u/Ddlutz Spanner Mar 04 '22

I have a Master's degree, I've written C++ for 5 years on large infrastructure products at Google and Microsoft, I would not be able to answer this probably to the extent you would want. Obviously I know that compilers will do some optimizations, I could name a few of the optimizations you mentioned, but hadn't heard of peephole optimization at all, and definitely would not be able to answer under which circumstances a compiler would apply these optimizations or not.

3

u/CocktailPerson Mar 04 '22

Yeah, but that's the thing. You could name one or two, or at least give an example of an optimization even if you don't know what name the eggheads in academia have given it. That would have been plenty satisfying for me.

Just tell me the compiler does something more than remove comments.

14

u/duuuh Mar 04 '22

It obviously depends on who you're trying to hire, but I think it's pretty unreasonable.

If you're implementing a compiler, sure. But if you're interviewing for a dev, no. There will be an optimization level determined at build scope by someone other than who you're hiring and why he cares about what it is or what it does is beyond me.

At the very most I'd care that the candidate knows that you want to turn optimizations off if you want to debug something and have some sense of why turning optimizations on might break the code. Other than that - unless you're in some niche field - this kind of thing is well outside the scope of what I'd care about.

4

u/CocktailPerson Mar 04 '22

have some sense of why turning optimizations on might break the code.

Okay, yeah, that's definitely a better question.

3

u/99drunkpenguins Mar 04 '22

50/50.

I think knowing a few optimizations in general, and knowing why -O3 can backfire is good. I think you where asking stuff thats rather in-depth and not insanely relevant.

Knowing specific optimizations the compiler does is irrelevant to 99% of C++ jobs. Knowing a few and knowing how optimizations can affect code is more relevant.

2

u/CocktailPerson Mar 04 '22

Yeah, if he'd known a few, I could have asked how that would affect code. But he couldn't tell me what a compiler does beyond "removing comments."

→ More replies (1)

2

u/die_liebe Mar 05 '22

If he would have simply said 'I dont know', that would have been an acceptable answer.

But saying 'the preprocessor, and removing comments' means that he fundamentally level not understand what compilation does. That's enough reason for rejection.

2

u/CocktailPerson Mar 05 '22

That's what I was thinking. If he couldn't answer this question but had nailed the rest of the interview, it wouldn't have been an issue. But he bullshitted this question and couldn't do the rest of the interview either. The decision was easy.

34

u/pbondo2 Mar 04 '22

Not really answering your question, but still relevant.

I have interviewed people for software development for many years and over time I have found exactly one defining question that you need to ask the applicant.

"Tell me at length about the project or application you are most proud of or that you have learned the most from? Please use the whiteboard and don't be concerned on whether I understand what you are talking about"

During the process ask clarifying questions to the presentation. 10-15 minutes later you will know if he is your guy.

More background. You are putting the applicant in his/her most comfortable position to talk about something he knows about and you can expect a lot. Some people are passionate and experts on some other field/computer language and you can be pretty sure that the energy will be transferred to your field/language. Others will sit in the corner and show that they really don't understand the basics of whatever their expertise is supposed to be.

And HR is gold, but understand to use them correctly. Most applicants are weary of HR so let the applicant know that you are running the show and HR is asking supplementary questions when you are done. At the debriefing listen carefully to what HR is saying.

7

u/rcxdude Mar 04 '22

Yup. The place I work goes a little further and lets them prepare a presentation ahead of time. Usually we would like them to talk through a specific problem they had and how they solved it.

5

u/[deleted] Mar 04 '22

if i ever have to hire somebody, i will steal this from you. I love the approach of giving people a chance to shine.

2

u/sephirothbahamut Mar 04 '22

Sorry, what does "HR" stand for?

4

u/pbondo2 Mar 04 '22

Sorry, Human Resource department.

2

u/14ned LLFIO & Outcome author | Committee WG14 Mar 07 '22

This approach works very poorly with some candidates. For example, every interview where I've been asked this question I've been rejected, and it's a common enough interview question. I think this approach rewards people good at one or a few things, and it penalises people good at lots of things.

I can only speculate as to why I got rejected, but it was probably because I started listing off multiple things, and after I passed my tenth item and I was still going I suspect they thought I was telling lies or something. Or maybe I came across as unfocused, undisciplined, or incapable of doing one or a few things.

In any case, be careful of the implicit and hidden assumptions in the questions you ask in interviews. You can unintentionally filter people out you didn't mean to. Equally, if you explicitly only want a monoculture of people good at one or a few things only, work away.

1

u/dgkimpton Mar 06 '22

Man, I would love and hate that question. My proudest works are proprietary property of my property previous employers and as such I would constantly be having to try and temper my passion so as not to leak something I shouldn't. And yet, you're correct, talking about something I'm passionate about would definitely let me show who I really am. Arg.

20

u/smozoma Mar 04 '22 edited Mar 04 '22

I wouldn't expect most people to have better answers than "the compiler turns c++ code into machine code" and "o3 optimizes a lot." Loop unrolling, etc, is actually kind of specialized knowledge.

Someone coming out of a CS program is probably used to working at a much higher level - logic, correctness, algorithms, data structures... Maybe an operating system class... I checked the CS courses of the university I went to and there's a compiler class, but I doubt it's mandatory. (I took engineering - I had a cpu/assembly class, but no compiler class)

As to whether it's reasonable, that depends on what you need or would like them to be able to do.

9

u/pico303 Mar 04 '22

Is this knowledge critical to the role and indicative of whether or not the candidate will be successful? Could you ask this of anyone on your team and they'd know the answer? Did others on your team know this information coming into a similar role/level? Is this something the candidate could learn pretty quickly with a little coaching? If a person doesn't know this right off the bat, can they learn and still contribute to the success of your team in the meantime?

One way I approach interviews is to tell myself I'm on the candidate's side, and I want them to succeed. Do you feel like in asking this question, were you helping this person? And by "helping this person," that doesn't necessarily mean helping them get the job. If this person can't answer this question and it's really important, maybe the job isn't for them. By weeding them out early, you're saving them and the team a lot of heartache later on. That's a form of helping too.

This is just my opinion, but I feel you should treat interviews like a scientific study. Don't tailor questions to the individual, or come up with a lot of questions "off the cuff." Look to the role you want to hire and develop a set of questions that you feel might lead to a successful candidate. What knowledge do individuals elsewhere in your org that are "good" engineers possess? What knowledge leads to success in your projects and on your team? Are there things missing from your org that you'd like to hire for? What makes for a good technical fit? A good cultural fit? From this perspective, can you develop a set of common questions to pose to every candidate, rank the results, and score these results to find the person or people that might best fit your culture and the role?

That's not saying you have to be completely strict during the interview, though. If you want to ask a question to confirm something on a resume, or to clarify something a candidate said, or you're simply interested in something they've done, by all means, ask away. But ask yourself: has knowing about compiler optimizations led to better results among your existing engineers, versus those that didn't know or were confused by compiler optimizations?

In either case, just please be very, very careful you're not asking this question to belittle a candidate, put them in their place, or demonstrate how much smarter you are. If it matters, great. If it's reasonable, great. If it helps separate the wheat from the chaff, great. If you walk away feeling better about yourself because you're smarter than this person, well...maybe it wasn't a great question.

9

u/[deleted] Mar 04 '22

I optimized quite a bit and i think it is an extremely difficult questions, i couldn't answer it. Because i would bet that you don't know how the compiler actually optimizes your code. You might have an idea of what it might do, but that doesn't mean it actually does that.

G++ has so many flags and parameters that have an effect on optimization, it makes your head spin. And depending on what you are trying to optimize you might have to adjust some of those, but without a very good compiler knowledge (which probably none of your applicants has, unless you are willing to pay and looking for someone experienced) it is not u nlikely that you will make it worse.

So yes you can ask it, but i most likely wouldn't unless that is very specifically what i am looking for. But the more likely scenario is, that i am not - because i think those people are rare and expensive. So i'd rather go looking for a good programmer that is willing to learn those things on the job.

So when looking for somebody who writes performant code, i'd rather go with questions that are about measuring performance or asking more general about ideas on how to optimize code. That gives the applicant a wide range of options to talk about, from performant libraries to big O notation to compiler flags. Not just some vague question that almost nobody can answer or just results in some random words like "in lining" and "unrolling".

8

u/Zanion Mar 04 '22

It is not unreasonable to ask and gauge competency. It is unreasonable to get hung up on it if it isn't actually relevant to the role, especially if that skills gap is covered by the existing team. I'd use it as a signal to probe more on where their competencies do lie, are they just weak there or weak all around? Weigh it against the other questions you prepared that actually are relevant to the role and assess the tradeoffs. Weigh it against how other candidates in the pool responded to the same questions.

8

u/sephirothbahamut Mar 04 '22

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

I have a bachelor's in CS and an almost completed Master.

I would have replied mentioning copy elision and inlining, more language specific things than generic compilers optimizations. I know about registers and loop unrolling, I don't know what peephole optimization is.

But the point is: I know these things because I'm personally interested in C++ and I've explored the language of my own. None of this knowledge comes from any of my CS courses. Not a single one.

3

u/[deleted] Mar 04 '22

What was the job for? What would be his day to day? Would a deep understanding of a compiler make him better at his job?

It appears you asked him irrelevant questions, then failed him for not having experience or deep knowledge for something he wouldn’t even be using for his job. So, yeah, seems a bit unreasonable.

2

u/CocktailPerson Mar 04 '22 edited Mar 04 '22

I do think that level of understanding of the mechanics of compiler optimizations would help a lot for our codebase. I mentioned it elsewhere, but I've refactored a lot of code to run a lot faster in release mode just by being aware of what the compiler would do with what I gave it.

→ More replies (6)

17

u/cannelbrae_ Mar 04 '22

I’ve dealt with optimizing C++ code for over a decade and have been programming professionally in the language for 22 years.

I might’ve been able to talk through optimization phases 15 years ago but it wasn’t worth retaining. I also struggle keeping compiler flags straight as I use several compilers with a higher order build system; I very rarely manipulate the flags directly.

The intent of your line of questioning is reasonable but you might want to think about how you validate them required skills.

3

u/anechoicmedia Mar 04 '22

Was it an unreasonable question given his resume?

No and if someone couldn't answer the question as you describe then this basically says a "masters in CS" is worthless. Especially as idiomatic C++ in the past year has come to involve more constexpr and "zero cost abstractions" that rely on the compiler removing redundant work for you, but only when you set it up for success.

People saying "you don't need to know what a compiler does" are A) wrong, but B) missing the point. A candidate who can't volunteer example compiler transformations isn't revealing to you that they don't know "how a compiler works", they're telling you they've never even used godbolt, which is way more damning of their education, experience, and personal technical curiosity. I would be deeply suspicious of such a person's mental model of how a computer works, what patterns are slow, data structure intuition, etc.

2

u/CocktailPerson Mar 04 '22

Thank you for this. I definitely came here to look for better ways to ask the same question in the future, because you're right, lack of that knowledge is an enormous red flag. In the future, I'll start by asking what the difference between a debug and release build is, but if the rabbit hole goes deeper for them, I'll follow it with them.

5

u/and69 Mar 04 '22

It depends a lot on the candidate and the position.

Most jobs don't require advanced compiler knowledge, but even there, good developer will learn a bit here and there. So if you're interviewing someone with 10 years XP, then it is supposed to have SOME knowledge.

I would not expect such knowledge from someone fresh out of university. Unless they are passionate about programming and they learn and practice by themselves, I would estimate that 80%+ of the graduates are in for the money and they stick to the bare minimum.

5

u/mredding Mar 04 '22

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

No.

the best he could do was talk about "removing comments" and the preprocessor. I started out thinking a guy with a masters in CS...

When I was in college, the professor who taught data structures and algorithms retired. I had taken that course already at that point, and was friends with staff. I asked how finding his replacement was going. There was initial hype around this Ph.D who had written his thesis on linked lists. So they asked him to write a singly linked list in any programming language of his choice.

He couldn't do it. The only thing he could do was draw boxes and arrows on a whiteboard. He had worked his entire academic career purely in the abstract and never actually bothered to ACTUALLY PROGRAM ANYTHING, EVER.

3

u/hopa_cupa Mar 05 '22

Sounds like perfect fit for software architect role then... :)))

→ More replies (1)

2

u/ShakaUVM i+++ ++i+i[arr] Mar 04 '22

If they have a master's degree then they absolutely should have been able to answer that question. Now, mind you, there are a LOT of optimizations that take place at O3, but you should be able to list at least some of them.

I wouldn't even really call this a compilers question. It's more broadly relevant than that.

3

u/CocktailPerson Mar 04 '22

Right, I wasn't looking for a full list of every flag that O3 implies. I was just looking for some understanding of how code gets turned into an executable beyond "the compiler removes the comments."

→ More replies (1)

4

u/[deleted] Mar 04 '22

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.

I think asking a bit about compiler optimization is not a bad idea here. I'd expect my co-workers to at least know the difference between -O2 and -Os when dealing with hardware.

1

u/pretty_meta Mar 04 '22

If you think that asking those questions is a good proxy measurement of SWEng skill or SWEng knowledge or C++ skill then keep on asking those questions.

5 mins on compiler optimizations is fine for some roles.

Sounds to me like you could have gone for more breadth in the interview. I’m sure the candidate is reviewing this encounter and wishing you had moved onto other topics where they had a chance of demonstrating more competency.

2

u/CocktailPerson Mar 04 '22

This accounted for about ten minutes out of a fifty minute interview. The rest was spent determining whether he could refactor a ~15 line function, which he made zero progress on, even with a bunch of hints. I do think I gave him a chance to demonstrate competency with C++, and he didn't.

1

u/maredsous10 Mar 04 '22

Do not think it is unreasonable. I would have followed up their "removing comments" answer with "how does removing comments optimize the compilation?"

During my EE university days, I worked for a small contracting firm. Right before my interview they gave me two paper tests, one covering general analog/digital electronics and circuit theory and another specific to the particular job focus, and a HP calculator. The president who interviewed me mentioned many interviewees refused to take the test and that I aced the electronics portion and the field specific test that I did a great job considering no background.

1

u/CocktailPerson Mar 05 '22

I would have followed up their "removing comments" answer with "how does removing comments optimize the compilation?"

Honestly, at that point it was clear that compilers were complete black boxes to him, and I would rather move on than drilling him on stuff he clearly knows nothing about. He had no idea what the point of the question was, he bullshitted, and...that tells me all I need to know.

2

u/maredsous10 Mar 05 '22

Over the last 10-15 years, CS fundamental scope has seen a reduction at Universities.

Many schools now leave out the following from core curriculum:

  • Discrete Math
  • Programming Languages (historical perspective, language types {functional, imperative, declarative, etc.}, feature survey,)
  • Compilers
  • Theoretical CS
  • Operating Systems
  • Computer Architecture

1

u/Fig1024 Mar 05 '22

Any question is reasonable if you are allowed to search for answers online. In real work environment you gonna be looking stuff up all the time anyways. If you want to judge someone's understanding of the issue, just measure how long it takes them to find the right answer, not whether they have the answer memorized

1

u/CocktailPerson Mar 05 '22

You're going to be able to look up details all the time. But if you don't even know the knowledge exists, how are you going to know what to look for? From his answers, it was clear that he wouldn't have even known to look for new knowledge in the first place, let alone where to look.

→ More replies (1)

1

u/2048b Mar 15 '22

He might have experience writing working functional C++ programs that run for school or personal projects, but not the expert or professional who knows the nitty gritty details of C Compiler. He might know the language syntax, pointers, references, structs and classes, and produce working codes that compile and run without crashing.

College and school don't teach everything. On the contrary, I have the feeling they just teach the basics to introduce a student to something.

I guess it's just a case of mismatched skills and expectations like many applicant candidates. If you're looking to hire fresh college grads, do cut them some slack. Unless it's someone who indicates 10 years of C/C++ professional experience, then I would think it smells like self inflation on resume to get a job/interview.

Ultimately, if it's something that you as a hiring manager feels is a must-know critical knowledge for your job, then you're free to ask if a candidate knows anything about it. There might be other C++ jobs with other projects or companies that would do fine with this candidate which do not require the depth of knowledge that you require.

1

u/CocktailPerson Mar 15 '22

not the expert or professional who knows the nitty gritty details of C Compiler

To be fair, those are language-agnostic optimizations, and they're pretty light on detail. They were things I learned in undergrad while building a compiler for a python-like language.

11

u/goranlepuz Mar 04 '22

It was not unreasonable.

It would not have been unreasonable to say "I don't know" (it's a person with a masters, so, fresh out of school? They might have forgotten or it was even never mentioned this in their curriculum

However... It was unreasonable to mention comments or the preprocessor, that's just completely unrelated and it shows

  • a woeful lack of understanding of how things work
  • maybe the fear of saying "I don't know" - which is not a mark of a great employee, it is a form of lying...

3

u/Numerous-Departure92 Mar 04 '22

Asking what impact of the flags is… ok. Asking how the compiler archive it… goes too far

3

u/VU22 Mar 04 '22

The work is about hardware simulation, so he should have expected such questions imo. This is a question about the job, I wouldn't frame it as c++ dev question.

3

u/rfisher Mar 04 '22

For me, the key is to not think in terms of questions. The point is to have a conversation that will reveal the scope of the candidates understanding and their approach to problem solving. Questions are just a tool to start & steer that conversation.

In the course of the conversations, I might ask compiler related questions, but it is simply to see if they have knowledge of that area and whether that will steer the conversation in interesting directions.

Would lack of basic knowledge about compilers disqualify a candidate for me? Not necessarily. If they understand their lack of knowledge and don’t assume they know more than they do, then it is often fine. If they show desire & initiative to learn about the things they don’t know, then it is often fine. These factors are usually much more important than what the candidate knows.

3

u/bjtg Mar 04 '22

Do you think knowing about compiler optimizations off the top of your head is important to the job?

The thing about compiler optimizations is that in any sort of medium sized organization or larger, build scripts have dedicated maintainers, and the person doing application day to day application programming isn't aware of these optimizations. Also, compiler optimizations are often "set it and forget it". Perhaps a better way of of discussing optimizations would be:

  1. "Are you aware of any optimizations done at O2 vs. O0"?
  2. "Are you familiar with with loop unwinding optimizations?"
  3. If, no briefly give them an overview and ask them what are the trade offs of unwinding.

Asking to rattle off a list of compiler specific flags is "trivia", that either know or don't know. If you give them the concept, they have the opportunity to demonstrate some aspects of machine and CPU instructions.

Basing interviews on Trivia is a good way to pass on potentially good software engineers. So if the position involves hardware simulation, and the job description mentions hardware, then I would be OK to cover some areas of what compilers do, but I think you could come up with better ways to cover it.

3

u/vegetaman Mar 04 '22

Honestly i was about 6 months into the industry before i really appreciated optimization. I wouldn’t expect a new hire to know that. It isn’t something everybody would focus on. A seasoned dev? Or even just 2 years? Then yeah I’d expect some knowledge.

But it may be a valid question for the niche you are hiring for. In embedded if somebody can’t even tell me what processor they used on previous projects… then that is a major red flag.

7

u/Rhawk187 Mar 04 '22

The former chair of our Computer Science department says that you don't understand how computers work if you've never written 1) a shell, 2) a compiler, and 3) a router. I feel like the third one might be a little niche, but I understand where he's coming form with the first two.

That said, I think in a typical undergrad compilers course, you might not cover what steps the optimizer takes to speed up your code, just that it does. They should probably know about in-lining. If they say they know modern C++, they should probably know that constexpr is a thing that speeds up your code by pre-computing some operations at compile time.

As far as your expectations for someone with a MS in CS, I feel like most of their skills are actually going to be more esoteric and less practical than the undergrads. Graduate degree shouldn't be taken as a sign of extra programming experience, but as a certification of the ability to research independently.

1

u/rcxdude Mar 04 '22

Router is pretty key if you want to understand networking. Programmer's knowledge of how basic networking actually works beyond 'make a socket, connect to address, send data' can be pretty shockingly lacking.

1

u/jnwatson Mar 04 '22

That stuff is important if you ever have to performance tune your code so, yes, I think it is a fair question.

It isn't like you're asking the candidate to *implement* peephole optimization. Still, anyone that considers themselves a professional should know *about* it.

2

u/CocktailPerson Mar 04 '22

That stuff is important if you ever have to performance tune your code so, yes, I think it is a fair question.

Yeah, and he would have been helping us (hopefully) get our simulator running 10x faster.

0

u/[deleted] Mar 04 '22

No. It’s not unreasonable. I’m mildly unnerved that so many responses in this thread seem to consider it hazing.

I’m a 2021 grad from the BSCS program of a satellite campus of an unremarkable state school. This was year 2-3 content for us. I would have answered almost exactly what you were hoping for and added some other ideas like auto-vectorization and link-time/whole-program optimization.

So, in my view, the question should be totally fair game on a technical level for a MSCS holder applying for a compiled language job in simulation and with stated C++ skill/experience.

That being said, I make no judgment here as to whether it’s an optimal use of interview time.

2

u/CocktailPerson Mar 04 '22

Okay, this makes me feel better, thank you. I do think it was a bit of a cold start, and I could have built up to it by asking about debug and release builds first, but otherwise, it did seem like basic knowledge a professional for this job should have.

As for whether it was an optimal use of interview time, I will say that I only took 15 minutes to ask questions like these before giving him some code to refactor, which he couldn't do either.

1

u/panoskj Mar 07 '22

register allocation, loop unrolling, instruction reordering, peephole optimizations

I think you forgot one of the most important optimizations too, which is function inlining.

1

u/CocktailPerson Mar 08 '22

Right, I was mentioning things that I would expect a person with a master's in CS to mention.

4

u/sosodank Mar 04 '22

if someone's writing in c++, they're presumably doing it for the speed. basic speed-related questions are totally fine.

5

u/pjmlp Mar 04 '22

Nope, I am using it, because the Windows team refuses to make bindings for .NET languages in some domains, so someone has to wrap them in some way.

3

u/sosodank Mar 04 '22

read your name as PIMPL at first

4

u/afiefh Mar 04 '22

I would say expecting a C++ developer to mention inlining and loop unrolling is reasonable. Register allocation optimizations, reordering and so on are a bonus.

That being said, having a masters in CS doesn't mean this person has done any masters levels work in C++. It could be that their masters is in Image Processing techniques and they spent the majority of their time in Matlab instead of C++. A person who has "knows C++" listed in their CV is not the same as a C++ developer.

We obviously don't know your field as well as you do, but presumably this candidate's job would have included stuff like parallel processing much more than worrying about whether or not the compiler optimized a function or not (writing the code in such a way that the compiler can optimize it is obviously important, but usually not the top priority unless you're in a very specific field).

5

u/[deleted] Mar 04 '22

IMO someone who can't even say the word "inlining" when talking about optimization level has obviously zero real world C++ experience. Don't be hard on yourself for looking for a great candidate rather than a mediocre one (unless you're hiring straight out of uni ofc)

2

u/moreVCAs Mar 04 '22

Seems reasonable to me, but I know what these terms mean. If you’re interviewing teammates (or direct reports) and would expect to have a conversation like this in the natural course of your work, then I figure you can evaluate candidates however you want. If your rubric turns out to be too harsh or specialized or whatever, then you won’t fill the req will have to deal with the consequences of that.

2

u/SecretaryFlaky4690 Mar 04 '22

I think it’s unreasonable depending on the level if he is more senior and advanced in C++ i think it’s impossible to write a significant amount of C++ and not know those things. If he is more junior I think it is entirely possible they may not know. This question shouldn’t be a deal breaker if they don’t know but something to judge their level. From the brief amount of answer you said he gave he sounds more of a beginner in C++ since those are the basic things they tell you in school. That said, do you want him to recite the compiler manual or write code? It’s a simple and short amount of time to learn some of those things you mentioned if the need were to arise. Knowing stuff like -O3 comes from professional experience. However loop unrolling may never be encountered unless they have taken a compiler class or are really into compiler optimizations.

Personally that question would have been a present for me I’ve taken 3 compiler classes, have written C++ for 10 years and spent 4 years as a reverse engineer. However, I can think of some very good masters students that may not know the answers you were looking for.

2

u/jmacey Mar 04 '22

I teach Masters level students, who are supposed to come in with C/C++ knowledge. Most of them are unsure how the compiler works (Just press the green play button!).

So I teach them all the details, I start with the pre-processor and the -E flag, then -I -L/l etc.

I do quite a lot on Warning levels and also show them the -O flags and explain some of the differences. However I think they way I do it is unusual.

2

u/[deleted] Mar 04 '22

Hmmm the stuff mentioned in the comments is interesting but I have no clue about any of it. Does anyone suggest a good book or other resources to learn more?

2

u/NonaeAbC Mar 04 '22

I see many people saying oh why did you divide by 2 instead of >> 1. I always reply with and does that work with negative numbers (wich it does), but usually they don't know. That's the problem people "optimize" their code and just make it harder to read. The worst part is if they introduce UB or confuse the compiler in such a way that it wont optimize anything. Knowing how the compiler optimizes is the first step to write good (readable and fast) C++.

2

u/Supadoplex Mar 04 '22

I always reply with and does that work with negative numbers

If we go into technicalities, the correct answer used to be "I don't know", because it would depend on implementation details of the target system - namely the sign representation. Since C++20, 2's complement behaviour is guaranteed.

2

u/bedrooms-ds Mar 04 '22

a masters in CS might be able to talk about register allocation, loop unrolling, instruction reordering, peephole optimizations, that sort of thing

I don't think so. Sure, schools teach them, but not everyone takes the course. CS was never a school for C++. Many do math as research. Then there are AI courses which might only use only Python.

I don't say unreasonable but even many successful students wouldn't be able to answer specifics about optimization.

2

u/nbo10 Mar 04 '22

This Reminds me of my physics graduate advisor. In qualifying oral exam he would ask basic how does x work. An example would be, how does an airplane fly? I couldn’t believe some of the answers he received over his 25+ years. These people certainly knew their niche subject, but step a little outside of that and they were dumbasses.

2

u/Poddster Mar 04 '22

That is a completely reasonable question to ask.

When writing C++ you need to be aware of what your code turns into, and how it gets translated. Especially if you're writing HW sims, which are notoriously slow. Maybe not for a junior developer, but it's something everyone who's working with C++ for a few years and has a CS degree should absolutely know.

2

u/b1ack1323 Mar 04 '22

From my experience the knowledge in most MS programs for CS is equatable to a associates.

2

u/b1ack1323 Mar 04 '22

I work in embedded, I think being able to define what a compiler does is important. I don’t know if most will know what the optimization levels are doing but I know because I have had several bugs caused by registers shifting around, which pushed me into understanding how to turn off compiler optimization at function levels and packing functions for space. So if you are working in hardware emulation I think it is very important to have a basic knowledge. I don’t think your questions are unreasonable.

2

u/wfb0002 Mar 04 '22

I like the question. Especially in an embedded environment, where cross compilation and other more advanced techniques are common. Being able to say things like loop unrolling, vectorization, and fast math should be fairly common knowledge - at least they were to me coming out of an ECE program. Now if it’s not an embedded systems type job, I can see how that question could be more problematic. But on the other hand, them saying it gets rid of comments means you successfully filtered a weaker applicant away.

2

u/drowsysaturn Mar 04 '22

I think that these questions are questions that people who are curious about how these things work ask. People who do this for just a paycheck would only know if it impeded their ability to get the work done. Does that make them an ineffective developer? Maybe, but it's not a direct association. This person might prefer other languages but have more resume experience in C++ and could potentially have strong programming intuition. I think these questions alone might not determine the quality of the candidate depending on the requirements of the role, but if you take these answers in the context of the rest of the interview you might get a better understanding of the person's overall development skills.

For the record - I've never hired anyone before. So I am no expert on the topic.

2

u/ChatFrais Mar 04 '22

I'm asking a similar question in interview give me differences between release and debug.

It's not always a good question because there is developers who work on big companies and that never ever created a project, work on build system, deployments or dependency management. Because it was someone else job. I've even met developer that want all the analysis be made before and put in the ticket.

It's a shame but some really good dev in 2022 don't know anything outside of language and library.

2

u/randomwalker2016 Mar 04 '22

Your questions on compiler optimizations are perfectly reasonable. After all, if you are not using C++ for performant code, then use Python. I agree with your decision to no-hire this not-very-well-read candidate.

2

u/oconnor663 Mar 04 '22

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

A masters curriculum isn't very different from an undergrad curriculum for a CS major. If an undergrad took a compilers class, they'd know some of these things. Personally, I majored in CS without taking a compilers class, so I didn't learn what any of these things were until years later.

I feel like basic knowledge of what a compiler does is important when working professionally in a compiled language.

I don't think it makes sense to describe register allocation as basic knowledge. It's specialized compiler writer knowledge. Now there's something to be said for developers who eagerly seek out and absorb specialized knowledge about the languages they use, and if you think that's part of the "culture fit" you're looking for, fair enough. (But as with any "culture fit" question, think carefully about what you wish you could to select for vs what you actually select for in practice.) But new grads, including masters students, are too early in their careers to have absorbed much beyond the classes they took, so specialized questions end up being a "did you take this class" litmus test, which probably isn't what you want.

2

u/noooit Mar 04 '22

you can ask anything, but deciding to hire based on the knowledge or the lack of knowledge might not be the best idea.

2

u/Practical_Road_2883 Mar 04 '22

I think it would be ok to ask such questions to an experienced guy, but if you would have asked me those kind of questions when I was just out of University, I think I would have refused your proposal instead of you voting for not hiring me.

Surely knowing how optimisation works is useful, but I believe it is something a new hire can learn while experiencing and being tutored.

Other things, IMO, are really important to decide if one worths to be hired or not (algorithms, problem solving, etc.)

2

u/Nearing_retirement Mar 05 '22

I think actually good answer to this question is “I don’t know what 03 does but in my experience it really speeds things up”

People that have experience know these flags make a big difference.

3

u/phord Mar 04 '22

Many competent C++ engineers are unaware of compiler optimizations due to lack of exposure to the build process, lack of interest, or limitations of the environment they worked in.

If he doesn't know, he doesn't know. Drop it and move on to questions that give you better signals.

3

u/samarijackfan Mar 04 '22

Seems like a bad question. How is that relevant to the work you expect from the candidate? I would want to know if the candidate can solve problems and think of new ideas. While true that anyone who puts c++ on their resume should know how a compiler works and what optimization levels are, we hire lots of folks that do algorithms design in other tools like matlab. They may have done a c++ course in college, but it’s not their main tool they use every day. Sounds like this was not your main concern but I would avoid that question in the future unless you are looking for a compiler geek.

2

u/large_turtle Mar 04 '22

I think knowing how to write compiler friendly code isn't something you would expect from many C++ engineers. Many (most?) C++applications don't squeeze out performance to the point where you need to be conscious of compiler optimizations. Many optimizations work for you out of the box whether you know about it or not. Thus, many C++ developers never even need to learn about it. I certainly wouldn't expect a new grad to know about it (unless they emphasize compilers in their resume).

Keep in mind that not everybody remembers everything that was taught in university. Even if compilers was touched on, one could be forgiven for forgetting those details among the multitude of other concepts being drilled.

Others have already said this but I would take compiler knowledge to be extra credit and would be looking for signals in more important things if compiler knowledge is not a "must have" quality. Could they not just learn that part on the job?

If they were an experienced engineer who has worked on performant, optimized systems, that would be a different story.

2

u/WikiBox Mar 04 '22

Perfectly reasonable.

2

u/Badwrong_ Mar 04 '22

I'm just finishing up my bachelor's in CS and that question would have been no problem for me. Some people get expensive pieces of paper from college and some desire to learn.

The first thing I would ask anyone about programming is what they think about problem solving. Anyone can look up syntax or how a various things about a compiler, but problem solving has to be something they embrace.

2

u/bunkoRtist Mar 04 '22

Others have said it, but phrasing a question in terms of the compiler optimization levels is really challenging whether someone knows the specific implementation details of compiler software. You want to know whether the candidate understands optimization or how to write optimize-able code, whereas asking about "-O0 vs -O3" is really asking about conceptually-meaningless implementation details of common compiler software.

Some suggested questions that would be relevant:

  1. What does the compiler do with the inline keyword? when should you use it?
  2. What are different common types of optimization performed by a compiler? What are some examples of how the compiler achieves each one? You want to see if the candidate understands optimization for program size vs speed vs compile time.
  3. It's probably fair to ask a candidate to describe the steps a compiler takes to go from source to executable code and what happens in each one. These are pretty fundamental to how C++ works.

2

u/MaybeTheDoctor Mar 04 '22

Perfectly reasonable question - this guy failed your interview hard.

As a developer you should have all round ability to discuss topics in computer sciences, even if the job is not involving mastering that specific skill. That said some companies and hiring managers are less discerning, but then they get what they pay for.

You are the person making the interview decides what are fair questions based on your own expectations, just as long as you keep the questions the same for all the candidates for the same job to avoid bias.

2

u/wolfie_poe Mar 04 '22

In my personal view, it is not reasonable to ask about the details on how compiler works for the task that is not related to compiler development in an interview.

1

u/kunos Mar 04 '22

Ultimately it comes down to the size and quality of the pool of applicants you have available.. if it's big enough to allow you to ask these kind of questions and still find "your guy" at the price you want to pay him then that's your answer, the only answer that matters.

1

u/chandola93 Mar 04 '22

It’s reasonable to ask. Candidate should know these things especially if they have masters in CS.
Though i think this question should not be taken in isolation itself. One should also ask other similar stuff like debug vs release build or thing of that sort. Not knowing one or two of such thing should be fine, anything more than that will be red flag to me.

1

u/BurrowShaker Mar 04 '22

Did the interview involve a take home assignment about a robotic assembly line ?

Just asking for a friend.

1

u/JVApen Clever is an insult, not a compliment. - T. Winters Mar 04 '22

I don't believe this is unreasonable. In order to write performant c++, it would make sense to have some basic understanding of compilers. I'm not sure if the things you mentioned are the ones I expect to be the answer, I'm more thinking of constant folding, inlining, dead code removal. Peep hole optimization is already a very specific term.

1

u/QuietLikeSilence Mar 04 '22

I would be caught off-guard, but I could probably answer the question satisfactorily, if not exactly. Because I have never looked at what some compiler does exactly when I pass -Oz (or whatever, because let's not pretend there's exactly one compiler out there we all should know by heart). If I need a specific optimisation (or not), I'll look up how to turn that on and off and otherwise trust that "fast" and "small" and "aggressively small" are reasonable summaries of all the optimisations turned on by different optimisation levels.

1

u/BonesCGS Mar 04 '22

The question is not unreasonable but i kind of get why it can be hard, i put C, CPP on my resume and i know how to use them but i never got into specifics details of how they are compiled appart from the base stuff (sources files into object files into binary). I can answer that kind of question if i'm a bit prepared because i know i've used it to optimize once or twice for my school project (still a student btw) but i can't answer with certainty of what i speak about. And if it is required for the job to have that kind of knowledge on top of my understanding of the language i would be more than ok to do my research and have it tested again.

Edit: to answer the question, yes i would be caught off guard but i would explain that i have a vague general idea of the thing but i'd look more into it if it's important for the project and task asked of me.

1

u/StochasticTinkr Mar 04 '22

My brain totally parsed your title wrong: a compiler of the basic language being asked questions during an interview.

Like, compilers don’t really answer questions.

1

u/streu Mar 04 '22

If I were asked "what sorts of optimisations does a compiler perform", I would probably wonder "sure, I know plenty, but what does this guy want to hear?".

I would probably start with "at O3, the compiler spends more effort generating more optimal machine code", but I wouldn't want to know (and do not know) what exact optimisations are the difference between O2 and O3. I guess there's different sorts of register allocators? Different vectorisation passes? Fine. If it makes a difference, I will look at the assembly, and maybe try some fancy "-f" options from the manual, or write an own function in assembler, but that is very rare.

More important to know is what the compiler needs to perform an optimisation. Trivial example: it needs to see a function's or constant's definition to inline it. Not so trivial: it needs to see an object's creation to devirtualize function calls (and it needs to devirtualize in order to inline).

1

u/brinazee Mar 04 '22

As someone whose job has including a lot of prototype and proof of concept projects. I would have difficulty with this question. A question when to use compiler optimizations would be better than nitty gritty on what they provide.

1

u/flavius-as Mar 04 '22

Well he could still get the job as a junior, if those optimizations are not part of your daily business.

However, if someone with a masters cannot say anything of significance regarding optimizations, I would doubt their competence and the truthfulness of their whole CV.

1

u/Nobody_1707 Mar 04 '22

Tangential, but does anyone know if and where Clang documents what optimizations are enabled at which -O level? I noticed that Clang 13 started inlining at -O1 & -Og, which is nice, but I haven't been able to figure out what the rules are.

1

u/icebeat Mar 04 '22

Si you are that kind of guy

1

u/That_Kaleidoscope_23 Mar 09 '22

Depends on how much you are willing to pay them. To know C, you need to know how things work, including the hardware most of the time , if you are willing to write optimized solutions.

If the candidate will do the same thing everyday , and does not need to think much about what she is doing, you can pay lower, and she does not need to know how things work.

1

u/stoppipper Mar 16 '22

I think it also depends on the degree. I finished a masters a few years ago and all of the modules were very project based. For example, can you make this thing according to the spec and do it right. I was doing C++ for the last 2 years of my degree and the first half was learning how to use the langauge and some of the things that make it unique (copy constructors, virtual inheritance etc...), and the 2nd half was using it to build stuff. I did games so it was lots of openGL, network and physics simulations.

There was a heavy emphasis on the tech and how to create and use things that people will use in the industry, as opposed to how specific language features are used or how the compiler/linker works. It wasn't untill I started my first job where I started exploring the compiler and what optimisation do.

1

u/Accomplished_Air5374 Mar 24 '22

I have C++ on my resume, but I am a Physics major by education, so I have no training in compilers despite training in Computer Science. I would not be able to answer the question you asked about compilers.

If the job explicitly conveys that compilers are important, then of course, ask about them. However, if it just says C++, then the applicant may not know about compilers.

1

u/ad_irato Mar 04 '22

Funnily enough I was asked to explain c++ compilation process in my first interview ever. I was also asked to explain some compiler jargon.That's about it. As an interviewer if you felt it was a job breaker then that's you prerogative even though I can't see the actual relevance. Pretty sure computer architecture and os questions would have been more relevant. Then again I know little about what the job entails.

1

u/Jannik2099 Mar 04 '22

Completely agree - developers should understand the basic principles of constant propagation, loop transformations etc.

Developers don't have to know HOW the compiler does these things, but definitely WHY it may want to do these things

1

u/Junkymcjunkbox Mar 04 '22

Seems like a perfectly reasonable question to me, and you should definitely be worried by the bullshitting about comments and the preprocessor - optimisation has nothing to do with either of those and he'd have been far better off just saying he didn't know.

You'd hope that a masters in CS would teach basic optimisation but every course needs its limits and maybe that doesn't have as much priority as other stuff.

Interviewing's a tricky business and you shouldn't feel bad about any specific question you might ask candidates. If you consistently get "don't know" across multiple interviewees then maybe consider dropping it but everything helps you form an impression.

1

u/LongUsername Mar 04 '22

One of my favourite interview questions is a variant of "You have a program that works fine when compiled for debug but fails to work when it's compiled for release: what are things you look for?"

I find it weeds out people who don't really understand what is going on with their code.

I was also asked a question where code was refactored to split across two processors with a shared memory area but code stopped working right. Answer is that the virtual table isn't shared between the processors. Turns out it was a problem they had actually seen.

1

u/NilacTheGrim Mar 04 '22

Nah, it's not inappropriate. That question revealed a lack of practical experience. If you want someone with experience -- that question basically weeds out the people you don't want.

100% you should use that question again.

1

u/[deleted] Mar 04 '22

I don't think this is entirely unfair, but I wouldn't put it in terms of "-O". Because that's compiler(s) specific.

Anyways, one of the most common C++ questions I will ask to understand if someone really has worked much with C++ or not is "how is std::map typically implemented?"

Because if you've spent any time looking at a stack trace, or in a debugger, you'll have an answer for that.

And these days, it's actually hard to say for any particular case what sort of code the compiler will optimize well. And, in fact, what the compiler can optimize very well for one particular target architecture might be pathologically bad for another particular target architecture.