So Peter and I were having this intelligent discussion on MSN Messenger discussing MyBB and how we could improve it. Peter was all like “Ooooooooooooppp” and I was like “Meeeeeeeeeh”. Then we were like “Weeeeeeeeeeeeeeeeeeee”. Okay, it didn’t really go like that at all.
Let’s face it; the code behind MyBB is crap. Well, a lot of it is crap. This is because MyBB has undergone numerous changes in coding standards and practices as well as development being underway in the past with no version control or collaboration tools in place.
Peter and I were actually discussing how we could improve the way MyBB performs validation on things such as threads, posts and users as well as the methods that MyBB uses when storing posts and other entities.
What we don’t have in MyBB is a standardised method for doing all of the above, code is repeated numerous times which makes it a pain when we’re adding in new features (or new database columns) to go back and make sure we updated other instances of the same, or similar code.
We wanted something to handle data. Enter data handlers. Data handlers will be our way of handling data in MyBB, as you may have already guessed. We’ll be developing several classes relating to different sections of the board (posting, poll voting and user account management) which deal with all of the different types of data that are used in them.
Think of it like a modular system for validation. Our validation classes extend upon an existing parent class called dataHandler. The dataHandler class provides standardised methods for setting and retrieving error messages. The validation classes, once extended upon the dataHandler then provide the actual methods for the type of validation we’ll be performing.
From validating new posts and registrations and determining what error messages to throw back to the user, right through to storing the actual post or user data in the database. Data handlers provide us with a standard API for storing information in MyBB as well as provide users with these APIs if they wish to easily extend upon them or use these features of MyBB in their existing projects.
Now, with our API in place (It’s not developed completely yet!), we’ll be able to do something like this to check if a new post is valid, if not then display the errors to the user, else insert the valid post into the database:
require_once "./inc/datahandlers/post.php";
$post_handler = new postHandler;
if(!$post_handler->validate_post(&$newpost))
{
foreach($post_handler->get_errors() as $error)
{
echo "$error\\n";
}
}
else
{
$post_handler->insert_post(&$newpost);
}
Along side our validate and insert methods, we’re going to have a verify method which will simply return true or false if say, a subject is valid, a username is valid or an email address is valid.
We’ve prototyped our error handling class which will allow either single errors to be set or multiple errors at a time. Multiple errors is particularly useful on pages such as the registration page where we supply a list of errors with the registration details along side the registration form again - inline error messages. Single error functionality was added in for those pages where we need to completely halt without further processing when a certain error is found.
Of course, it isn’t only data handlers we have planned. There are a lot of things which can be handled in different ways (Hey! - stop thinking like that!). We’re also talking permission handlers, to determine if a specific user or the current user has the permissions required to perform an action such as edit an event, edit a post, or edit their profile.
At the moment, most of this functionality exists in a prototype class that Peter has developed and we have both reviewed and discussed. Nothing has been implemented as of now - there is still a lot of planning we have to do in regards to how this system will work and exactly how we’ll deal with some of the more tedious parts of the system.
In short, we have lots of things being undertaken with MyBB at the moment, a lot of rewrites, extensions in both front end and code functionality as well as a few more little secrets we’re not going to let out of the bag yet.
I knew there was a reason why I wanted Peter to work with us on MyBB!
Comments
Peter Akkies (January 6th, 2006, 9:52 pm)
Wow, so much credit to me! I must say I’m really liking the way we are heading with the MyBB development. MyBB has a solid userbase already and if we improve the code a lot MyBB will be able to compete with the big fish more easily.
Peter Akkies (January 7th, 2006, 3:04 am)
[...] Now that Chris has been busy working with these techniques, I expect he will have some pretty cool stuff ready to implement in MyBB. First though, let’s clean up and optimise MyBB, as he mentioned. [...]
WDZ (January 7th, 2006, 9:18 am)
Oh, wonderful… even more dodgy classes and functions. :/
While I think MyBB is heading in the right direction in many areas (functionality, ease of use, XHTML compliance, to name a few), the increasing complexity of the code is disturbing. I really don’t want to see MyBB’s code become like IPB’s — so darn complicated that nobody can understand it. Dozens and dozens of include files, functions for everything, etc. I really prefer light, clean, simple, straightforward, unbloated, uncomplicated code.
If I were you, I’d want to focus on fixing the hundreds of uninitialized variables, and removing the bits of deprecated code left over from past versions. A nice goal might be to make MyBB work with error_reporting set to E_ALL.
Chris Boulton (January 7th, 2006, 1:13 pm)
I agree, which is the focus we’re taking with this. We’re spending a lot of time planning how this is going to work to make it easy to follow and use. We’re trying not to make it complicated and bloated too, and it shouldn’t be once we’re done too.
Cleaning up the code is also one of our priorities. We’re refining our coding standards, removing the old code that is no longer needed and things like that.
Uninitialised variables are no longer a security issue due to the “complex code” (:P) we put in place which handles all incoming data. That isn’t to say, however, that we won’t be cleaning them up.
Snake (January 7th, 2006, 3:52 pm)
I agree with WDZ. I like a light board. I don’t like heavy features that does who no’s what. I think thats why WDZ sticks with RC2 and Msgplus :\
WDZ (January 7th, 2006, 4:39 pm)
That’s good to hear, and I hope you guys can make it work. Good luck.
Well, that’s not the main point. It’s still not a good coding practice. Your “global-killing” function should not be needed at all… it’s like using buggy unpatched software but relying on a firewall to keep you safe.
All right, cool…
Chris Boulton (January 7th, 2006, 6:47 pm)
Well, we’re doing this mainly because we feel it is necessary for both us when developing and users who are editing MyBB. Currently, if you wanted to modify the query used to create a user, or the validation done on it then you’d need to edit both the front end code as well as the back end code (Admin CP) to make sure they’re both up to date.. A real pain.
With this solution, it separates this functionality into its own methods of a class which will spit back any error messages or perform the insertion itself.
The feature will be completely transparent to users who aren’t digging in to MyBB, and those who do, should be able to easily figure out what is going on here.
Oh, and to further improve what we’re doing, we’re going through MyBB and using PHP Documenter so we can generate PHPDoc about the code - which should help people find their way through MyBB.
My thoughts about total OOP, especially in MyBB, if you didn’t guess from my opening paragraph: I don’t really think it suits or application where alot of things would make sense in a class, but at the same time, alot would make sense as functions or just structured code.
Chris
Tikitiki (January 9th, 2006, 9:55 am)
Sounds like fun. Who’s up for the ride?
One thing that I would assume would come with the upgrades is more arrays. But the funny thing is Every call to a variable array retuires a hash-table lookup internally within the engine. This is substantially slower than the access time required for scalar values. (just plain variable)
John Anderton (January 9th, 2006, 9:54 pm)
I hope it turns out for the best. The best thing that us users would like out of MyBB is to have a nice clean code that is easy to understand and which works smoothly without much, if any (hopefully none :P), problems
Keep up the good work chris
I think you meant “RC2 on Msgplus”
Eljay (January 10th, 2006, 5:20 am)
I think i would prefer finding those two queries and changing them than digging through complicated include files to find one query.
Guido (January 10th, 2006, 8:11 am)
Sounds like it’s for the better, so go ahead with it (and taking WDZ’s advice) and good luck!
Peter Akkies (January 10th, 2006, 5:32 pm)
They would just be in the inc/class_user.php class or something, which is a very logical place for it to be.
Rodney H. (January 26th, 2006, 12:35 am)
I found this site because I wanted to thank someone for writing the forum and making it available for free. I downloaded it and launched a simple family forum (family in US and Europe) so we could all keep in touch. I am very happy with all the features. Each time I am thinking of doing something, I can, EASILY, with the forum. thank you.
In terms of re-writing the code, yes: Simple is better. that is why I opted for this instead of your competitors. If you keep the code clean and simple, it helps me to make all the changes I need, and maintenance is smoother.
Overall, I am a very pleased customer and will do whatever I can to support a product that helps me accomplish my needs.
thanks. and keep up the good work.
-Rodney H.
Chris G (January 27th, 2006, 3:41 pm)
Hey!
I like the progress of MyBB. I think there are allot of things that could be done better, but with anything it takes time ti refine and work at. Keep putting 100% in, and you’ll get 100% out.
Chris G (January 27th, 2006, 3:42 pm)
Oh, and I like the AJAX here on this site Chris…will we ever see some in MyBB?
Chestah (February 5th, 2006, 12:00 am)
I agree, will AJAX make an appearance in MyBB once all the code is cleaned up?
Tikitiki (February 12th, 2006, 8:08 am)
I guess we’ll have to wait and find out