185

I recently had a job interview in which they gave me an hour to write some real code. It wasn't a huge amount, probably less than 100 lines. After about 45 minutes, I compiled, ran it, and got it to work. I may have spent 5-10 minutes working out compile errors and a couple minor bugs, but overall it was very smooth. (Incidentally, I did get an offer from them.)

However, what puzzled me was that after I handed over the completed code, the interviewer told me that the only thing I did wrong was "not compiling as I go along". I asked him what the difference is, and he said "what would you have done if you finished the code and it didn't compile in time".

In my understanding that's an invalid argument, because "getting code to compile" for a given length of code generally involves fixing a constant number of compile errors and takes a fairly constant amount of time, which should be the same whether you do it after you finish writing the code, or if you interleave it with your coding time. If anything, interrupting your coding to search for missing semicolons would probably be detrimental to your efficiency. Except in extreme circumstances when I'm experimenting with obscurities around edge-cases on things like virtual functions in derived classes, etc. it seems reasonable to expect that code written by a an experienced developer will compile, minus the occasional typing error, and even if it doesn't, it's not as if I would have to rewrite a portion of the code in order to fix the compile error.

In another similar incident, I was given an incomplete codebase in an interview, and asked to finish it and make necessary modifications to get it running. I started by reading through the existing code, and then after a few minutes (even before I had finished looking at the code), the interviewer told me that's enough. When I asked him what he would have done (i.e. "what did I do wrong"), he told me that he would have started by immediately getting the code to compile.

Why is that even relevant? In my opinion and in my experience, whether or not a piece of code compiles is essentially random, involving things like whether or not semicolons are missing, and has little to do with the correctness of the underlying program. (To me, focusing on compiling is like running an article through a spell-check without proofreading to check the grammar.)

If you give me a piece of incomplete code, the first thing I do will be to read it. I won't even try to compile it until I know what the code is doing and I know the algorithm is correct.

Anyway, these have been just a couple recent incidents, but in general I've heard many developers talk about compiling their code as they go along, and yet nobody has been able to tell me the benefit of doing so. I understand the benefits of testing your code as you go along, but why compiling?

So my question is this: Is there something I missed? Is there actually a benefit to compiling as you go along? Or is this some sort of myth propagated by the software community that you must compile your code frequently?

sakisk
  • 3,377
  • 2
  • 24
  • 24
