This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
modernizing_the_vanillajuce_code_base [2017/08/31 20:35] shane created |
modernizing_the_vanillajuce_code_base [2017/09/01 19:49] (current) shane [Newer C++ features and constructs] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | |||
| ====== Modernizing the VanillaJuce code base ====== | ====== Modernizing the VanillaJuce code base ====== | ||
| - | I was very pleased to receive the following feedback on [[vanillajuce|VanillaJuce]] directly from JUCE author Jules Storer himself: | + | I was very pleased to receive the following feedback on [[vanillajuce|VanillaJuce]] directly from JUCE author Jules Storer himself. I have added a bit of formatting to improve legibility: |
| + | |||
| + | //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/ | ||
| + | * //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:: | ||
| + | * //" | ||
| + | * //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 (" | ||
| + | |||
| + | //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!)// | ||
| + | |||
| + | Jules' | ||
| + | |||
| + | It occurred to me that Jules' | ||
| + | |||
| + | I'll start by reorganizing Jules' | ||
| + | |||
| + | ===== Outdated C syntax and library functions ===== | ||
| + | * [[enum_class_rather_than_typedef_enum|C++11 "enum class" rather than C " | ||
| + | * [[eliminate_char_arrays|C++ string classes instead of char[] arrays]] | ||
| + | * [[constexpr instead of preprocessor define]] | ||
| + | |||
| + | ===== Pointers and references ===== | ||
| + | * [[Avoid new/delete, prefer references to pointers, use member variables for sub-Components]] | ||
| + | |||
| + | ===== Newer C++ features and constructs ===== | ||
| + | The following two items remain open at this point, pending further guidance from more experienced JUCE developers. I reviewed all my '' | ||
| + | Comments welcome on the JUCE Forum! | ||
| + | * [[Range-based for loops]] | ||
| + | * [[inline member variable initialization]] | ||
| - | 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/ | ||
| - | 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:: | ||
| - | “typedef enum” is C, not C++! An “enum class” has vastly more type-safety, | ||
| - | 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 (" | ||
| - | 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!) | ||