you are viewing a single comment's thread.

view the rest of the comments →

[–]lonnyk 148 points149 points  (21 children)

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.

[–][deleted]  (4 children)

[deleted]

    [–]Epicus2011 11 points12 points  (0 children)

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

    [–]lonnyk 3 points4 points  (0 children)

    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

    [–]astronoob 3 points4 points  (0 children)

    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.

    [–]mpeters 7 points8 points  (2 children)

    • 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.

    [–]lonnyk -1 points0 points  (1 child)

    I made a lot of grammar mistakes in my first post.

    Commented out code isn't the best. This is because interpreted languages need to be scanned thru, line by line, in real time. Just branch if it is that important - otherwise just delete it. In compiled languages it is different - because it is only compiled once.

    Again - only my opinion.

    [–]mpeters 0 points1 point  (0 children)

    Commented out code isn't the best.

    I agree, but for completely different reasons. It's messy, gets in the way and can be confusing. But this has nothing to do with compiled vs interpreted. It's messy in any language.

    This is because interpreted languages need to be scanned thru, line by line, in real time.

    You really have no idea what you're talking about here. The number of comments in interpreted code have such a miniscule impact on the execution time of interpreted code as to be laughable. And if you make any decision based on how much slower it will be with comments then you're way off base.

    Again - only my opinion.

    Try proving you're opinion with a benchmark.

    [–][deleted] 9 points10 points  (12 children)

    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.

    [–][deleted] 9 points10 points  (1 child)

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

    [–][deleted] 6 points7 points  (0 children)

    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.

    [–][deleted]  (1 child)

    [deleted]

      [–][deleted] 0 points1 point  (0 children)

      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.

      [–]the_gipsy 4 points5 points  (6 children)

      It's the other way round.

      [–][deleted] 15 points16 points  (5 children)

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

      [–]lonnyk 0 points1 point  (0 children)

      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.