Reddit in 61 minutes and 97 lines of PHP

I read this article, about a guy who made a Reddit clone in 10 minutes in Clojure. He was inspired by this guy, who made a Reddit clone in Lisp in 20 minutes and a hundred lines.

I’m so sick of Lisp hackers. Functional programming is pretty awesome, but every single Lisp/Erlang/Haskell/Clojure/Emacs guy thinks Lisp is the greatest thing since list processing (what?).

So I implemented Reddit in (properly formatted) PHP in 97 lines. Granted it took a bit longer, but I had to remember how to use the low-level mysql_* functions. Oh, and I used MySQL. I don’t know what the Lisp people used for data persistence. Some of the lines were taken up by CSS and JavaScript, and making things look nice(r).

Reddit in 61 minutes of alone time with Notepad++

Reddit in 61 minutes of alone time with Notepad++

Source | Playground

I hate Lisp people.

February 3, 2010   Posted in: php, rants

15 Responses

  1. Joe Derek - February 3, 2010

    Ow my eyes.

  2. Piyush - February 3, 2010

    Very true. Lisp people suck. Bitches

  3. zakk - February 3, 2010

    Hahaha! Well done guy!

  4. Lau B. Jensen - February 3, 2010

    Hey,

    Great idea to do the same exercise in PHP. You’re running a little short on features, so here’s what you need to implement in order to do a direct comparison:

    * Add the specific error messages which both Lisp variants have
    * Show 2 lists, first sorted by points, second by age
    * Show the duration between posting and now, instead of a datetime
    * Put the 2 input boxes on their own separate page
    * Serve this from your own webserver, as both Lisp variants not only serve pages but run entire webservers.

    Feel free to drop a line once you implement the missing features, I’ll be very interested in seeing the code + the total time spent producing it.

    Best regards,
    Lau

    ps: Sorry you think we’re so annoying :) Come hang out with us on #clojure/irc.freenode.net, if you want a quickstart with Lisp. There’s a friendly crowd who’s happy to help out.

  5. Dan - February 7, 2010

    Hey I would be interested in getting this working, send me an email, thanks!

  6. Reddit Clone — Now accepting registrations! | BEST IN CLASS - February 9, 2010

    [...] This guy, actually sat down and wrote out a Reddit Clone in PHP, which I thought was amazing — If PHP could do the same as Clojure in only 6 extra lines I would be greatly impressed — However it lacked the almost every feature except rendering links. [...]

  7. anon - February 9, 2010

    wow, talk about fail. Let’s count, shall we:
    1) Didn’t reproduce all of the functionality of the other examples.
    2) DB connection is never closed
    3) SQL Injection galore
    4) Cross site scripting galore
    5) HTTP response spliting

    way to prove all the negative comments about php devs.

  8. admin - February 10, 2010

    @anon

    1) probably. i didn’t really read them that well, i haven’t coded any lisp since college.
    2) who cares? it’s one page, and the connection closes when the script ends (that’s how php works).
    3) actually, not. hundreds of people tried, nothing actually happened.
    4) actually, not. everything is escaped properly. see the documentation on htmlspecialchars() and htmlentities().
    5) actually not. everything is properly sanitized.

  9. Malicart - February 10, 2010

    @Admin: You forgot something in your rebuttal.

    *way to prove all the negative comments about lisp devs.

    Hi Reddit!

  10. Dan - February 13, 2010

    can you do a tutorial on how to set this up?I tried to get it to work here: http://thebay.comlu.com/reddit%20clone2.php

  11. Nick Tulip - March 2, 2010

    Compress the js and css and we’re down to 90 lines. awesome!

  12. Than - June 4, 2010

    Um… where’s the source? Link just goes to the playground…

  13. tmont - June 5, 2010

    @Than – It disappeared in my switch to nginx. It now resides here.

  14. Zarek - July 22, 2010

    Can you please upload the SQL query used to create the table for this? I am trying to set it up at http://zarek2.co.cc/lollit/ but I need the SQL query to set up the database. Thanks

  15. tmont - July 23, 2010

    @Zarek


    CREATE TABLE `links` (
    `link_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `url` varchar(300) NOT NULL,
    `title` varchar(1000) NOT NULL,
    `votes` int(11) NOT NULL DEFAULT '0',
    `date_posted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`link_id`)
    ) ENGINE=InnoDB

    Go wild.

Leave a Reply