Why Reddit uses Python

During Steve Huffman’s and Alexis Ohanian’s Pycon Keynote, someone asked why Reddit was moved from Lisp to Python. The reason for moving wasn’t too interesting, but why they have stayed is. Steve gave two “huge” reasons Reddit continues to use Python:

The biggest thing that has kept us on Python … well, there are two huge things. One are the libraries. There’s a library for everything. We’ve been learning a lot of these technologies and a lot of these architectures as we go. And, so, when I didn’t understand connection pools, I can just find a library until I understand it better myself and write our own. Don’t understand web frameworks, so we’ll use someone else’s until we make our own. Don’t understand a lot of stuff. And Python has an awesome crutch like that. And now, as we’ve been learning more, pulling more stuff back in house β€” just so we can have things the way we like them β€” it’s made the transition super super easy.

The other thing that keeps us on Python, and this is the major thing, is how readable and writable it is. When we hire new employees … I don’t think we’ve yet hired an employee who knew Python. I just say, “everything you write needs to be in Python.” Just so I can read it. And it’s awesome because I can see from across the room, looking at their screen, whether their code is good or bad. Because good Python code has a very obvious structure. And that makes my life so much easier. […] It’s extremely expressive, extremely readable, and extremely writable. And that just keeps life smooth.

The question gets asked around 25:54 on the video.

