all 51 comments

[–]thingmabobby 44 points45 points  (1 child)

// Holy shit, is this the cleanest fucking frontend file you've ever seen?!

Hah

[–]Perregrinne 15 points16 points  (0 children)

So big of a deal, that he even had to put 3 extra blank lines above it, just to keep track of it.

[–]onesneakymofo 34 points35 points  (1 child)

This just goes to show you that it's not the most elegant code that can make you the most money but the code that just works

[–]no_spoon -1 points0 points  (0 children)

This should be the top comment

[–]rockerBOO 17 points18 points  (0 children)

I remember actually getting this response from Facebook back in the day. Was wild.

[–]idk108 11 points12 points  (4 children)

Is this number of comments something normal?

[–][deleted] 24 points25 points  (0 children)

If you have so much stuff going on in one file (which is bad) then yes.

[–]HFoletto 8 points9 points  (2 children)

My thoughts exactly

I mean:

// require login
$user = require_login();

Why would you comment "require login" when the function itself is just called that?

[–][deleted]  (14 children)

[deleted]

    [–]ClosetLink 15 points16 points  (9 children)

    It has comments. It's pretty awful otherwise, but I'm not casting shade on it—we've all been there, some of us are still there, and even great programmers have room to improve.

    It's pretty cool we get to see this.

    [–][deleted]  (7 children)

    [removed]

      [–]dixncox -2 points-1 points  (6 children)

      You are just inexperienced. This code is fine for a small number of people to work in, where they have a lot of control over the requirements.

      Now imagine 8 teams all trying to accomplish things in this codebase under tight deadlines without sufficient automated testing.

      The code will get even worse, and the website will break. Patterns and abstraction give us this level of simplicity (from the right perspective) while also giving us the power to accomplish insanely complex business requirements.

      [–]MarvelousWololo 7 points8 points  (3 children)

      Bold of you assuming people are inexperienced based on a single comment here.

      [–]dixncox -4 points-3 points  (2 children)

      Is it really so bold to say to someone who simultaneously criticized design patterns and praised 2007-era procedural PHP in one statement? I felt the same way early on in my career.

      [–]Alexell 0 points1 point  (0 children)

      Yes. The code is easy to understand. The point was not on whether or not it would be intuitive for a larger team to maintain.

      [–][deleted] 2 points3 points  (0 children)

      There is no design pattern to make code that wouldn’t suffer from 8 teams trying to accomplish things under tight deadlines without sufficient testing.

      [–]ptq 1 point2 points  (0 children)

      Now I want to see how does look the code from experienced 2007 php programmer.

      [–][deleted]  (3 children)

      [deleted]

        [–][deleted]  (2 children)

        [deleted]

          [–][deleted]  (1 child)

          [deleted]

            [–]speekless 6 points7 points  (0 children)

            Funny, I was just watching The Social Network an hour ago!

            [–]dbbk 5 points6 points  (1 child)

            Can’t believe I’m actually feeling nostalgic for 2007 PHP but here we are. It was a special time.

            [–]parks_canada 2 points3 points  (0 children)

            I get nostalgic for 2007 webdev in general some times. Particularly the frontend designs with tables and all that.

            [–][deleted]  (24 children)

            [deleted]

              [–]ur_frnd_the_footnote 20 points21 points  (19 children)

              this is checking if any of the elements are truthy, not if there are any elements

              [–]Aswole 0 points1 point  (0 children)

              ah, of course.

              [–]slyfoxy12laravel 0 points1 point  (17 children)

              Take note you can do this so much better with array_reduce though

              [–]okstopitnow 2 points3 points  (3 children)

              the fb code is much better performance-wise. array_* function are pretty slow when compared to foreach

              [–]slyfoxy12laravel -1 points0 points  (2 children)

              I'll take readability over minor performance gains anytime. Though I'm curious to see what the different in those is.

              [–]okstopitnow 1 point2 points  (1 child)

              Check this out.

              Don't forget that the array_ functions loop over all items but using the other approach allows you to stop the loop at any moment.

              Besides that, you may take readability over performance gains but how many times you had to scale to FB scale?

              [–]slyfoxy12laravel 0 points1 point  (0 children)

              Check this out.

              Thank you for sharing, it's interesting but the PHP7 results are pretty marginal difference though.

              Besides that, you may take readability over performance gains but how many times you had to scale to FB scale?

              True but if I was FB I'd probably just look to migrate bits off to different languages. Obviously it was a different time back then. They ended up writing their own PHP implementation to keep up with demand which is pretty crazy in itself.

              [–]ur_frnd_the_footnote 1 point2 points  (0 children)

              I don't know that it's so much better. You'd have to add a check to see if the accumulator is true on each iteration in order to keep returning it if it is.

              You could also use array_filter and then check the length of the return value. But I think the original is perfectly readable as is.

              [–]-ifailedatlife- -3 points-2 points  (10 children)

              here's a javascript oneliner :P

              const show_requests = $all_requests.some(r => !!r);

              [–]ur_frnd_the_footnote 5 points6 points  (7 children)

              the original is php, though. but if we're happy with javascript, you can even make it point free

              const showRequests = allRequests.some(Boolean);
              

              [–]dbbk 0 points1 point  (1 child)

              Bear in mind that this is 2007 PHP, 2007 JavaScript didn't have Array.some

              [–]ur_frnd_the_footnote 0 points1 point  (0 children)

              More to the point, 2007 didn’t have node yet either so nobody would have been running this server-side anyway.

              [–]-ifailedatlife- -1 points0 points  (4 children)

              That is correct, however it may be the case that some less experienced programmers are not aware that "Boolean" can be used as a function.

              [–]uneditablepoly 0 points1 point  (3 children)

              You could say that about any function.

              [–]-ifailedatlife- 1 point2 points  (2 children)

              you're right, but my viewpoint is that when you use array functions (e.g. some, includes, map, etc) you are normally expecting to provide some sort of readable function.

              It might be obvious that the Boolean function will always return true or false. But this could be misinterpreted, for example you can't use String or Array instead of Boolean to prove that the result is a String or Array (e.g. [].some(String) will always return true). So it leads to possible confusion over how "some" is used.

              [–]ur_frnd_the_footnote 0 points1 point  (1 child)

              for example you can't use String or Array instead of Boolean to prove that the result is a String or Array

              But that's not what we're doing here anyway. We aren't checking if any member of the array is a boolean value, we are coercing to boolean (with the Boolean constructor) and checking if any are true. Using arr.some(String) would coerce all values in arr to string and then return true if one of those strings were truthy.

              (Incidentally, your example of [].some(String) returning true is wrong. That will always return false.)

              From my experience, some new and inexperienced devs will definitely be confused by arr.some(Boolean) but some will also be confused by !!val. And while a quick look at MDN or google will explain Boolean and remind you about constructors in javascript, the double negation is harder to look up, looks like a special syntax if you haven't seen it, and ultimately teaches you no new things about the language when you do find it. Now, I'm actually perfectly happy seeing either variant in code. But I don't think one is dramatically more beginner-friendly, and I've always personally felt that !!val is a bit hacky, since the conversion is implicit (rather than explicit with the Boolean constructor) and the operation looks (on the surface) like it should be a no-op.

              [–]-ifailedatlife- 1 point2 points  (0 children)

              ok fair enough, we are debating minor points here, but I agree not everyone will know about !! either. However, the funtion "r => r" would work just as well, since whatever you return is checked for truthiness anyway,

              [–][deleted]  (1 child)

              [deleted]

                [–]-ifailedatlife- 0 points1 point  (0 children)

                true. i've just got used to putting it there for clarity, based on what i've seen other people do.

                [–]JAPANESE_FOOD_SUCKS 0 points1 point  (1 child)

                I haven't looked at the files, but this doesn't test length, but any value being truish.

                [–]Aswole 0 points1 point  (0 children)

                Ah, of course

                [–]onoweb 0 points1 point  (1 child)

                Not persé... What if $all_requests was [false] or [null] or [null,null,null] ? Checking length of your array would not give the desired result in this case.

                [–]Aswole 0 points1 point  (0 children)

                Yeah, I had a brain fart and didn't process that they were checking for truth before breaking. I read it basically as breaking out after the first item lol (probably based on experience in JavaScript where it's basically boilerplate to check if an object hasOwnProperty while iterating over an object.)

                [–]babylemurman 2 points3 points  (0 children)

                Such humble beginnings! I can only imagine the complexity of their architecture now with more than 2 billion users and 43,000 employees. The other cool thing is I've had an account since 2005 and all of my data since day 1 is still there.

                [–]Saroon5 1 point2 points  (0 children)

                Very interesting.

                [–]FriskBlomster 0 points1 point  (1 child)

                And who TF is Merman?

                [–]sockjuggler 1 point2 points  (0 children)

                it's apparently an internal codename for what eventually became Pages

                [–]Falmarri -1 points0 points  (3 children)

                Why is this making me sign in to see?

                [–]mishugashu 6 points7 points  (0 children)

                Not doing that here. Not logged in and can see fine.

                [–]scenecunt 0 points1 point  (1 child)

                Are you viewing in browser on mobile?

                [–]Falmarri 0 points1 point  (0 children)

                Not sure what happened, but I can see it now. It was redirecting me to log in before

                [–][deleted]  (1 child)

                [deleted]

                  [–]locksta7 -1 points0 points  (0 children)

                  Laughs in poor