Slashdot Mirror


Interviews: Guido van Rossum Answers Your Questions

Last week you had a chance to ask Guido van Rossum, Python's BDFL (Benevolent Dictator For Life), about all things Python and his move to Dropbox. Guido wasted no time answering your questions and you'll find his responses below. From Google to Dropbox
by nurhussein

Hi, What prompted the move from Google to Dropbox? What did you do at Google, and what are you going to do at Dropbox?

Guido: After seven years at Google I was just ready for some change in environment, and then the Dropbox offer came along. At a high level, my job hasn't changed much: I still

- spend 50% of my time on whatever I want to do for Python in my BDFL role
- am a regular engineer in the organization (not a manager or even TL)
- do a lot of code reviews, architecture and design work
- handle a lot of email
- do a lot of actual coding for my job, in Python

The specifics differ of course. I really did only two things at Google: the first two years I worked on one of the first online code review tools Mondrian, which itself was never open-sourced but begat Rietveld, which did, and is used amongst others, by the Python, Go and Chromium communities. After that I joined Google App Engine where I did a lot of different things, almost all of them in Python. My last big project there was a new Python database API, NDB.

I've been at Dropbox for 7 months and my main project has been the design of the Dropbox Datastore API . It's ironic but not my fault that this also uses the "datastore" moniker -- there's little overlap between Dropbox Datastores and the Google App Engine Datastore.

What's even more ironic is that even though I did much of the design, and wrote two prototypes in Python, the SDKs we released last month only support Java, Objective-C and JavaScript. But I am working on a fix, this interview is just slowing me down. :-)



Why did Python avoid some common "OO" idioms?
by i_ate_god

Interfaces, abstract classes, private members, etc... Why did python avoid all this?

Guido: I can think of two reasons: (a) you don't really need them, and (b) they are hard to do if you have no compile-time type checking. Python started out as a skunkworks project (not endorsed or encouraged by management but not actively prevented), and I wanted results quickly. This led me to remove features that weren't actually needed or urgent; it also led me to do all type checking at run time, which gave me natural constraints on what features Python could support. I also had no religious OO ax to grind -- I just wanted an easy language, and it became OO more or less by accident.

In modern Python there are rough equivalents for all of these, but they don't necessarily work all that well, or they cause a lot of execution overhead, so they are often avoided, but they have their uses and their fans.



functional programming
by ebno-10db

Some people claim that Python is, at least partly, a functional language. You disagree, as do I. Simply having a few map and filter type functions does not make for a functional language. As I understand it those functions were added to the libraries by a homesick Lisper, and that several times you've been tempted to eliminate them. In general it seems you're not a fan of functional programming, at least for Python.

Question: do you feel that the functional programming approach is not very useful in general, or simply that it's not appropriate for Python? It would be nice to hear your reasons either way.


Guido: I'm not a fan of religiously taking some idea to the extreme, and I try to be pragmatic in my design choices (but not *too* pragmatic, see the start of this sentence :-). I value readability and usefulness for real code. There are some places where map() and filter() make sense, and for other places Python has list comprehensions. I ended up hating reduce() because it was almost exclusively used (a) to implement sum(), or (b) to write unreadable code. So we added builtin sum() at the same time we demoted reduce() from a builtin to something in functools (which is a dumping ground for stuff I don't really care about :-).

If I think of functional programming, I mostly think of languages that have incredibly powerful compilers, like Haskell. For such a compiler, the functional paradigm is useful because it opens up a vast array of possible transformations, including parallelization. But Python's compiler has no idea what your code means, and that's useful too. So, mostly I don't think it makes much sense to try to add "functional" primitives to Python, because the reason those primitives work well in functional languages don't apply to Python, and they make the code pretty unreadable for people who aren't used to functional languages (which means most programmers).

I also don't think that the current crop of functional languages is ready for mainstream. Admittedly I don't know much about the field besides Haskell, but any language *less* popular than Haskell surely has very little practical value, and I haven't heard of functional languages *more* popular than Haskell. As for Haskell, I think it's a great proving ground for all sorts of ideas about compiler technology, but I think its "purity" will always remain in the way of adoption. Having to come to grips with Monads just isn't worth it for most people.

