2 ms·
One of our struggles at Facebook was actually with circular includes that made our php codebase super tasty spaghetti. File A includes File B includes File C i
by bbillings 15y ago
One of our struggles at Facebook was actually with circular includes that made our php codebase super tasty spaghetti.
File A includes File B includes File C includes File A by about 10000 files.
It was for a very scary trying to change a core library during this time because it was almost impossible to figure out where all it was included and impossible to test all the code that touched it. Additionally, we were basically loading up our entire init stack on every page load and async request because as soon as you loaded up one file all the circular dependencies would load up the entire stack. This had a big performance overhead prior to our switch to HipHop.
To this end we developed a new include system for library files that forces developers to be sane. Every module in the our library files must explicitly include everything that they need and it forbids circular dependencies. If module A requires module B, module B cannot require module A.
Making this change took a long time (in some places we are still untangling the code), but our core code is now infinitely more manageable and most importantly testable.
- adambard 15y agoI worked on a large PHP codebase for a few years, and that sounds very familiar. We never did get it untangled enough to test before I left. Do you have a static analyzer or something like it that enforces the no-circular-dependencies rule, or is it just a procedural thing?
- bbillings 15y agoWe have a static analyzer that runs when we submit a diff yes or try to commit, but in our "require_module" we also check for circular dependencies at run time. If you create one you get the module stack dumped into your log and promptly exited with an error message.
- jergason 15y agoThat sounds like it could be useful to the PHP community. Are there plans to open source it?
- bbillings 15y agoI'll look into it. Not sure how tightly coupled it is with some Facebook specific stuff. http://phabricator.org/ http://phabricator.org/ has a very similar system if you are curious. epriestley made some nice updates to it in there as well.
- rexreed 15y agoHow does Facebook use Autoload? Does it help in this situation?