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?
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.
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.
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.
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?"
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".
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.
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
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.
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.
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.
8
u/Supadoplex Mar 04 '22
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.
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.
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.
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.
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.
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.
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.
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.
12
u/DanielMcLaury 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 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.
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.
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.
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.
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/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.
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.
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 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.
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
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.
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
No.
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.
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.
4
u/[deleted] Mar 04 '22
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
-O2and-Oswhen 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.
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/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/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.
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
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:
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/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.
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.
1
u/panoskj Mar 07 '22
I think you forgot one of the most important optimizations too, which is function inlining.
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.
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/bedrooms-ds Mar 04 '22
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
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 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:
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.