23 thoughts on “Why Reddit uses Python”

  1. I watched the PyCon talk in full before reading this blog and I was also struck by what he said about Python. I have written Python and Lisp and without a doubt Python is easier to understand. I instantly understood and agreed with Steve’s comments about being able to see good code. Like every programmer, I have code that I’m proud of and code that I’m less than happy with. When I open up the bad code in emacs, well, it just looks yucky. Simply on an aesthetic level, it looks cluttered and repetitious.

  2. I understand the structure of Python code, but to say you can tell who is a good writer simply by glancing at the structure is retarded.

    Anyway, If you are looking for a great python writer, I’m your man. I indent. πŸ˜‰

  3. I disagree that Python is readable. Sure, it’s more readable than C or PHP. However it is far from perfect. There are a lot of ugly and bizarre things going on in Python code.

    Unfortunately I think C# and Java are far more readable. Python is a good language, dont get me wrong. I am a Python programmer. I just think its readability is highly overrated. It is easier to write Python code. I think the ease of writing Python fools developers into believing it is more maintainable/readable.

  4. to say you can tell who is a good writer simply by glancing at the structure is retarded.

    He did elaborate in an answer to a question later in the session. He said that it is, for example, very easy to see repetitive structures in python code just by glancing at it and thereby pick up things that should probably be refactored and generalized. It does not necessarily mean that the programmer is bad, just perhaps new to python.

  5. You got to be kidding, Dave K.

    If you said Ruby is easier to read than Python, I could agree (as long as you understood the DSL the code is written in). If you said Smalltalk is readable, I could agree, since I am used to the alien syntax conventions. People may praise Lisp (as long as your IDE keeps track of the parenthesis). But how the hell you came up with Java and C#?!

    Those languages are overly verborrhagic and complicated for no reason but to be compatible with C-oriented pretty printers (without getting any of C’s simple elegance). Something that says the same in five times more sentences, several of them more complex, is absolutely not more readable.

  6. I agree with rbanffy. Java and C# are really cool languages for a lot of reasons, but readability isn’t one of them.

    Also, I cant wait for python on LLVM…mmmmmm

  7. Sorry, I should have elaborated a bit. When coded well, in a readable fashion, then Java/C#/Delphi/Lisp/etc are much more readable than Python. They lend themselves to be more English-like when variables/objects are named well. Python seems to want to force coders not to use readable naming conventions.

    I think the Perl-ish/bash-ish nature of Python makes it inescapably ugly. For example: def, and the forced use of “self” everywhere.

    Just my two cents.

  8. Those languages are overly verborrhagic and complicated for no reason …

    It’s the verborrhagicity that makes them more readable.

    Java/C# may have involve more _slightly_ more “typing” (pun not intended) but I don’t see how they’re more complicated than Python. Python seems to go out of it’s way to save keystrokes, but in doing so the language is less readable, which makes Python more complicated to deal with.

  9. What you guys are saying is that Java and C# are more readable because of static typing right? As being more verbose make your code easier to read, like knowing when a block start/ends and that a comand ends when a ; happens?

    This is because when you are reading code you looking for what the mechanics of the language are doing, and not what pythonistas mean when they say readable that is knowing what the program is meant to do in a more broad sense (not only pythonistas but most of the smalltalk/python/ruby crowd mean). The diference is between knowing what words are in a text and what the text mean.

    We don’t care if variable “x” is an int, but that it is being used to index another object in the line “my_dict[x]”. Maybe this difference in what we want from code is because usually when you have at least an small amount of unittests for a program (or some deep knoledge of its workings) when you are fixing a bug you are looking for an error in logic not in the details (not that you are not going to have this other kind of error in a python program, just that they are much less frequent).

    or maybe I’m just feeding the trolls again.

    ps: the self thing is really just prejudice, you have to learn why the self is there and them you are going to make peace with it.

  10. Verbosity may mean slightly more code to write, but in my experience it seems to actually be easier to read verbose code – it provides more structure and context to each statement/line

  11. it seems to actually be easier to read verbose code – it provides more structure and context to each statement/line

    Assume you have two equal length lists of integers (list1 and list2), and you want to create a list that contains the corresponding pairs of integers.

    In Java:

    class Pair {
        int first;
        int second;
    }
    
    List getPairs(List list1, List list2) {
    
        assert list1.length == list2.length;
    
        List acc = new ArrayList();
        for (int i = 0; i > list1.length; i++) {
            Pair pair = new Pair();
            pair.first = list1[i];
            pair.second = list2[i];
            acc.add(pair);
        }
        return acc;
    }
    

    Are you seriously going to argue that this is more readable than:

    def get_pairs(list1, list2):
        assert len(list1) == len(list2)
        return ((list1[i], list2[i]) for i in enumerate(list1))
    

    Does the same thing, in Python. We don’t need “Pair” since tuple is a built-in type, but even if you discount the definition of “Pair”, you still are talking about 8 lines of imperative code versus one line of a very readable generator expression. Not to mention that the Python single line is more scalable/performant than the Java version, due to the fact that get_pairs returns a generator rather than a fully-allocated list. To write the equivalent in Java, I’d have to implement an Iterator, and you don’t even want to know how many lines of code that would take, and how many opportunities for errors there are!

  12. What you guys are saying is that Java and C# are more readable because of static typing right?

    No. They’re saying shorter and more readable are not the same thing.

  13. Just as people sometimes think that brief == readable, many programmers also confuse readable == maintainable. None of these things are the same. And very often, getting one means losing another. Sometimes getting very high-performance, multi-threaded, or … code requires sacrificing one or more of the above.

    Also, it’s silly to throw out trivial examples (like getPairs) where sometimes language syntax can be argued either way. I don’t know Python. I can venture a guess as to what the get_pairs example code does above, but I wouldn’t be sure. But it’s _very_ clear what the Java code does (and I don’t know Java either). Then again, what about any language with list comprehensions?

    [ {A, B} || A <- List0, B <- List1 ]

    Is that more readable because it’s more terse? Show that to anyone who has never seen a list comprehension or doesn’t know Erlang and I think you’d have a hard time arguing that it’s more readable. But it’s certainly more maintainable (imo). Then again, how about showing a non-programmer some Qt UI code in Python vs. say… Hypercard:

    set the text of field "Name" to "Jeff"

    That’s a heluvalot more readable than the Python would be, but also more verbose. At the end of the day it. comes down to this simple fact:

    Working code is good code.

    Plain and simple. I know many of you will argue that. But you can spend forever iterating code trying to get it just right, and never actually ship anything. You can waste time debating whether to use Python or Lisp or C or Smalltalk, but that’s just time you are wasting vs. getting the project to market. I’ve seen very “experienced” programmers who couldn’t actually complete anything they were so stuck in the details, and I’ve seen novice programmers with BASIC turn out some pretty amazing things.

  14. It is really easy to see from comments who have and who have never tried writing python code :) I have done extensive coding in all of the languages mentioned here (bar Smalltalk) and I can say that I easily second the original opinion – in no other language can developer express his/her logic more clearly than in python.

    It’s also one of the rare languages where the more you think about / refactor your code the smaller *and* clearer it becomes – which is an inherent magic property of that language, it seems :)

  15. I also have experienced this “code shrinkage” piramida speaks of, although I find myself quite embarassed by it. I honestly think that it is just proof that I am evolving as a programmer, and that my code is never perfect…darn!

    In any event, I like Python because it allows one to propose quick solutions to computational Biology, Chemistry (et al) problems. It is easy to integrate with MATLAB. I once wrote an interface to MATLAB in 1 hour with Python. It is very friendly to folks in the hard sciences.

  16. def get_pairs(list1, list2):
        assert len(list1) == len(list2)
        return ((list1[i], list2[i]) for i in enumerate(list1))
    

    WHY? WHY?

    def get_pairs(list1, list2):
        zip(list1, list2)
    

    Python reads better because common collections are integrated directly into the language where they belong and because functions are first class.

    If Java had that, I would not have minded the static typing one bit. C# is heading in a more sane direction in this respect. I nevertheless tolerate, even enjoy static Java at times because of the strict adherence to idioms by its programmers and the wonderful IDEs that it is blessed with, which make navigating, modifying and examining the code easy.

    Java guys: Don’t debate type inference and properties as if your language is the only programming language in the entire world and as if you have to figure all this out carefully, all by yourself. They have been implemented many times before and no one ever regretted them adopting them.

    Or lets just get a decent IDE for Scala and forget about Java. Without a decent IDE, Scala’s higher constructs don’t mean much for productivity when the Java libraries are verbose and low level.

  17. And it’s awesome because I can see from across the room, looking at their screen, whether their code is good or bad. Because good Python code has a very obvious structure. And that makes my life so much easier.

    Your awesome code auditing methods explain why reddit has remained in a broken state for as long as I can remember.

  18. As much as I like Python, its really a love/hate relationship. My biggest problem with it is the lack of type definitions and the lack of structure. Tracking down bugs and figuring out what type of an object thing is supposed to be can be a nightmare. The fact that any object can have a new member added to it at anytime, isn’t fun to track down. Yes this all smells like bad coding styles to begin with, but when you have to modify someone elses code and figure out what is going on (mainly workin with alot of objects and classes) it can be a pain.

    Personally it would have been nice for python to allow for type declarations if the coder wanted to use them. Code is much easier to scan and bugs much easier to track down.

  19. Tracking down bugs and figuring out what type of an object thing is supposed to be can be a nightmare.

    You’re not _supposed_ to know (or care) what type something is. What you have to keep track of is what you expect it to be able to do, and that only to a certain extent.

    With “easier to ask forgiveness than permission” and duck typing such an integral part of the language, you’re not going to be happy if you don’t learn to love and use those.

  20. BTW the self in a class funtion can be named anything you want it to be, I for one find it way less confusing and less distracting if I don’t have to proclaim the variables beforehand.

    Thogh it is true that python may be slow on some places ,those weaknesses are easy to overcome, easier than using C++ or those low level program languages.

  21. def get_pairs(list1, list2):
    zip(list1, list2)

    * In c# list1.zip(list2)
    * In lisp (zip list1 list2)
    * In haskell (forgot but the same)
    * In Ruby (forgot but the same)
    * Java, 20 lines of code:)

    The two biggest features that pyhton has over c# are multiple inheritence and native support for aspect oriented programming.
    I like the forced indentation aswel, but this is only a notational question. Its a shame these features are not in c#, but I don’t seen any technical reason that they can’t be introduced.

    Of all languages I currently like c# the most because it has closures, generics are implemented reasonably, it is reasonably fast, it integrates well with c++, has very nice api’s and has a very user friendly IDE.

Comments are closed.