Compile early, compile often!

Do you buy into the mantra :

Compile early, compile often!


???

Andy
closed account (1yR4jE8b)
No, I regularly write 1,000,000 LOC without compiling and when I do, it compiles and runs perfectly ever.single.time.
:-)

I forgot to add...

If so, did you do so instinctively, or was it instilled into you?

If not, why not. (geniuses are excempted from this question!)

Andy
Compile early, compile often!


Early as in, even if the program isn't finished yet?
And often as in, even though you made no changes since the last time?
In that case, I don't.

I guess dry compilation would help if you're tired and just want to fix typo's; but I'd rather prefer finding a way to keep my mind awake.
Well, I didn't invent the mantra !!

But some of the beginners' questions arise from the fact that they've typed in far too much code between compiles (the ones where there is just a few "obvious" typos -- well, obvious once you've been coding a year or two).

The code "distance" I leave between compiles/builds depends on the complexity of the code, based on experience with compiler error messages. For exmple, if I'm working on templated code I probably check that compiles a bit more often, as the error messages for this kind of code can be a bit cryptic.
Last edited on
I compile early, but not often. Usually, I compile each time I have to update my makefile or whenever I add/change/remove a block from my C++ code, but in case of the second option never before the changes are complete.

-Albatross
closed account (zwA4jE8b)
I compile every time a portion of a program is coded, if the program can be ran with the addition, and test/debug.
Last edited on
if I'm working on templated code I probably check that compiles a bit more often, as the error messages for this kind of code can be a bit cryptic
I agree with this. I generally only compile if I want to syntax- or type-check, or if I want to run (obviously). After all, there's no difference between fixing 100 compiler errors in one go and fixing 10 compiler errors 10 times.
Different from fixing actual bugs, which will get harder as time goes on.
This will probably sound weird/would drive most people nuts. But the majority of my programs that are written in compiled languages are modular and I recompile every time I add some type of module. So a new class gets a recompile of the module it belongs to the moment I finish all the method. Also, each finished or modified method gets a rebuild of the source files involved. It's kind of a hierarchy thing.

From most to least often occuring event:

Changed, added or removed line -> Save file (that's a given)
Changed, finished, or removed function/method -> rebuild file(s) involved.
Greatly Modified, finished, or removed class -> Recompile.

So I guess I don't Compile very often, but I rebuild my code at least once every 10 minutes or so.
I always do test of portions in the code. So at the end I put all the pieces together and it all compiles cleanly
For C++ templatized code I always compile very often as the compiler always throw very cryptic and very long error messages. It helps to resolve them early whenever you made changes to templatized code. How I wish C++ compiler can give more meaningful error message for those C++ templatized code. So the frequency of compilation depend on what kind of code I am dealing with in C++.

Finally, it never hurts to compile often assuming your total lines of code is small to medium. For HUGE lines of code, you may want to compile them say just before you go for your lunch,dinner break.

For some commercial companies, they even have a mandatory daily at night job that will check the source code out and do compilation. Any errors will be emailed to the respective developers. So next morning developers came in know their yesterday checked-in code has compilation errors so they can do a quick rectification.
What kind of moron commits code with compiler errors, though?

What kind of moron commits code with compiler errors, though?


Well I encounter a case before in my previous employer company where the developer was serving his 1 month resignation notice. Since company make him work till last day instead of asking him to do proper hand-over, till the last moment he commit code that does not compile cuz his superiors ask him to.

Now that is classic example in the real working world of a developer commit code that has compilation errors. Unbelievable but it happen :P
I don't compile until I finish a section of code - I never compile incomplete segments of code. By segment, I mean a function or class and all the functions or classes the function or class depends on, and sometimes even the functions and classes related to it.
Simple answer no,
because almost all of my code is dealing with filestreams, and byte shifting i cant just drycompile, unless im tesing to see if one aspect of my code works or im adding a gui, but normaly ill use a blank program to test a aspect, otherwise ill compile every snack break, 6 hours, or every 5 interuptions from working.
closed account (3hM2Nwbp)
Sure do. I'd rather deal with errors a dozen at a time rather than having my compiler abort the build because of too many errors.

I am also a firm believer in the "one class per file" mantra, so a single file build generally isn't very time-consuming.
I'd rather deal with errors a dozen at a time rather than having my compiler abort the build because of too many errors.
Well, one error is enough for that.

I am also a firm believer in the "one class per file" mantra
I used to do that before I got sick of endless compilation times.
Why would that cause endless compilation times?
Because there's usually a set of headers that end up being included in every translation unit. If you don't or can't use precompiled headers, you have to compile them once for every translation unit. God help you if one of those headers is a Boost header, windows.h, or something equally enormous or... templaty.
Asking how often to compile is almost equivalent to asking how often to test (sometimes just a quick "it compiles" check is good as has been pointed out -- I tend to make the smallest changes possible when dealing with boost::spirit because of the error messages)

If using TDD, it means very, very often since you have to run very, very often.

I like to test the smallest piece of functionality that I think I might have gotten wrong or that I think would be harder to debug when used in the "production" scenario.
Topic archived. No new replies allowed.