Moving the Mozilla code base over to more modern C++

 The Mozilla code base is very old.  It dates back to before many of the common features of C++ today existed.  As a result, people need to get used to a lot of arcane patterns and idioms that don’t really feel great for those used to more modern code bases.  This has been especially difficult for new contributors as it increases the barrier to entry for them by adding to the list of new things that they need to learn before they can be effective working on the Mozilla code.

This pattern bothered a lot of people, and Michael Wu fixed the first notable example of such arcane pattern: converting the usage of the type PRBool to bool.  PRBool is a typedef to int which was used all around our code base instead of the C++ bool type.  I then followed the train by converting instances of PR_TRUE and PR_FALSE in our code base to true and false.  Aryeh Gregor then stepped up to convert our null value, nsnull, into the C++11 nullptr.  And I recently switched our usages of NSPR numeric types (such as PRInt16/PRUint32) to the stdint.h numeric types (int16_t, uint32_t).

This has been a long and hard road, and we should continue to do more of this in the future.  While this type of work may not seem that interesting as it’s not improving any of the user/web developer facing features, I believe it’s very important to the continuous growth of the Mozilla project, as it makes the code more modern and pleasant to read, and it makes the live of people contributing to the Mozilla code base for the first time much easier.

If you have ideas on more of this kind of cleanup, or are interested in helping with this effort, please contact me!

Tagged with: ,
Posted in Blog
5 comments on “Moving the Mozilla code base over to more modern C++
  1. Mark Côté says:

    Is there a wiki page with the current suggested usage of NSPR? I’m currently writing a new SUT agent in C++ using NSPR, and I wasn’t sure what aspects are deprecated in favour of standard C++ or for other reasons.

  2. Ehsan Akhgari says:

    No, unfortunately as far as I know, no such page exists yet.

  3. alihelmy says:

    hey mate, I would love to contribute to this kind of code cleanup work. I think it might work as a good introduction to the code base for me, and I think it might be simple enough and I can make a contribution

    If possible, or if you have similar work like this, I’d love to hear about it (via email)

  4. James Napolitano says:

    Excellent work, it’s always good to see these kinds of things get done. I wonder, though: large portions of Gecko may be ported over to Rust (as part of the Servo project) in the future. Would these cleanups then become irrelevant, or would they help the transition? (Certainly at least the switch to standard bool types would help, because that would need to be done anyway as part of the porting.)

  5. Ehsan Akhgari says:

    If and when we port such code from C++ to Rust, these cleanups would become irrelevant, but in the mean time there is a lot of gain to be had from them. :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>