Got an interesting little idea that I’ve been tinkering with, and wonder what you all think of it…
By some cunning hackery, I’ve found a way to create two files - juce.h and juce.cpp, which contain the entire library. Yep, the whole thing - all the source, all the 3rd-party libs like zlib, flac, ogg, png, jpeg, etc. The only external files that either of these include are system headers.
So this means that to compile a juce app, you just need to include juce.h and add juce.cpp to your project. No libs to include (well, apart from the necessary frameworks on the mac). No need to build juce itself, just compile your project. The files are about 2MB and 8MB, so they’re big, but not unmanageable.
Advantages I can see are:
- no need to ever build the juce libs
- massively faster to compile - on my mac it took me about 5-10 mins to build juce, but to compile the juce_inline.cpp file takes under 30 secs. On my PC it takes under 10 secs.
- no need to set up any library paths in your project, so things like the juce demo/jucer could build and run on a clean PC without the user needing to manually set anything up.
- no need to keep different libraries for different configurations. You might (like me) have 10 different juce apps, each needing a different setup of some juce_Config.h flags, debug, release, OSX version, etc., and that meant doing 10 different builds of the juce library, and somehow keeping track of all the libs that were produced. If it’s just a .cpp file, then each project can just set the config flags it needs, and each build instantly gets its own tailored version.
- better code generation because the compiler is effectively being tricked into doing whole-program optimisation on the juce classes
- ability to easily lock your project to a specific version of juce - just make copies of the two files in your project, and archive them along with your own code
- more laborious when you’re writing code in the library itself, (but that probably only applies only to me and a handful of other hackers). It’s actually not particularly hard, though - I’ve written a utility that generates the two mega-files, and it only takes a a few seconds to run.
- slightly more confusing when you need to debug down into juce code (but all the source is still there, just in a big file)
- will probably break some compilers. I hit a few “internal compiler errors” in XCode, but by random tweaking these were avoidable.
So… am I mad? Is this a stupid way to do things? Or will all programming be done like this in the future? Answers and opinions please!