CaptainCodeman
  • 1,895
  • 2
  • 15
  • 14
  • 1
    Sounds you have problems to change your habits, but you are considering the possibility that those are bad habits. – Doc Brown Jun 23 '14 at 11:46
  • 54
    Either that, or that my habits are being called bad habits by people who have different habits. – CaptainCodeman Jun 23 '14 at 12:21
  • 4
    I think your spell-check comparison is flawed. An article with syntax errors can still be read, but a program with syntax errors won't run. So getting the syntax 100% right (as well as the semantics) is more important in the context of a computer program. – Doc Brown Jun 23 '14 at 12:29
  • And another point are compile times. If the turn-around times are high, it is clear that compiling too often has a drawback. But if you can compile always in between without disturbing your workflow (and in many environments that's possible today, even with C++), then why not make use if the compiler as often as possible? – Doc Brown Jun 23 '14 at 12:34
  • 1
    This seems like a very strange comment to me - if the ONLY thing an interviewer can pick up in a code review is how many times you hit Ctrl-B... Just seems odd! – Liath Jun 23 '14 at 12:45
  • 9
    @DocBrown The comparison is valid if the end goal is having a correct product. A program that "runs" is no better than a program that runs incorrectly. You can't expect the compile to check your code for you any more than you can expect a spell-check to fix your grammar mistakes. – CaptainCodeman Jun 23 '14 at 12:45
  • 1
    @DocBrown It is impossible to compile without disturbing your workflow, because the compiler's messages will necessarily interrupt whatever you're doing! Therefore it seems that with a slow compiler you're actually doubling the problem. – CaptainCodeman Jun 23 '14 at 12:51
  • 1
    @CaptainCodeman Yes, but at the same token it's not that much of a stretch of the imagination to run a document through the spell checker after every chapter. I for one like to make sure that one chapter is completely sorted before I launch into the next. – Jorg Jun 23 '14 at 12:51
  • 3
    "It is impossible to compile without disturbing your workflow" - actually, that is your fallacy (at least when compile times are low). @utnapistim's answer explains it well, why. – Doc Brown Jun 23 '14 at 13:00
  • 7
    Whether compiling disturbs your workflow is very subjective and depends on language, build environment, size/complexity of project etc. IMO more likely to be an issue on large legacy projects. – pjc50 Jun 23 '14 at 13:02
  • And a program that runs incorrectly is better than a program that does not even compile - because you can debug the former, but not the latter. – Doc Brown Jun 23 '14 at 13:02
  • 3
    @Jorg Fair enough and I totally respect that, but I'm saying that the difference is primarily a matter of personal preference, and not something that has a functional effect on your efficiency or output. – CaptainCodeman Jun 23 '14 at 13:05
  • 2
    @CaptainCodeman I'm not sure about that. Your train of thought has moved on from code you wrote 45 minutes ago and it'll be harder to get back into the logic of functions you've left behind by then. – Jorg Jun 23 '14 at 13:11
  • @Jorg Yes but compile errors are largely syntactical and should not have much to do with the logic. I agree 100% that the logic should be checked as soon as possible, but compile errors are usually trivial things that can be fixed in O(1). – CaptainCodeman Jun 23 '14 at 13:15
  • 2
    The operative word being `usually`. I'll agree that this is preference because I have no hard evidence to back this up, but from my perspective there are only advantages to compiling more often. + 1 for a thought provoking question. I'll also agree that this has no place in an interview, I'm more commenting on the coding practice. – Jorg Jun 23 '14 at 13:17
  • 64
    I fully agree with the OP. I can't understand how someone can be judgemental about one's work habits, e.g. when he/she uses to start the compiler. The only thing that counts, is the output of the efforts. Is it correct? Is it maintainable? Does it run in the expected timeframe? How long did it take to implement it? These are the interesting questions. All else is arbitrary BS. If the interviewee writes 2 hours perfect code that compiles on the first try, where's the problem? Just because the interviewer does it differently? My godness. – JensG Jun 23 '14 at 13:18
  • 4
    Compiling regularly seems a prerequisit for "compiling and running" regularly which seems more useful. – Richard Tingle Jun 23 '14 at 13:37
  • 1
    @JensG: when someone here states he can produce good code by 45 minutes without compiling, it does not mean he could further improve and write even better code by changing his habits and compile more often. And the OP was the one who asked this (very good!) question. – Doc Brown Jun 23 '14 at 13:57
  • 1
    Answers to this question really ought to include (a) which languages they might be valid for and (b) what duration of compile time they're expecting... – pjc50 Jun 23 '14 at 14:56
  • 2
    Also fully agree with OP. Actually I'd go further than @JensG ; Frankly, I'd mark up any candidate who naturally "compiles in their head". The OP sounds like he is a fluent reader of code, unlike so many candidates I see. OP should consider whether they really want to work for the interviewer, who may well be less competent that the OP. – Keith Jun 24 '14 at 03:32
  • 7
    @Keith: any dev who believes he can better "compile in his head" than the actually compiler overestimates his own skills. The OP sounds like someone who has got himself accustomed too some bad habits and now searches for justification, though the vast majority here tells him to consider to change his habits. – Doc Brown Jun 24 '14 at 03:43
  • 3
    After 20 years of programming, I can feel when I'm "in the zone" and don't want to interrupt coding to compile. It's hard enough to type fast enough to keep up with my thoughts. Other times, I compile often because I realize I'm making mistakes and/or need the brain downtime. I don't think there is only one "best" way to code. Also, I've only been "let go" once, and it was the owners son who thought he knew everything about coding. Everyone else has tried to talk me into staying longer. Be careful out there. – Guy Schalnat Jun 24 '14 at 03:44
  • 6
    @GuySchalnat: after 30 years of programming I can tell you that people are very reluctant to change their habits when they have >20 years of programming experience, because the believe they cannot learn anything new. – Doc Brown Jun 24 '14 at 03:52
  • 1
    @DocBrown I agree that it is harder to change habits after many years of experience. But there are exceptions, of course. I believe that this industry requires you to be constantly learning. For example, I wrote my first jQuery plugin a few months ago, because it was what the problem seemed to call for. Maybe that isn't the point you were making, I'm not sure, but my point was that there isn't a one size fits all silver bullet here, and that the OP should not have been marked down for doing what he did best. Maybe his brain works differently then the average programmer. – Guy Schalnat Jun 24 '14 at 04:05
  • 1
    @GuySchalnat: fair enough, but this is not about "marking down" the OP for his habits, only for - as it seems to me - not beeing very open to change them. He asked about his current practice, but from his comments it seems he was probably only seeking for justification. – Doc Brown Jun 24 '14 at 04:28
  • @DocBrown - I see your point, having reread some of the comments. Still, I think there is no right answer here in all cases. I try out my incomplete code much more often (not all languages "compile") when I can just refresh a browser as opposed to when I have to compile and publish some Java code, then log into the application and do various things to get my code to run. For future readers, I wanted to point out that the answer depends on the circumstances. All that said, I started out coding at school where I had to wait for a computer. I got GOOD at writing bug free code. YMMV. – Guy Schalnat Jun 24 '14 at 04:35
  • 1
    My best code is when I create as much as possible upfront not worrying about spelling syntax etc.. – MVCylon Jun 24 '14 at 05:07
  • 1
    @DocBrown It is absolutely not about being "better than the compiler". It is more being clear in one's own head exactly what one expects the code to do. Actually by that I mean according to the relevant standard (which one can and should know), not actually according to the compiler (which most of us do not and should not need to). It is by doing this that one has a good chance that the compilation results in the intended behavior. And please also note, I have no actual problem with continuous compilation. – Keith Jun 24 '14 at 06:18
  • 2
    @JensG Although I agree with you, people could say the same about TDD. Why bother writing tests first? What matters is that your code works eventually, and if you test it afterwards it's not worse than if you had thought the test before implementing the interface. Same goes with all XP methodologies. Why do pair programming if you can make it work on your own? Etc. – Pierre Arlaud Jun 24 '14 at 08:27
  • 9
    It should also be mentioned that for certain languages and IDEs (Java/[Eclipse|NetBeans|etc], C#/Visual Studio, ...), the IDE is *already* compiling everything in the background in real time, as you type, in effect giving you an immediate feedback loop as to whether you have made a mistake. One would hope the IDE developers had some research backing this compile-as-you go approach. – Ogre Psalm33 Jun 24 '14 at 15:10
  • Sounds like the first interviewer was basically impressed with your skills, and was just giving you a little tip. That second interview question was rather weird - why give someone an incomplete codebase, that doesn't even compile, presumably with no real explanation of in what ways it is incomplete? When does that happen in the real world? I don't think I would start by getting it to compile, I would read it to try to figure out what had been omitted - just like you did. – MarkJ Jun 24 '14 at 16:21
  • @MarkJ The scenario for the second interview was that they told me "imagine we had somebody working on this order system and he got hit by a bus.. this is his code and we need to get it to work" – CaptainCodeman Jun 24 '14 at 16:38
  • 3
    If the programmer got hit by a bus, the location of compilation errors, if any, should give you a clue as to what they were coding. That should give you and idea were to start reviewing. – BillThor Jun 25 '14 at 04:18
  • I use ReSharper to do this automatically for me. – Uwe Keim Jun 25 '14 at 05:40
  • What language was this? – Jus12 Jun 25 '14 at 13:01
  • @Jus12 C++ for the first story, C# for the second. – CaptainCodeman Jun 25 '14 at 13:21
  • 2
    @CaptainCodeman In that scenario, I would do the same thing you did - read the code. "Immediately getting the code to compile" sounds to me like the interviewer was a quick-and-dirty programmer. I mean the type who hacks code together really fast, compiles & runs it to "find out what it does", and fixes bugs. The coding process ends up being slow-and-dirty rather than quick-and-clean. – MarkJ Jun 25 '14 at 13:44
  • I was told by a developer of live-critical applications that entering code that produces a warning the first time it gets compiled is severely frowned upon where he works and will result in a talk to the manager at least. That's when you write code that will kill people if you don't get it right. Anyway, don't look at it as failing an interview, look at it as a narrow escape. – gnasher729 Jun 25 '14 at 16:18
  • Ideally, you would run tests as you program. Being able to test (or at least compile) the program while it's still not finished means you're chunking your solution well. – Dominykas Mostauskis Jun 25 '14 at 18:25
  • 2
    I wonder if this is a generational thing. In one MIS class I took in 1978, there was an assignment that involved writing a PL/1 program, by punching cards and submitting a batch job. (Some departments still used batch even then.) Each student was allotted $50 of computer time. An aborted compilation due to syntax errors cost almost $10. So we had basically 5 tries to get the syntax and the semantics correct. That made us look at the program *very* carefully before handing it off to the compiler, and that methodology, sort of an anti-trial-and-error, was perhaps what they wanted to teach us. – Mark Plotnick Jun 26 '14 at 15:14
  • @MarkPlotnick When I was training for programming competitions, I used to practice coding using the Linux cat command. Any compile errors or bugs would mean I would have to rewrite everything! I used to be able to do this for up to around 100 lines of code. Now I find it amusing when people can't write code without auto-complete. – CaptainCodeman Jun 26 '14 at 15:40
  • 1
    I think what you are missing are the benefits of the DEBUGGING. Writing long winded untested code might work for you, but using TDD and testing as you go along is not only better for maintenance but also faster. When you are looking for a bug which requires following program flow, if the compiler can't help you, you are on your own sifting through hundreds of classes and functions and overrides trying to get your bearings when what you should do i compile and debug your code. – Mickey Perlstein Jun 27 '14 at 10:19
  • 5
    `he told me that he would have started by immediately getting the code to compile.` The first thing I would do when receiving a new codebase that I knew is faulty is to get it to compile and see what it does wrong. If the code is essentially just a single file, this may not be much difference, but if you have a project with thousands of files, there is no sense in trying to read the code before trying to run it and see what it is doing wrong. All you know, you might be scouring the code for half an hour for what might be a simple missing semicolon that a compiler would've found in 3 seconds. – Lie Ryan Jun 27 '14 at 22:32
  • I compile as I go only because I set up flymake in my emacs environment many years ago when I was starting with compiled languages and I had more semantical errors than syntactically correct lines of code. I generally don't think about it and wouldn't if I was in an interview setting without my tools, however, @LieRyan makes a good point about leveraging the compiler on an unknown codebase. – Steve Buzonas Jun 28 '14 at 10:31
  • @DocBrown: I cannot see how this is about "changing one's habits". The OP is describing interview situations, first contacts with other people who give the OP a code-related task. The OP has no way of knowing what personal preferences each of the interviewers has, so any approach - compiling first, compiling sometimes in between, compiling only in the end - is just as good as any other. During my studies, one of the more practically-oriented classes even presented development without intermediate compiling and testing, and instead a focus on being concentrated and aware of what one is ... – O. R. Mapper Jun 29 '14 at 12:44
  • ... doing as a generally preferrable approach to writing correct and reliable source code as opposed to the naive approach of writing *something* that might be approximately right and then repeatedly compiling and testing to remove the obvious errors (and leave the non-obvious ones in the codebase). In that respect, compiling repeatedly could be classified as a bad habit. Of course, the usefulness of each method depends on the context, and when given a large written portion of code with syntax errors, asking the compiler to detect those is *sometimes* indeed the best way to go. – O. R. Mapper Jun 29 '14 at 12:48
  • 2
    `He told me that he would have started by immediately getting the code to compile.` I'd call that **trial and error**. Sure it may be necessary when an interviewer won't give you much time. But when I'm working on something I care about, I want to understand the code and know what I'm doing in order to write beautiful code rather than "fixing typos and recompile" until it suddenly compiles for some reason. – basic6 Jun 30 '14 at 07:36
  • @DocBrown: To make things more concrete, writing code without compiling is a core concept of the *Cleanroom Development Process* (cf. e.g. [here](http://books.google.de/books?id=S_8Yf1wTKNoC&pg=PA35&lpg=PA35&dq=%22cleanroom+development+process%22+%22development+team%22&source=bl&ots=B6RwZ2KGOL&sig=qORw0TuxotewdFulDekCoMLlSAg&hl=en&sa=X&ei=rCexU9OaNJPX7Abe6oGYBA&redir_esc=y#v=onepage&q=%22cleanroom%20development%20process%22%20%22development%20team%22&f=false) or [here](http://mimoza.marmara.edu.tr/~samet.tonyali/courses/cse344/lectures/week7.pdf)). – O. R. Mapper Jun 30 '14 at 09:04
  • @O.R.Mapper: I don't believe the OP had "Cleanroom Development" in mind when asking his question. Moreover, I looked at your links and can't find anything supporting your thesis cleanroom development means "writing code without compiling". Quite the opposite - the second link mentions "static code analysis" as a key point for clean room development! The compiler does actually some static analysis, and other static analysis tools AFAIK expect a syntactically correct, compilable code. – Doc Brown Jun 30 '14 at 13:12
  • @DocBrown: That may be your interpretation. My first thought upon reading this question was something like: "Ah, someone following the cleanroom approach." That said, the second link mentions (on page 43): "Development team. Responsible for developing and verifying the software. **The software is NOT** executed or even **compiled** during this process." (emphasis by myself) – O. R. Mapper Jun 30 '14 at 13:14
  • @O.R.Mapper: that (academic!) process description is surely not about *efficient* coding. It is about a very strict role separation between development and verification, with different teams, probably separated in those slides just for the sake of the argument (and probably not with the intention that someone should *really* work that way). But the question was what to do when you have some real coding to do, you work alone, you have 45 minutes and 100 lines of code to write. – Doc Brown Jun 30 '14 at 13:27
  • @DocBrown: As I said, I learned about that process in one of the more industry-oriented classes as one out of various practical models to use in actual projects. Definitely meant for being actually used, without the claim that it actually is a lot (as happens with many superficially costly, but actually possibly reasonable things). It is true that if by *efficient* you mean *fast*, this is not the goal of this model, it is rather geared toward supporting reliable and error-free coding. – O. R. Mapper Jun 30 '14 at 13:35
  • From my own experience, I can only add that any dev who goes as long as 45 minutes without validating his/her assumptions about code by not only not compiling but also not running tests, is risking a lot of unnecessary rework and overly complex solutions. In any case, instead of wondering what you've missed, I would advise you to simply try the "other" way of working for a while. If after a month or so, you truly feel you've gained nothing, then you'll have your answer. – Stefan Billiet Aug 31 '14 at 13:42

17 Answers17

221

Is there actually a benefit to compiling as you go along?

There is. It gives you a shorter feedback loop - which in general, when designing (UI, writing software, visual design etc...) is a good thing.

A short feedback loop means you can quickly fix errors early on, before they become more expensive to fix.

To borrow your example, say you were coding in a C-like language and forgot a } somewhere in the middle of the program.

If you compile just after you finish writing the statement, you can be quite certain you have just introduced the compilation error and can fix it there and then, within seconds.

If you don't, however, you would have to spend a good amount of time reading the code, looking for the exact position that the } is and making sure, once you have located the error that the fix is indeed what was intended. This would take place a while after you left that bit of code. It wouldn't be as crystal clear as during the moment you wrote it.


Now, yes, the end result is the same, but you wasted a good amount of time on syntactical issues that the compiler is there to help you with - an amount of time that could be significantly shorter if you compiled as you went along.

samthebrand
  • 368
  • 2
  • 12
  • 27
Oded
  • 53,326
  • 19
  • 166
  • 181
  • 72
    Indeed, for syntactic errors like that, modern IDEs essentially compile and recompile all the time to make your feedback loop as short as it can reasonably go, and it's unreasonably helpful for catching minor mistakes. – Phoshi Jun 23 '14 at 11:32
  • 2
    That's a good point, but I think it applies more to testing than compiling. I've rarely had to spend more than a few seconds trying to find the cause of a compile error, so it seems the additional overhead is not worth the benefit. – CaptainCodeman Jun 23 '14 at 11:33
  • 12
    @CaptainCodeman - I'd say that there are some compile errors that would require you to dig through quite a lot of code. This is more true for larger codebases and larger change sets. – Oded Jun 23 '14 at 11:35
  • 1
    Also, compiler doesn't only give errors but also hints. – Pieter B Jun 23 '14 at 11:42
  • 1
    @Downvoter - care to comment? – Oded Jun 23 '14 at 12:48
  • 29
    Sometimes the compiler gives you a puzzle instead of a hint, such as gcc template errors. – pjc50 Jun 23 '14 at 13:03
  • 14
    @pjc50: absolutely (which is easier to handle by not changing too many things at once before the next compilation, so you know exactly what you have changed at last). – Doc Brown Jun 23 '14 at 13:07
  • 5
    I'm not the downvoter, but your logic seems biased. You will have wasted some time compiling, possibly you will also end up wasting a bit of time investigating errors caused simply by the program being in an incomplete state. I see the theory in mismatched brackets causing issues, I just don't remember the last time I had that issue and it wasn't a quick and trivial fix. Ultimately, if you know your compiler then compile errors are the easy errors, and a test that only catch the easy errors isn't worth spending a lot of time on. – aaaaaaaaaaaa Jun 23 '14 at 17:51
  • 21
    The idea isn't to just compile by random. It's to compile at each significant step, to compile when you expect it to still work properly. For example, I'll compile to test to make sure than objects are being created/deleted properly, or to ensure that events are being fired properly to a new class I created. If I create a class and hook it into my program in some way, I want to make sure I did it correctly before going about hooking more stuff to my app. Less important with small apps, vital for big ones. – Thebluefish Jun 23 '14 at 18:26
  • 2
    @Thebluefish The question is if you should also compile when the program will not work properly, but merely has the semantics to pass through the compiler. – aaaaaaaaaaaa Jun 23 '14 at 18:45
  • 1
    I'll compile when I expect it to be able to compile, but only at milestones as previously listed above. Granted I am spoiled by Visual Studio's error highlighting, so rarely would I need to compile to spot an error. – Thebluefish Jun 23 '14 at 19:01
  • 1
    "You will have wasted some time compiling, possibly you will also end up wasting a bit of time investigating errors caused simply by the program being in an incomplete state" This is only true if you're interrupting your workflow to do these things. Editing text isn't so CPU intensive that a compiler can't run in the background now and then, populating a list of issues that you can look at *when you choose to*. This does depend on the compilation environment, compile times, etc., but it's not, in general, the case that running the compiler, or even just a parser, wastes any programmer time. – Joshua Taylor Jun 24 '14 at 14:42
  • 3
    On the other hand, compiling breaks my flow. It's often more important to get the high-level structure of the code right than catching every little syntax error. – nikie Jun 24 '14 at 14:45
  • 2
    You don't just want to compile often to fix syntax errors as you go; you also want to make sure that the semantics are right, i.e. that your program does what it's intended to. Your code may compile without mishap but produce a completely wrong result. Fixing that may be prohibitively time-consuming. – jub0bs Jun 25 '14 at 00:50
  • 1
    Compiling itself could also be time-consuming. There are some large code bases out there. On an interview question, I'd probably be lazy and just compile it to see if there are any syntax issues or not, then begin analyzing the code. But as a practice at work, that might not be feasible. – Ellesedil Jun 25 '14 at 22:36
  • 7
    These kids today... they don't understand what it's like to have an error 5000 lines below the character that caused it. They should be forced to use C until they understand that, then questions like this wouldn't be asked. Loved your example - did that many times. – user1068 Jun 25 '14 at 22:46
  • If compiling frequently is such a good practice (I strongly agree with that), then what does that fact say about interpreted languages? – Tulains Córdova Mar 11 '16 at 17:12
107

Compiling is a form of test, especially in languages which make extensive use of types such as Haskell or ML. In other languages it's a syntactic scan that tells you little.

Having said that, "compile as you go" seems to me a very situational habit. You could equally well be marked down for being "twitchy" for compiling more frequently than the interviewer's personal prejudice. It sounds like nitpicking; nobody likes to admit that an interviewee has aced the test; it tips the scales of the salary negotiation.

Not all build systems are fast. I worked on a (C++) project where Make would spend 30 seconds just stat'ting everything to determine whether it needed to build or not, and most files would take a couple of minutes to build if you had made changes. We were reluctant to do this more frequently than every 10-15 minutes. Someone will no doubt supply an anecdote of when compiling involved taking your deck of punch cards and carrying them to a different building ...

Compile when you feel you've done a complete conceptual unit in your head and are ready to have it validated. Once a minute or once a week depending on the workflow.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
pjc50
  • 10,595
  • 1
  • 26
  • 29
  • 25
    when you do take your punch cards to the sysops to load, make sure you never ever ever drop them because putting them back in the right order is a real PitA! Ah, for the days when an essential debugging tool was an elastic band. – gbjbaanb Jun 23 '14 at 14:48
  • 3
    When I first started programming I measured my progress by how much code I could write without compiling—essentially by the quality of my mental compiler. At first it was a few characters, then a few lines. Now I don't care about it. I compile a lot for small changes I just want to see the effects of, I compile very little when doing the structural layout of the project. – Phil Jun 24 '14 at 05:48
  • Hmm. Just want to say that a well written C++ file should not take more than a few seconds for compilation. If it's longer, it's a smell for bad code. And if it's so big that make has problems, I would argue that the application is too monolithic. "My" make never had problems, and afair not even when compiling Linux. – phresnel Jun 24 '14 at 11:42
  • 2
    It was 1.5 million LOC when I left. Note that Linux is C not C++; templates seem to be slow in gcc, and if you've done something clever and useful that happens to be slow to compile, there's no easy way of profiling the compiler to work out what it was. – pjc50 Jun 24 '14 at 12:41
  • @gbjbaanb I saw that happen once in my youth. A grad student had a good sized program and/or data set in three boxes of cards in his arms when he tripped and fell on his way in to the computing center. Cards everywhere. And this was Seattle, so the floors were not pristine and dry in the foyer, either.... I started using *two* rubber bands on my toy programs after that, and gained a new appreciation for why the FORTRAN cards had a mandatory comment field starting at column 72. Once his cards were corralled back into a neat stack, he did get them back in order with the card sorter. – RBerteig Jun 24 '14 at 18:06
  • 22
    @gbjbaanb I think it would be better to say "the days when **source control** was an elastic band." ;) – JasonMArcher Jun 25 '14 at 00:08
34

So my question is this: Is there something I missed?

Yes: your mind is not a compiler. While a compiler can make n context switches per second, your mind cannot. The number of context switches your mind can make in a day depends on a number of factors like experience/familiarity with code base, how mentally immersed you are in the code, how clean the code is, how complex is the problem you are tackling, how tired you are, if you are frequently interrupted or in a noisy environment and so on.

Compiling a code base (all at the same time), for the first time (think "project with 20 files") will force you to switch context from what you are thinking about (e.g. "this value is set to 5 here, then in the for loop blablabla, and the complex algorithm yields the correct value on return") to a compilation problem that is completely unrelated to what you are thinking about (different file/module/function/pre-conditions/syntax/variable names, preconditions etc).

The more code you compile at once, the more context switching your mind has to make. This is not a problem for a small code base, when all the code you wrote is whatever you wrote in one hour. It is a big problem though, when working in an existing code base, with multiple (and many times undocumented) interdependencies.

Is there actually a benefit to compiling as you go along?

You minimize the context switches your mind has to make, allowing you to focus more on the impact and side effects of the changes you make. It also makes you less tired (and less prone to mistakes) and increases the quality of your output (i.e. you can guarantee minimized side effects easier when you change and compile one file at a time, than when you compile and change ten).

If you compile in very short iterations (this assumes the compilation process is optimized to take a short time) it is possible to fix compilation errors without getting out of "the zone".

Or is this some sort of myth propagated by the software community that you must compile your code frequently?

It is propagated by the software comunity as well, but it has good reasons behind it.

In my understanding that's an invalid argument, because "getting code to compile" for a given length of code generally involves fixing a constant number of compile errors and takes a fairly constant amount of time

It sounds to me like you have little (to no) experience, in maintenance of medium to large legacy code bases (hundreds or thousands of source files). This is where this attitude (i.e. "compile as you go") will help the most, and this is where you form this kind of habit.

I would imagine that the people who inteviewed you drew a similar conclusion ("you have little to no experience in large code bases").

utnapistim
  • 5,285
  • 16
  • 25
  • 1
    "compile and change ten" - plenty of situations where this is the smallest meaningful unit to try; such as adding a new parameter to a function and all its call sites. – pjc50 Jun 23 '14 at 12:55
  • 7
    Context switches. You're kidding, right? If we talk about automated background compilation to indicate syntactical errors in your code as you go, that's fine. But the fastest context switch will not be able to tell you, whether the algorithm logic is correctly implemented or if the algorithm is suitable at all. But that is what sets a working solution apart from neatly organized, error-free compiled and blasting fast, but utterly wrong code. – JensG Jun 23 '14 at 13:13
  • 5
    @JenS, no, I am not kidding. Having to jump all over the code to fix compilation errors ensures you no longer think about the problem you are currently solving (gets you out of the zone). If instead, you can compile as you write code you can keep working on checking the algorithm - not the syntax. The fastest way to handle context switches is to ensure you won't need them). My post does assume an ideal world though (with fast C++ compilation of large code bases and minimized inter-dependencies). – utnapistim Jun 23 '14 at 13:28
  • 1
    @JensG that seems to be a logical fallacy: this is not about choosing between compiled code and shitty code but about any possible benefits of compiling more than once. – Jorg Jun 23 '14 at 13:32
  • 1
    I doubt that the claim that breaking concentration dozens of times for a short amount of time to fix single syntactical errors is faster than breaking it once and fixing a dozen syntactical errors in one go (after you worried about your actual algorithm). That's certainly not how context switches work in computing (we're trying to optimize for throughput after all here). And I've been working on a project with about 500k LoC of C++ code that has evolved over more than a decade, so I hope we don't draw the inexperience card just yet? – Voo Jun 25 '14 at 23:31
  • Concerning large codebases: Some of those don't lend themselves to frequent compiling. The more interdependent the compilation units are, the longer the average compilation time becomes, up to the point where you can drink a coffee while your code compiles. Of course, that's a huge problem of the project itself, but if you are working on such a project, you should *not* be compiling as you go along because that would render you completely inefficient due to the many large pauses for compiling. – cmaster - reinstate monica Mar 11 '16 at 21:34
26

I think there is more than a little professional snobbery here. The implication seems to be "if you've never had the need to compile regularly then you've never worked with anything that complicated - go get some more experience and come back when you've learned to work exactly the way we do."

But obviously there is another side to this. Some projects take an age to compile. I've worked with frameworks that take 30 minutes or more to compile after even minor edits. Heaven help you if you ever need to edit a header file. Full recompilations are typically done overnight, and if you're relying on the compiler to catch your mistakes there are still rare errors that won't be detected during a partial build. You just don't re-compile every 5 minutes under these conditions - unless you're feeling lazy.

The compiler cannot help you with logical or semantic errors and syntax errors really aren't so hard to avoid that spending half of your day compiling becomes worthwhile. Of course, you'll make the occasional typo, but I'm going to assume you can both touch-type and read. If you have the freedom to choose, use a coding style that makes good use of layout to visually highlight errors and you'll never drop a brace, bracket or semicolon ever again. It takes a little practice and a little more discipline than most are used to, but it is possible. I can write code for a couple of hours at a time, in a plain text editor, and compile it first time better than nine times out of ten. Sure, I could compile more often, but I can't remember the last time I had an error that would have been easier to correct as a result.

If you aren't a fan of constant recompilation, you're in good company. Here's Donald Knuth:

As to your real question, the idea of immediate compilation and "unit tests" appeals to me only rarely, when I’m feeling my way in a totally unknown environment and need feedback about what works and what doesn’t. Otherwise, lots of time is wasted on activities that I simply never need to perform or even think about.


All of that being said... if you're working in a context where compilation is a free action, why wouldn't you? At home, on personal projects, I hit ctrl-S about once every 30 seconds and the "compile" shortcut nearly as often, in an IDE that constantly runs the code through the compiler's front end to provide real-time error highlighting. Why pass up a free lunch?

  • I disagree that compiling is free, distractions are costly! But otherwise, good answer, thanks :) – CaptainCodeman Jun 23 '14 at 23:00
  • Maybe I should have made the bold, italicised "if" an "iff" instead... I think depending on the project, compiler and environment it *can* be pretty darn close to a free action. If you have a second window or screen for compiler output then you can compile nearly as often as you stop to breath. If you were really hardcore (I'm not) you wouldn't even need to look away from your code - provided the compiler produced verbose enough errors to register on your peripheral vision. Again, this is ***iff*** compiling is reasonably fast, otherwise see above. – DeveloperInDevelopment Jun 25 '14 at 01:10
  • 2
    `I hit ctrl-S about once every 30 seconds`. I probably save twice as often lol. It's a really bad habit. Sometimes I'll save in the middle of a line of code, and then save again at the end of it. Whenever I stop to think for a second and not typing, I save. – Cruncher Jun 25 '14 at 18:00
21

There are merits to compiling as you go. But I very much agree that staying on task is an OK coding strategy.

The most significant benefit to incremental compiling is the mentality many get in if they wait for the end to compile and test: we're more concerned at the end in getting the code to run than anything else at that point. We say "Oh, just need to add this bracket so the compiler stops complaining" or "oh just need to capitalize this" without thinking if there is an underlying semantic error that this syntax error hides. I really do find syntactical errors often nest themselves in semantic errors (the converse not true).

As an example, say I changed a variable's meaning and as a result, changed its name. The name change generates a syntax error later on in the code but if I just please the complier by correcting the name, I've ignored why that error came into existence.

Lan
  • 475
  • 3
  • 9
15

I understand the benefits of testing your code as you go along, but why compiling?

But how will you test your code as you go along when you don't compile accordingly?

The extreme case is test-driven development (TDD). It is obvious that TDD does not work with your strategy, since TDD means extremely short cycles of write-test, compile (should fail), write-code, compile again, run-test, fix-bugs, compile again, refactor, compile-again, run-test, and-so-on...

So not everyone does TDD, at least not always (me too, I admit). With your current strategy, you will never have a chance to even try TDD. But even when you are not doing TDD, it is IMHO extremly helpful to test your code more regular - which is not possible when you don't compile it regularly. And when your test fails, you have running to debug it (which can help you to understand why the nice looking algorithm you have written some minutes before does not behave so nice as you thought it should do). And the more code you write without compiling, the more code you write without testing, so the more likely it will happen that you run into a case where you cannot predict that the time to fix the problem is "O(1)", as you wrote.

jub0bs
  • 109
  • 5
Doc Brown
  • 199,015
  • 33
  • 367
  • 565
  • 1
    I agree with you, but I think there is a difference between compiling a program because you want to run it, vs. compiling when there is nothing meaningful to test (or for fixing compile errors). – CaptainCodeman Jun 23 '14 at 15:03
  • @CaptainCodeman: I think when writing 100 lines of code, there should almost always be plenty of small parts which could be individually tested for its own. 100 lines of code typically means something between 4 and 15 functions (or >20, if you code in Bob Martin's style). – Doc Brown Jun 23 '14 at 15:28
  • 5
    @CaptainCodeman: In TDD there's never "nothing meaningful" to test. The classic example is you want to write a new class (lets call it Foo) then the first thing you do is to create a unit test and write `new Foo();` which will obviously fail to compile since you haven't written the class definition. In TDD that's a valid reason to run a compiler - it proves that your unit test is working (by failing). – slebetman Jun 24 '14 at 08:12
  • @slebetman: thanks for that helpful comment. I would like to add that IMHO this is not restricted to TDD. When writing 100 lines of code, there is always something meaningful to test in between, if you do TDD or not. – Doc Brown Jun 24 '14 at 09:02
14

I actually agree with you that compiler errors should be no big deal for an experienced developer. I don't think the cost of fixing them increases significantly enough over time to worry about. If it were possible to postpone fixing all the compiler errors until just before a push, I would do so, as it would present a much smaller and more consolidated interruption.

Unfortunately, finding compiler errors isn't the only thing compilers do. At the risk of stating the obvious, compiling is required to run your program, and running your program is required to find all the more complex, subtle, and interesting runtime bugs that even experienced developers create. And those types of bugs are more difficult and therefore more expensive to fix the longer you postpone debugging them, because they can build on or mask each other.

However, I wouldn't necessarily mark someone down in an interview exercise for postponing compiling until the very end. Interview exercises tend to be very straightforward, and experienced developers usually know their limits. The more confident you are about what you wrote, the longer you will go between compiles. That's just human nature.

In order to not mark you down for it, the confidence would have to be justified, though. If you had spent 45 minutes writing something without compiling, then required another 45 minutes to debug it, I would have weighed that heavily against you.

Karl Bielefeldt
  • 146,727
  • 38
  • 279
  • 479
8

The one important thing about compiling often, missing from other answers as far as I can see is this: if you compile rarely and get a large amount of compiler errors, most of those are meaningless, because they are generated by the first error. It could be because you had wrong type, or typo, or plain syntax error which makes some declaration invalid.

You could always just fix the first one, recompile, fix the next remaining one, and so on, but with large code base this can be slow. But if you try to skim through the long list of compiler errors and spot errors which are independent, then you spend a lot of time reading irrelevant messages, or navigating code from secondary error spot to actual cause.

Another thing going for regular builds is, nothing stops you from starting to compile as soon as you have a complete block of code written, which should compile. You can then continue writing more code while compilation goes on, just as long as you don't save the new edits until compilation finishes. So there's practically no time wasted on waiting for build. If you wait until you have written everything you are going to write at that time, you then have to wait for compilation without nothing to do. This is basically the manual version of what modern IDEs can do in the background automatically.

hyde
  • 3,744
  • 4
  • 25
  • 35
  • Interestingly, this is a good reason to regularly compile *even if compilation is slow*. Good point. – sleske Jun 25 '14 at 09:19
3

No, it's not unreasonable to hold off compiling until you've done a sufficient amount of code (and a 'sufficient amount' depends on the coder and the code being written).

For example, if you're an awesome coder who takes his time to get it right, and you're not writing massive amounts or convoluted code, then compiling regularly is a waste, and probably a distraction too. If you're not, then compiling every function can be a good thing. It depends on the person.

As a counter-example, imagine you're writing JavaScript code - there is no compiler. Instead (given the nature of most JavaScript code) you would run the program (or refresh the page) to see the results of your coding. Now, you cannot do that until you're written enough code to make sense. As a result, JavaScript developers tend to "compile" as often as they can, which isn't necessarily very often.

In short, there's no correct answer here - the interviewer isn't wrong, but neither are you. Do what makes you productive and forget what anyone tells you you're supposed to do. There are much more important factors about coding than your tendency to hit F7 regularly (or not) is of absolutely no consequence.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
gbjbaanb
  • 48,354
  • 6
  • 102
  • 172
  • Your second paragraph is unclear; you may want to edit it, to be clear if the "awesome coder" should compile regularly or not. (Did you add a "t" and change "no" to "not"?) – DougM Jun 23 '14 at 15:52
  • @DougM - ta muchly. – gbjbaanb Jun 23 '14 at 15:55
  • Quite often scripting code is developed "live", that is it is executed in REPL environment. So "compilation" indeed happens all the time, most code that is written to the source file has also been executed once. Not all write script code this way, but I'd say anybody used to and fond of the relative "safety" of statically typed languages and compiler errors given by bad code, they *should* work in scripting languages this way. – hyde Jun 23 '14 at 18:55
3

For a sufficiently experienced programmer compiling code is never the bottleneck.

Once you know a language well enough (i.e. when you no longer have to think about the syntax and instead just code for functionality) you tend not to make simple syntactical errors. Those you do make are usually typos or copy-paste bugs, and they can be cleaned up in short order with just a few compilation passes.

I regularly write code all day without compiling, then I'll compile and just fix up what syntax errors and warnings the compiler reports before I commit my code (with a note that says "needs to be tested!"). I have no problem cleaning up 1,000+ lines of C or C++ code in just a few minutes.

Debugging and testing on the other hand is what takes a while. Logic errors arise for all sorts of reasons and I have yet to meet a compiler that will tell me about the subroutine I totally forgot to write, or will notice that my binary tree doesn't work because I pasted node->left when it should have been node->right.

While I think it's generally unwise to fight with an interviewer, I'd say if you felt your style was worth defending you should have pointed out that you left yourself enough time to debug the code you'd written. That's the thing no good programmer ever neglects.

p.s. - If I had been watching you review code by reading it, I would have hired you on the spot. That's what a pro does, every time.

par
  • 455
  • 3
  • 6
  • 4
    "I have yet to meet a compiler that will tell me about the subroutine I totally forgot to write." I totally rely on the compiler to tell me when I've not completed far-reaching changes. Sometimes I even rename a variable to prevent successful compilation until I've checked every instance of its usage and given them all the new name. I don't understand how you can say you haven't come across a compiler that won't warn you if something is missing. Unless you are writing empty place-holder subroutines and then forgetting about them, in which case heaven help you. – Ian Goldby Jun 24 '14 at 11:57
  • @par Thanks for your answer; It's good to know that I'm not the only one that codes like this! – CaptainCodeman Jun 24 '14 at 12:27
  • @IanGoldby You're missing his main point which is that the compiler will not catch logic errors which are the real problem. – CaptainCodeman Jun 24 '14 at 12:29
  • 3
    @CaptainCodeman I'm well aware that logic errors are more insidious than compiler errors. But it was his assertion about a compiler being unable to tell you about missing code that I wanted to dispute. Unless you are deliberately writing wrong (or incomplete) code that compiles…, but that rather defeats the argument that errors the compiler can't catch are the real problem IMO. Heck, I even use the compiler to move the caret to the line where I next need to write some code. But maybe I'm very lazy. – Ian Goldby Jun 24 '14 at 13:20
  • 1
    @IanGoldby: You missed the point entirely and I'd even go so far as to say you elected to twist my words. The compiler can't warn you about missing code in the same way I can't tell you what you'll eat for breakfast tomorrow. Introducing syntax errors intentionally so the compiler will remind you of something is a programming technique; it doesn't qualify as an error or give the compiler psychic superpowers. – par Jun 24 '14 at 17:57
  • And for what it's worth, sprinkling errors into your code in this way actually makes the case for deferring compilation. `#warning` and `// TODO:` comments are left with the sole intent of addressing them later. – par Jun 24 '14 at 18:02
  • 1
    @par I apologise for the offence I have obviously caused by my comment - it was not intended and I certainly did not intend to misrepresent what you said. I see now that when you write incomplete code that nevertheless compiles, you make it a practice to ensure that it can't be forgotten by adding #warning or TODO. That's a legitimate technique. The important thing, on which we both agree, is that code that compiles but doesn't work is far more dangerous than code that doesn't compile. – Ian Goldby Jun 25 '14 at 07:32
2

With a good development environment I see little reason to compile unless you're actually planning to test code. The background syntax checking tools catch most everything that the interviewer seems to be talking about, although I will admit there are still a few cases (involving changes that propagate across files) that aren't always fully identified.

That being said, I will try to compile and run pretty much the smallest unit of code that can actually produce an outcome. Half an hour ago I was creating a means of printing some search results and I did half a dozen test prints (to .pdf, not paper) making changes to the result to make it look better--a rate of about 1 compile per 10 lines.

Loren Pechtel
  • 3,371
  • 24
  • 19
1

In my opinion and in my experience, whether or not a piece of code compiles is essentially random, involving things like whether or not semicolons are missing, and has little to do with the correctness of the underlying program. (To me, focusing on compiling is like running an article through a spell-check without proofreading to check the grammar.)

My experience is very different: less than 5% of compile errors I get are about syntax. I know the language well, when I get errors it's mostly type errors, telling me that the semantics are not correct.

This is why I am happy to benefit as quickly as possible from the feedback of my compiler. Have you ever experienced using an IDE which underlines compile errors in real-time? Having a shorter feedback loop can be very valuable.

If you give me a piece of incomplete code, the first thing I do will be to read it. I won't even try to compile it until I know what the code is doing and I know the algorithm is correct.

If you are expected to work on code written by someone else, you don't always have time to read everything. The good news is: well-written code has low coupling, and should enable you to reason independently about just the part of the code that you need.

In those cases you have to assume that the code you have not yet read is correct, and investigate lazily when there is a problem.

"getting code to compile" for a given length of code generally involves fixing a constant number of compile errors and takes a fairly constant amount of time, which should be the same whether you do it after you finish writing the code, or if you interleave it with your coding time.

Context-switching is costly for your brain, therefore fixing small errors as soon as you write them can be more efficient.

EDIT: I can also make an analogy with source control, when a whole team is working on the same sources. Compiling as you go along is like making frequent commits, it helps to avoid having a lot of pain at the end when you have to merge and sort out everything.

You say that you disable things like red lines under your text. Do you also do that when typing an email or writing a technical document? Then you have to proof-read again all the pages instead of fixing mistakes as you go.

Another advantage is, when working on your code, if you keep it compiling or near-compiling at all times, you can benefit from a lot of semantic-based IDE features (safe renaming, refactoring, finding uses of a symbol...).

If you want to have a better understanding of how these features help, you could try enabling them and practicing, to experience yourself their benefits. You could also try to do some pair-programming with anyone that is used to them, and see how they benefit from them.

  • 1
    I usually turn off annoying compiler "features" like auto-formatting, drawing red lines under your text, etc. as I find I'm more productive without these dumbed down features. – CaptainCodeman Jun 27 '14 at 08:45
1

I thought a bit longer about this, because I felt that there is something very, very wrong with the interviewer and couldn't exactly point out what it is. Here's the problem: For any code that I have written in the last twenty years, the amount of time needed to turn a workable algorithm into code that compiles has been minimal. Any gain in efficiency in that area has so little impact on total development time that it is totally negligible, and an interviewer who rejects a candidate for perceived inefficiencies in that area has no idea what makes a good developer.

Most time should be spent on gathering information what the code is supposed to do, gathering information and specs about outside services that need to be used, creating a global design that will lead to correct and maintainable code instead of hacked together code, and finding algorithms that will lead to working code instead of code that is patched together until it happens to work (code that has obviously no errors vs. code that has no obvious errors).

Then come a tiny amount of time writing code that compiles.

Then comes a larger amount of time spent to make sure that the code works, and to make sure that we know that the code works and will stay working. Which is done by writing unit tests, stepping through code, and to a large extent by having well-designed code in the first place.

This interviewer concentrated on something that is covered by ten words in my reply. Which represent 10 percent or less of the actual working time. And has almost zero influence on the ability of that developer to produce reliable and working code.

gnasher729
  • 42,090
  • 4
  • 59
  • 119
  • That makes a lot of sense. In my opinion, a good developer should be able to write code on paper all day, and then at the end of the day type it up. – CaptainCodeman Jun 27 '14 at 21:56
1

The advantage of "compiling as you go along" is you get constant feedback, and won't have a chance to go far wrong before being pushed in the right direction. For a competent programmer like you, that's not a huge consideration, but for many others it is. Put another way, "compiling as you go along" is a way of "minimizing the maximum loss," even though there are some potential efficiency losses in your case.

Companies these days aren't just interested in a finished product. They want to know that it was "under control" all along. For them, "getting there is half the fun."

Tom Au
  • 893
  • 7
  • 17
  • this doesn't seem to offer anything substantial over what was posted in prior 16 answers – gnat Jun 27 '14 at 21:52
  • 2
    Thanks but what kind of loss are we talking about? Surely, unless you've done something drastic like accidentally write in the wrong language you would never have to rewrite any code simply because of compile errors. – CaptainCodeman Jun 27 '14 at 21:53
  • @CaptainCodeman: It makes companies feel better, and is a form of "insurance." That's something that costs money, but makes most people (including managers) "sleep better at night." – Tom Au Jun 27 '14 at 22:09
  • @gnat: The point I was trying to make was that most of the benefits were "corporate" level benefits, and it's something that the programmer should do because the boss told him to, not because the programmer thinks it's right or wrong. – Tom Au Jun 27 '14 at 22:16
  • well points in favor of ["shorter feedback loop"](http://programmers.stackexchange.com/a/245765/31260) have been already made and well explained in very first answer here; I honestly don't see how stuffing bare guessing about "companies these days" adds anything worthy over what was already stated – gnat Jun 27 '14 at 22:22
1

The other answers here mount a good defense for compiling frequently on the job, but since your question is centered around interviews, I'd like to tackle that angle of it.

In my interviews, I do the exact opposite: candidates can't use a compiler. They write short programs on the white board and then we discuss them. I have found that too many developers use the compiler (or interpreter) as a crutch, and that is a far bigger waste of time than compiling too infrequently. If I'm offering you a lot of money and you can't even write FizzBuzz correctly without a compiler, then you're never going to cut it on a long term basis, working on problems that are 100x more difficult than the toy exercises in the interview. And yet these simple exercises weed out more candidates than any other part of the interview.

The goal of an interview is to evaluate the mutual fit of the candidate and the business. A good interview question should state the objectives of the question and how the interviewee will be assessed. Springing a trick question on the interviewee and then penalizing them for not knowing the hidden answer doesn't help the interviewer or interviewee. Unfortunately, most programmers — even senior ones — aren't trained to interview other programmers, so they just rely on clichés and ask the same types of questions they were asked when they interviewed, without much though about whether these are effective techniques for evaluating candidates or not.

I'm not claiming that my approach is the "one true way", but it has served me very well. Like so many software methodologies that start with a capital letter, there are an equal number of "mandates" for interviewing. They're all bunk. You need to do what works for you and your business.

Mark E. Haase
  • 5,175
  • 1
  • 17
  • 11
0

In larger projects, with several subroutines, you want to test these parts, before using them in the larger scheme, since it is way easier to debug if you know certain parts already work.

In order to test these smaller pieces, you need to compile.

It might be that the interviewer confuses this situation with a small program that is not designed in this manner.

0

Regarding the second interview, a benefit of compiling is that you can observe, within just a few seconds, what the programs does (or doesn't). From there it is easier to read the code and to focus your efforts on the relevant parts. Perhaps this is what the interviewer was expecting.

Reading an unknown code base like this from beginning to end can be quite unproductive (you're not a compiler), while compiling/running the application will quickly give you a bigger picture.

laurent
  • 715
  • 1
  • 12
  • 22
  • this doesn't seem to offer anything substantial over what was posted in prior 15 answers – gnat Jun 27 '14 at 21:52