(A similar comment applies to Scala. It may be the best you can do trying to combine functional and OO paradigms in one language, but the result isn't all that easy to use unless you're really smart.)



Multi-line lambdas
by NeverWorker1

One of the most common complaints about Python is the limitations of its lambdas, namely being one line only without the ability to do assignments. Obviously, Python's whitespace treatment is a major part of that (and, IIRC, I've read comments from you to that effect). I've spent quite a bit of time thinking about possible syntax for a multi-line lambda, and the best I've come up with is trying to shoehorn some unused (or little used) symbol into a C-style curly brace, but that's messy at best. Is there a better way, and do you see this functionality ever being added?

Guido: Really? I almost never hear that complaint except from people who submit questions to Slashdot interviews. :-)

There is indeed a better way, and that is using the 'def' keyword to define a regular function in a local scope. The defined function object becomes a local variable that has exactly the same semantics as a lambda except that it is bound to a local variable, and it doesn't have any of the syntactic constraints. For example, there is *no* semantic difference between

def make_adder(n):
__def adder(x):
____return x + n
__return adder

and this equivalent using lambda:

def make_adder(n):
__return lambda x: x + n

(except that when you introspect the lambda asking for its name, it will say '' instead of 'adder').

Andrew Koenig once pointed out to me that there's one pattern where lambdas are really much more convenient, and that is if you have a long list or dict (perhaps some kind of switching definition) containing lots of lambdas, since if you wanted to do that without lambda you'd end up first having to define lots of little functions, giving them all names, and then referencing them all by name from inside the list or dict. But in that pattern the lambdas are usually simple enough to be lambdas, and if you have a few exceptions, using 'def' before starting the list or dict is a fine compromise.



PyPy
by Btrot69

Do you see PyPy as the future? Or do you remain unconvinced, and -- if so -- why ?

Guido: I'm still unconvinced, for two reasons: (a) they don't support Python 3 (well) yet, and (b) there are lots of extension modules (both third party and in the standard library) that they don't support well. But I hope they'll fix those issues. I think it's competition from projects like PyPy, Jython and IronPython that keeps the CPython project honest and on its toes.



Python in the browser ?
by Btrot69

Over the years, there have been several attempts to create a sandboxed version of python that will safely run in a web browser.Mostly this was because of problems with Javascript. Now that Javascript works -- and we have nice things like CoffeeScript -- is it time to give up on python in the browser ?

Guido: I gave up on it in 1995, so yes. And please don't try to compile Python to JavaScript. The semantics are so different that you end up writing most of a Python runtime in JavaScript, which slows things down too much. (CoffeScript's strength is that it is designed to map cleanly to JavaScript, and the two are now co-evolving to make the mapping even cleaner.)



Python 3
by MetalliQaZ

How do you feel about the current state of the migration to Python 3 (Py3k)? From a user perspective it seems that the conversion of popular libraries has lagged far behind, which has impeded the transition. In my professional capacity, nearly every single system I use lacks an installed 3.x interpreter. In fact, 2.7 is a rarity. I'd like to get your thoughts.

Guido: Curious where you work. I agree that Python 3 migration will still take a long time, but if your systems don't come with Python 2.7 they must be pretty ancient! When I left Google they were about done with the internal transition to Python 2.7 (having successfully migrated from 2.4 to 2.6 over the past few years) and here at Dropbox both the client and the server are using Python 2.7. Both companies are already thinking about Python 3 too.

Back to Python 3 migration, I am actually pretty optimistic. Lots of popular libraries have a working port or are working on one. (The Python Software Foundation also occasionally funds projects to port libraries that are widely used but don't have enough of a community to do a port.) It will take a long time, but I see a lot of progress, and in a few years I expect most new code will be written in Python 3. Totally eradicating Python 2 usage will probably take much longer, but then again, Windows XP isn't quite dead yet either. :-)



Key question for any language designer
by dkleinsc

Have the prospects of Python in any way improved since you grew a beard? To what degree does language success correlate to beard length?

Guido: It is absolutely essential. Just look at Perl's fate -- Larry Wall is just too clean-shaven. :-)

