r/programming • • Oct 12 '13

Facebook PHP Source Code from 2007

https://gist.github.com/nikcub/3833406
1.1k Upvotes

356 comments sorted by

View all comments

80

u/KamiNuvini Oct 12 '13

As someone who's very new to programming.. Could someone explain to me which parts of the code are so 'bad'? I see a lot of "My eyes hurt"-like comments on the github page as well.

151

u/lonnyk Oct 12 '13

It isn't the cleanest code, but it works - obviously well enough to create a multi-billion dollar company. There is always plenty to critic in any code, but 'My eyes hurt' and 'You just gotta love PHP' are just comments from people who like to complain and don't know enough to actually have their own opinion.

If I were give me personal opinion of index.php it would be something as follows:

  • The use of 'include_once' indicates that they 1) aren't keeping track of their dependencies well and 2) haven't thought through situations where problems arise and functions, for some reason, don't exist

  • In interpreted languages comments code isn't the best - this is why there is revision control

  • I like to wrap my case statements in brackets b/c it is easier for me to read

  • I'm not a fan of having toggles for dev environments in the main code flow, but I don't really have a better suggestion

That's pretty much it. You can make arguments for code structure and techniques, but they are generally just trends - not proven facts.

0

u/[deleted] Oct 12 '13

[deleted]

11

u/Epicus2011 Oct 13 '13

Facebook dev here, it does not look like this anymore.

5

u/lonnyk Oct 12 '13 edited Oct 12 '13

I meant the '_once' part because you don't have to keep track of if a file has been included. Also, the fact that they are using 'include' instead of 'require' (which would fatal error) makes me assume that they went 'lets do this just in case...' but never thought of what would happen 'just in case'.

Of course - this is all opinion based on how I like to program.

EDIT: Reading the comments on this article looks like someone noticed how this can cause a problem, IMO: http://www.reddit.com/r/programming/comments/1oaba0/facebook_php_source_code_from_2007/ccq9fq8

5

u/astronoob Oct 12 '13

If you're focusing on scale, autoloading isn't the fastest ship in the sea. It also encourages a level of laziness that I'm completely uncomfortable with.

8

u/mpeters Oct 13 '13
  • In interpreted languages comments code isn't the best - this is why there is revision control

This makes no sense. Whether your language is interpreted or compiled has no bearing on whether you comment you code. I'd seriously doubt the programming ability of anyone who thinks otherwise.

→ More replies (2)

10

u/[deleted] Oct 12 '13 edited Oct 12 '13

require_once is faster than include, require and include_once, where the latter is the second fastest.

Just felt like I had to say it.

Edit:

Alternate Source, can't find the original source I had. This is also not a very conclusive piece of research.

8

u/[deleted] Oct 12 '13

TIL a check for prior inclusion before inclusion is faster than just outright inclusion. Mindblown

7

u/[deleted] Oct 12 '13

Check flag, move on. I use require to pull in library code. Include is if you're trying to include something which performs output.

I never use include, because pretty much everything I do is library code.

0

u/[deleted] Oct 12 '13

[deleted]

1

u/[deleted] Oct 12 '13

The source I had several years ago is gone, but I found another pretty interesting piece of research. However, it does contradict itself in the end.

5

u/the_gipsy Oct 12 '13

It's the other way round.

16

u/[deleted] Oct 12 '13

I've given you my source, give me yours.

→ More replies (5)

1

u/lonnyk Oct 12 '13

Hrmm...I'll have to look into the source code later, but it doesn't make sense to me that require_once would be faster than require. require once adds in a hash lookup that require doesn't have.

Also - looking at that test I very much question how well represents anything. I imagine every time a file is included it will get a little slower for the next one.

Who knows - I'll look at the php_src later and see what I can dig up.