r/cpp • u/CocktailPerson • 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?
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 writingx operator| y[sic] instead ofx | y.→ More replies (4)5
u/cleroth Game Developer Mar 04 '22
x operator| yWell this is enough info in itself.
→ More replies (1)
33
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
→ More replies (5)
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".
→ More replies (11)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.
→ More replies (2)
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.
→ More replies (1)
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.
→ More replies (2)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.
→ More replies (2)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.
→ More replies (5)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.→ More replies (2)
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.
→ More replies (5)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”.
→ More replies (1)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.
→ More replies (2)
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.
→ More replies (1)
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.
→ More replies (14)0
Mar 04 '22
[deleted]
→ More replies (17)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 (3)37
u/BinaryIdiot Mar 04 '22
I've been writing in C and C++ every day for a while now. When I want to tweak the output of the compiler I just look up the flags. If I need extra debug info I just look up the flags.
IMO I see zero value in memorizing any of these flags. You can just look them all up really easy. Usually I apply them to my make file or my Visual Studio project and then forget about them until I need to look up another change one day.
→ More replies (7)
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.
→ More replies (13)→ More replies (1)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.
→ More replies (1)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.
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.
→ More replies (2)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.
→ More replies (1)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.
→ More replies (3)
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.
→ More replies (4)5
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.
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
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
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
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.
→ More replies (1)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.
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:
"Are you aware of any optimizations done at O2 vs. O0"?
"Are you familiar with with loop unwinding optimizations?"
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.
→ More replies (1)
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
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.
→ More replies (1)
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
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
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
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:
What does the compiler do with the inline keyword? when should you use it?
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.
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/patrulek Mar 04 '22
How often do you change optimization flag in your project?
5
u/CocktailPerson Mar 04 '22
I'm not sure how that's relevant, but we do the standard debug with
-Ogand release with-O3.→ More replies (2)
-1
u/mikey10006 Mar 04 '22
EY yo what....is this a job to make compilers? Or sumn
3
u/CocktailPerson Mar 04 '22
No, but it is a job that involves using them.
r/drunk is that way
→ More replies (1)
-2
Mar 04 '22
Sadly there are way way too many schools with Computer Science degrees that never get to real hardware issues. Also, if you hired him to be a C++ programmer to do X, and they can talk about X... does it matter if his school shorted him on his degree? If he has a computer science degree then they shoudl be able to at a high level make the code more efficient, and some training on the hardware if it is specialized shouldn't be that hard.
Now if it was a degree in computer engineering or something like that, yeah.. giant red flag.
2
u/CocktailPerson Mar 04 '22
Now if it was a degree in computer engineering or something like that, yeah.. giant red flag.
Yeah, actually, his undergrad was in computer engineering, but from a school in India, so I have no idea what that counts for.
2
Mar 04 '22
I doubt many computer engineering curricula put a heavy emphasis on compiler optimizations.
those that do probably leave out other content that other universities thought important.
→ More replies (2)3
u/CocktailPerson Mar 04 '22
If you take a compilers course, it should include discussions of compiler optimizations. Whether you think a compilers course should be required for a CE degree is a different question.
→ More replies (2)3
u/idontappearmissing Mar 04 '22
Now if it was a degree in computer engineering or something like that, yeah.. giant red flag.
I don't know about that, my computer engineering program is much more focused on hardware. The most my CS classes have taught me about compilers was how to use GCC from the terminal and basic CMake. I'm not required to take the course on compilers, but I believe that computer science majors are.
→ More replies (1)
0
Mar 04 '22
[deleted]
3
u/CocktailPerson Mar 04 '22
I spent about ten minutes on this question. I would have spent less, but he kept asking for clarification even after it became clear that he didn't know anything about compilers. If he'd said as much, I would have moved on immediately. If he hadn't said anything about comments when asked about optimization, I probably wouldn't have made this post in the first place.
The rest of the interview was spent determining whether he could refactor a small function, practically verbatim from our codebase. He couldn't.
I'm sure that if you or your friend were in the same position, you would have nailed the coding part, and I would have recommended you wholeheartedly. But go on.
0
Mar 04 '22
[deleted]
→ More replies (2)1
u/CocktailPerson Mar 04 '22
That's fair, and if you'd answered like that, it would have been clear that you at least understood the question. This is a hardware simulation job, though. I'd expect you to be able to expand a bit on what it can do at the "translating to machine instructions" step to make it run faster on a physical machine.
0
Mar 23 '22
[deleted]
1
u/CocktailPerson Mar 24 '22
I was surprised too, which is why I asked this in the first place. It did seem like his masters was focused on machine learning, but he also had professional experience with hardware simulation and had a bachelors in computer engineering, so I have no idea what happened there.
0
Mar 04 '22
[deleted]
5
u/CocktailPerson Mar 04 '22
Are you hiring this candidate to optimize your codebase? No...
Yes, actually. The speed of our simulator is our top priority right now. Anybody we hire will be working full time on making it faster.
You have one guy who knows absolutely everything.
It's quite the opposite. I want to hire candidates who have deep skills in a few areas and a broad understanding elsewhere. I want him to be able to optimize code even if it's not his primary responsibility or his best skill.
That said, as I mentioned, it will also be his primary responsibility.
0
36
Mar 04 '22
[removed] — view removed comment
7
u/CocktailPerson Mar 04 '22
Definitely take a compilers course if you still can. 100% worth it, IMO, even if all you learn is how to write a recursive-descent parser. I use that skill remarkably often.
13
u/snerp Mar 04 '22
What field are you in where you're frequently writing parsers?
7
u/CocktailPerson Mar 04 '22
For simulating this sort of hardware, you basically need to have a huge set of classes that mirrors the physical hardware's register hierarchy. Since it's so massive, it's easier to generate the class hierarchy from the register specification than it is to write it up by hand. We have to parse the register spec and output an equivalent set of classes. A similar issue exists for the connections between various units within the chip.
So it's not so much that we're constantly building parsers, it's just that we've had to build and maintain more than one.
15
u/AVTOCRAT Mar 04 '22
It's a lot easier to accidentally write one than you think: DSLs are very common, JSON serialization/deserialization 100% counts, JavaScript transpilers are all the rage...
1
1
u/edgyBouchi Mar 08 '22
Can you suggest some good compiler courses or study material?
1
u/CocktailPerson Mar 08 '22
Unfortunately, not really. I took a compilers course during undergrad, and all the resources I know of assume that level of knowledge. Starting from scratch is a bit more difficult. But it looks like Stanford has a free course.
1
u/tsojtsojtsoj Mar 04 '22
In my computer science bachelor degree I took a compiler course but optimizations weren't part of it. You'd probably take an extra course for this.
24
u/RevRagnarok Mar 04 '22
The only "blacker" Black Magic I've seen in my career when compared to compiler optimizations would be FPGA routing. As far as mere mortals are concerned, both of them have transcended Clarke's 3rd law - "any sufficiently advanced technology is indistinguishable from magic."
5
u/imMute Mar 04 '22
Honestly, once I learned what P&R is, the problem itself isn't terribly difficult to understand. The problem is finding an efficient way to solve it. And that's where I throw my hands up and go "you find smarter people than me!"
5
u/theICEBear_dk Mar 04 '22
The basic passes are often described in compiler construction literature, but since the passes and subpasses within each optimization level changes each compiler release having to know exact passes in each phase would throw any candidate I've ever interviewed (and me in any interview I have given).
But yeah anyone working near hardware must know the general semantic intent behind optimization level (O0, Og, O1 and so on) but also that debug is tied to -g and you can even change the amount and type of debug output (some embedded tools are stuck in the past in terms of types of DWARF they read).
It is interesting also that the types of possible optimizations are different depending on the language in some cases since the languages can express different intents and needs. For example C++ often suffers when using virtual interfaces but since the newer language features can express if a virtual is final or overriden the devirtualization passes can do more with final than not... in theory at least. And I recall Rust had some opportunities for optimzation that was not fully utilized by their compiler because of lacking optimization passes and rust exercising pasts of llvm that had been coded and tested using C++. The dlanguage has a tonne of information and guarantees about pure code that could let gcc and llvm optimize the code more as it is known to be without side effects and so on it goes. It is a very interesting subject but there is not a lot of publications about it that reaches engineers like me (I am sure the academic world knows a lot more here).
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.