24 of 169 comments (clear)

  1. Broaden your functional horizons, Guido! by EricTheGreen · · Score: 3, Interesting

    but any language *less* popular than Haskell surely has very little practical value, and I haven't heard of functional languages *more* popular than Haskell.

    There is this language called Lisp. Might have heard of it before.

    Erlang, also.

    I understand the kiddies are feeling the Clojure love these days as well (although I suppose that just ends up categorized as a Lisp subset)

    C'mon Guido, you're smarter than this...

    1. Re:Broaden your functional horizons, Guido! by DuckDodgers · · Score: 4, Insightful

      If Lisp was going to take over the world, or even just be used in as much as 10% of the software created in any given year, it would have done it already. That, I think, is the entire reason why Clojure ( and before Clojure, Scheme and Racket, https://en.wikipedia.org/wiki/Racket_(programming_language), and since Clojure, Hy http://docs.hylang.org/en/latest/ ) have been created - attempts to tweak the Lisp formula into something more palatable for the mainstream without losing any of the core features that make the language useful.

      I wish Lisp and Clojure were more prevalent. Most of my work experience is with Java, and now that I've become comfortable with Lisp and Clojure in my spare time I'm chafing at the tools I have to use for work. There just aren't that many jobs around, at least outside Silicon Valley, that use either language. So I'm trying to do useful Clojure stuff in my spare time in order to have a portfolio I can show off for a Clojure shop.

      But to your point, I think Guido is safe to dismiss Lisp - it's a spectacular functional language, it's one of the most well known functional languages, and at least in original and Common Lisp form it just can't get traction in the mainstream.

    2. Re:Broaden your functional horizons, Guido! by phantomfive · · Score: 2

      FWIW Lisp isn't a functional programming language; it has functional parts, but it's a multi-paradigmatic language that includes object oriented programming. So yeah, it can be used like that, but modern Lisp is much, much more.

      Incidentally, currently my favorite part of Lisp that I wish was in other languages is the way the variable binding allows for easy dependency injection, even in places where it wasn't originally designed that way. It makes unit testing a lot easier.

      --
      "First they came for the slanderers and i said nothing."
    3. Re:Broaden your functional horizons, Guido! by ebno-10db · · Score: 2

      Even though I have mixed feelings about the Lisp family of languages, I wish they would become more popular. I've never been convinced that it's the One True Approach, but for some things they're great.

      Unfortunately, much of the Lisp(s) community is the biggest enemy of the broader adoption of Lisp(s). Part of the problem is that one has to refer to Lisp(s) in the plural. Common Lisp is clearly the most powerful variant, but it's byzantine in its (unnecessary) complexity and redundant features, as well as still using a standard from 1985 (the later ANSI standard didn't change much). I understand that CL started as an attempt to unify various Lisp dialects, which explains its byzantine and redundant features. But that was 27 years ago! They could have moved towards deprecating parts of it. Allow it to compiled with a switch that says "accept deprecated", "warn on deprecated" or "forbid deprecated". The libraries also need some serious updating. 27 years ago people didn't expect networking and graphics in standard libraries, but times change. The usual rebuttal that there are many such libraries is part of the problem. Lisp is the ultimate in herding cats.

      Scheme turns that around. It started as a "toy" language for teaching, but 30+ years still doesn't have standard features needed in a powerful language (e.g. a module system). R6RS tried to fix that, but was largely rejected by the implementers. R7RS is supposed to fix that, but we'll see. Meanwhile Racket (and other implementations) go off and do their own thing (albeit Racket has pragmas to enforce R5RS or R6RS compatibility).

      Now along comes Clojure. I haven't even looked at it because my reaction is that the last thing the world needs is YALV (Yet Another Lisp Variant). Undoubtedly Clojure fans will tell me what's newer and betterer about it, but it's still YALV.

      Lastly there's the attitude of a small but vocal minority of Lispers who believe Lisp(s) are the One True Approach, are condescending towards anyone who doesn't accept that as an article of faith, and argue that every drawback of Lisp(s) is actually an advantage that lesser programmers don't appreciate. If their goal is to keep Lisp(s) a niche language used only by the self-proclaimed cognoscenti, they're doing a damn good job of it.

    4. Re:Broaden your functional horizons, Guido! by DuckDodgers · · Score: 2

      Then you and I are using different criteria to measure practicality - though I suspect my criteria line up more closely with Guido's criteria than yours.

      No matter how effective a tool is, if it's not in mainstream use that's a significant mark against its practicality. Four decent Lisp developers might be able to build a particular piece of business software faster and with fewer errors than fifteen decent Python developers - but if I can't find four decent Lisp developers in the local market, I'm still going to pick Python when I start the project.

    5. Re:Broaden your functional horizons, Guido! by DuckDodgers · · Score: 2

      Right. But nobody in the Lisp community has the authority to fix the situation - and as you noted, the community is full of people who are opposed to any such fix, so the chances of someone entering the community to fix it is small.

      So the best possible solution, weak though it may be, is to create something new that just borrows strengths from Lisp but is intentionally different. Clojure is that kind of attempt at a fresh start, and it breaks some Lisp syntax (using square brackets in some cases) and intentionally does not have compatibility with the Common Lisp standard. Maybe that's more balkanization, but maybe these intentionally more different offshoots have a chance to succeed when the dialects that are closer to each other have failed.

      If you read articles on Lisp dialects on Github, the sad news is that Emacs Lisp configuration files are the most popular Lisp variant. That's great for fans of Emacs, not so great for people who want to see Lisp widely adopted. Outside of those files, the two most popular Lisp dialects are Clojure and Racket - which I believe are the two versions of Lisp that are furthest from the Lisp core family.

      Armed Bear Common Lisp is a full Lisp implementation on the JVM. To my knowledge its popularity is miniscule. Clojure is newer, not a standard Lisp, and it's used hundreds of times as often.

    6. Re:Broaden your functional horizons, Guido! by Anonymous+Brave+Guy · · Score: 4, Insightful

      If you're going to depend on a set of public libraries instead of an included set, they you had better verify them for quality. This is why Python's "batteries included" stance is so good. You can depend on the basic libraries.

      Ironically, that's actually one of my biggest concerns about using Python. IME, the included batteries aren't very good, once you get past the first few parts of the library reference that everyone uses all the time. A lot of the later parts -- things like file and directory manipulation, data formats and compression tools, process control, networking, even some of the date/time functionality -- have elements that are horribly slow, platform-dependent, or simply too bug-ridden to trust in production.

      It's unfortunate that package management in Python is such a mess, mostly for historical reasons. There's quite a bit of good stuff on PyPI these days, and if we were starting over, I think we'd do better to limit the standard library to a much smaller set of essential foundations, and to promote the best libraries from outside sources via the standardised package repository and tools.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    7. Re:Broaden your functional horizons, Guido! by Half-pint+HAL · · Score: 2

      Actually, if other language designers were smarter, other languages would use indenting for blocks.* Eliminating redundancy is a general aim in computing. Languages that use curly brackets or other delimiters for blocks are unreadable unless they also use indenting. And once you have the redundancy of both delimiters AND whitespace you have the danger that the two may not be in agreement. Which is compounded by the one that the compiler relies on (delimiters) not being the same as the one that stands out most to the human (indenting.)

      Using indents for blocks has a drawback in that standard text editors aren't good at matching the indent level when cutting and pasting. But that simply means that only Python aware editors should be used for python code. Not difficult when most programmers use IDEs.

      * (Which is what you actually mean. Scope relies on more than whitespace.)

      You have almost achieved enlightment, grasshopper, but you have yet to catch that fly with your chopsticks...

      Q: Why is (for example) C reliant on human intervention for both curly-bracing and indentation? A: Because coders have a fetish for "human-readable" source code that can be used in a "dumb" text editor.

      Now, you state that the solution to the Python copy-and-paste problem is a "Python-aware" editor... so why shouldn't the solution to the braces/indentation redundancy in C, Java etc. be a C-/Java-aware editor? The user inserts the curly braces, and the editor automatically manages spaces. I'm working in Python just now, and for all the things I love about it, the indentation still messes me up

      The most common bugs in my code are when I end multiple blocks simultaneously (I tend to deindent either too far or not far enough) and forgetting to change IF to ELIF when I add a higher precedence case as the first IF condition above it. I never make this latter mistake in C or Javascript, and the reason is a quite simple question of task design and psychology. In Python, when I'm finished writing the body of the branch, I feel "finished", but the curly-brace notation of C etc makes "finishing" an active process, so I don't just stop dead...

      --
      Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
  2. He did answer one question by buchner.johannes · · Score: 2, Funny

    He did answer one question once and for all. The smiley closes the bracket.
    https://xkcd.com/541/ All hail the BDFL

    --
    NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
  3. whitespace by photonic · · Score: 2, Interesting

    I know about all the religious arguments pro or against whitespace as syntax. Personally, I am a happy user of python and I actually like the forced indentation, YMMV. But please slashdot, why do you screw up the indentation when the inventor of a whitespace-as-syntax-language gives a code example? This will be too easy for anyone arguing against the use whitespace of syntax.

    --
    karma police: arrest this man, he talks in maths; he buzzes like a fridge, he's like a detuned radio. [radiohead]
    1. Re:whitespace by Anonymous Coward · · Score: 5, Insightful

      What do you mean, too easy? That's exactly what's wrong with making indentation part of the syntax. It's too easy to break. It's only fitting that code given by the head honcho of Python falls victim to reformatting. It is literally his own fault.

    2. Re:whitespace by Anonymous Coward · · Score: 4, Insightful

      I have found that everyone who complains about The Python Whitespace Thing are people who have convinced themselves that they are special little snowflakes and therefore any attempt to limit their creative output on whitespace use must be some kind of crime against humanity. Any time I get code in a free-whitespace language from someone like that, I need to run it through a code formatter before it's readable.

      You are not special. Your unique ideas about how to indent code are not special, so fucking indent your code according to the standard. The fact that Python mandates proper indentation is a feature, not a bug. The fact that C lets you throw the whole program on one line is a bug, not a feature.

    3. Re:whitespace by countach74 · · Score: 4, Insightful

      I do a fair bit of programming in Python and curly-bracket languages (C, C++, JavaScript, PHP, etc.) and interestingly, a forgotten/misplaced curly bracket in any of those various curly-bracket languages seem to break my code vastly more often than indentation issues do. Your code should *always* be indented. Python whitespace should already be there in all of your code (minus an occasional tweak here and there). Why complain about having to write {} less frequently?

    4. Re:whitespace by Anonymous Coward · · Score: 5, Insightful

      You can run my code through a code formatter if you don't like my choice of coding convention. You can not fix the broken code from the story by running it through a code formatter, because the inadvertent reformatting destroyed its meaning.

    5. Re:whitespace by tuffy · · Score: 2

      Or you could've saved weeks of your life by running the pep8 tool on your code, which will tell you all the lines that aren't indented by a multiple of 4, or which lines have tab characters in them, or any number of other formatting problems that aren't recommended by the style guide.

      --

      Ita erat quando hic adveni.

    6. Re:whitespace by Half-pint+HAL · · Score: 3, Interesting

      I do a fair bit of programming in Python and curly-bracket languages (C, C++, JavaScript, PHP, etc.) and interestingly, a forgotten/misplaced curly bracket in any of those various curly-bracket languages seem to break my code vastly more often than indentation issues do.

      Yes, but there's a rather huge difference: when you forget to close a block in C, your compiler completely flakes out as your {s and }s don't match. Your procedures don't close -- syntax error and fall over. However, if I forget to close a block in Python, this results not in a syntax error, but a logical error that the interpreter is not aware of. The block will be closed, even if only when I define my next class or procedure.

      So you've got to weigh up frequency-of-occurrence against cost-of-incident....

      --
      Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
    7. Re:whitespace by AuMatar · · Score: 2

      If you have to follow a style guide to get compiling code, your language is broken. If you have to know of the existence of a one off tool to get compiling code, your language is broken. The fact that tool even needs to exist is proof of my point.

      --
      I still have more fans than freaks. WTF is wrong with you people?
  4. To answer GvR's question by MetalliQaZ · · Score: 3, Informative

    I asked the Python 3 question and to answer Guido's question of me; I work at a large conglomerate that does a lot of defense contracting. In my area we deal with aerospace applications and so our linux systems are not Internet-facing. They are real-time systems that run simulations and data-acquisition. As you might expect, they only get upgraded when they really need it. We had a PDP-11 down in the lab until 2010.

    I'm not sure why I mentioned my workplace other to demonstrate how distant Py3k can seem to be. My main concern was the apparent lack of 3.x support in the big libraries out there. PIL is a great example. Also PyPy. It seems to me that there are many users that will only upgrade when the 3rd party libraries require it.

    --
    "Here Lies Philip J. Fry, named for his uncle, to carry on his spirit"
    1. Re:To answer GvR's question by EvanED · · Score: 3, Informative

      Just to add my input, in the CS department at my university, the Linux that is currently in use is RHEL, the latest version of which (RHEL6) ships with 2.6.6.

      Now that said, we also have several other Python installations available from nonstandard locations, and a [i]python[/i] shell alias for me runs 2.7.3 and [i]python3[/i] runs 3.2. (Huh, 3.3 is available. I should update that.)

      Also, the Python project that I use that it'd be nice to see support Python 3 is SCons, and there's some talk of that going on and they'll get there eventually, but it's not clear when.

    2. Re:To answer GvR's question by codealot · · Score: 4, Informative

      I was a little surprised by GvR's answer to this. RHEL 6 ships with Python 2.6, last I checked, and we don't normally deviate from Red Hat packages without good reason. Getting the masses off pre-2.7 versions of Python will also entail releasing newer OS distributions and retiring older ones, both of which happen slowly.

      Not everyone can keep up with the latest/greatest versions out there, especially when they have hundreds of servers and big legacy applications to support.

    3. Re:To answer GvR's question by mrvan · · Score: 2

      And in theory you can write all the compute-expensive routines in C++.

      Sure, but then that's not Python being fast, it's C++ being fast. "You could write the expensive parts in C or C++" can be said of nearly any language. :-)

      Not quite. In java and most other languages I know, you would have to make quite some changes to the rest of the code to get it to communicate with something written in C.

      In CPython, you can replace a module and the rest of the code won't notice, e.g. in

      import mymodule
       
      x = mymodule.compute_answer()

      mymodule can be a python module or a c module and you really don't need to know or care. You can build the prototype in python and later replace it with a C module, and unittest and benchmark both. You can even do it conditionally, e.g. replace mymodule by something like

      try:
        from mycmodule import compute_answer
      except ImportError:
        from myfallbackmodule import compute_answer

      And the same original code would use the c module if available, and otherwise the fallback module.

      Even if you don't do any of this, you do get benefits, since the expensive parts of the standard library and 'computational libraries' like numpy are written in C. If you can write your problem with efficient use of these functions, especially turning loops into vector/matrix calculations that are done by numpy, you can get the speedup without writing a single line of C. I've actually sometimes encountered a slowdown after reimplementing in C because all the expensive bits were in library calls that were apparently better written than my rewrite.

      Finally, there are tools like cython which allow you to add type hints to your python code that compile to C code. This will be slower than hand written C code, but require a lot less changes to the module and is less error prone, and in my experience can easily give a 10x speedup with a couple of "int" hints, especially in nested loops.

  5. Re:Summary by ebno-10db · · Score: 2

    borking up the whitespace in a Python code sample? That ain't OK at all.

    It may have to do with a sloppy HTML conversion by Slashdot or something, but it is ironic.

    P.S. I'm actually a fan of the Python/Haskell whitespace approach.

  6. Re:Functional programming is no harder than OOP by phantomfive · · Score: 2

    But sure, just carry on 'dissing functional programming and alienate some more of your core users.

    After that post, I seriously doubt you are a core user.....

    --
    "First they came for the slanderers and i said nothing."
  7. Re:Functional programming is no harder than OOP by MetalliQaZ · · Score: 2

    Did you read what he said? He wasn't dissing functional programming. His point was that FP features require powerful compilers. Python doesn't have that kind of compiler. Therefore the features don't have much use to Python.

    By the way, I don't believe they made the print function to be intuitive. They made it because print had no reason to be a statement. Also who said that tuples are more important than arrays? Arrays are really a concept for lower-level languages. Tuples, lists, and dictionaries are higher-level concepts that might be implemented with arrays behind the scenes. Lists function similarly to how many people visualize arrays. The beauty of tuples is that they are immutable, which means that they never change and can be thought of as a single, meaningful package with its contents. In contrast, lists have to be thought of as containers that can contain unknown things that may change at any moment.

    --
    "Here Lies Philip J. Fry, named for his uncle, to carry on his spirit"