Page 1 of 1

Namespacing complete for classes

Posted: Sun May 25, 2014 21:56 UTC
by thekabal
I am thrilled to announce that I've completed namespacing the classes directory in the SVN tree. This change completed in revision 3461.

Now, instead of having a composer classmap for the classes/ directory and a includes/ directory, we now have just classes/ autoloaded using PSR-4.

In addition, going through that process helped trim the class names considerably. The worst case scenario is that a class call is one character longer (\class), but in most cases it is dramatically shorter (What was once BntDb can now be Db inside the Bnt namespace in a class file).

This helped speed up virtually every page in the game by a slight amount, as we no longer need classmapping for any directory.

When coding now, if you are creating a class (in the classes/ directory), use either namespace Bnt or Bad at the top of the file. Bad is for files that have globals, mixed input & processing, old code that has not been cleaned, etc. Bnt is for clean code, with no globals, a defined input and output, minimal output, etc.

If you are in a Bnt file, then you have to explicitly target anything in the Bad namespace with a leading backslash (\Bad\Footer::display() for example). If you are in a Bnt file, then you do NOT have to prefix a Bnt class (Instead of \Bnt\Score::updateScore, you use Score::updateScore).

For files in the main directory of Bnt, you will need to explicitly target both Bnt and Bad for now.

The plan is to eventually clean up the Bad files and convert them to be Bnt files as well, which would mean we could use a single namespace for everything.

Please be aware that there may be some uncaught bugs as a result of this change, but by and large, I've been extremely careful with this change. I've been able to test a large part of the game with these changes in place, and have found no issues.