News for hackers. Stuff that matters.
Re:I Like PHP by bbillings on Wednesday August 10, 2011 @02:31PM (#2869527)
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.

Re:I Like PHP by adambard on Wednesday August 10, 2011 @02:41PM (#2869592)
I 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?

Re:I Like PHP by bbillings on Wednesday August 10, 2011 @03:26PM (#2869783)
We 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.
Re:I Like PHP by jergason on Wednesday August 10, 2011 @05:40PM (#2870339)
That sounds like it could be useful to the PHP community. Are there plans to open source it?
Re:I Like PHP by bbillings on Wednesday August 10, 2011 @08:59PM (#2870898)
I'll look into it. Not sure how tightly coupled it is with some Facebook specific stuff.

http://phabricator.org/ has a very similar system if you are curious. epriestley made some nice updates to it in there as well.

Re:I Like PHP by rexreed on Wednesday August 10, 2011 @09:00PM (#2870901)
How does Facebook use Autoload? Does it help in this situation?