GetDunne Wiki

Notes from the desk of Shane Dunne, software development consultant

User Tools

Site Tools


modernizing_the_vanillajuce_code_base

This is an old revision of the document!


Modernizing the VanillaJuce code base

I was very pleased to receive the following feedback on VanillaJuce directly from JUCE author Jules Storer himself:

Great contribution! But… if you’re posting your code for beginners to learn from, you really need to get up to speed with modern C++ practices, because all the old-fashioned stuff in here sets a really bad example to any newcomers who don’t know that there are better ways to do things. I can see that you’re a proficient programmer, and I’m guessing you’ve written a lot of high-quality C in the past, but modern C++ is a very different beast and you need to lose all that old baggage! So quick code review: ditch all your new/delete/sprintf/strcmp and other C functions. Convert all your for loops into range-based fors and you’ll cut out a ton of boilerplate. Use member variables for subcomponents rather than pointers. Use juce::String or std::string, not raw char arrays (!) “typedef enum” is C, not C++! An “enum class” has vastly more type-safety, and enforces a syntax that makes the old-fashioned ‘k’ prefix redundant. NEVER use a #define for a constant!! Use constexpr! Pass references if possible, not pointers! Use inline member variable initialisation and you’ll save another hundred lines of code. If you’re passing an argument that’s a string, you can just use a string literal e.g. foo (“xyz”), you don’t need to wrap it in foo (String (“xyz”)) (God knows why we see sooo much code that’s written that way) Hope that helps! (Also, the list above is probably something that could be copy-pasted as a code review for hundreds of other projects that people have shared on here over the years!)

modernizing_the_vanillajuce_code_base.1504211702.txt.gz · Last modified: 2017/08/31 20:35 by shane