PyCon: Evangelizing Python
Python core developer Raymond Hettinger's PyCon 2013 keynote had elements of a revival meeting sermon, but it was also meant to spread the "religion" well beyond those inside the meeting tent. Hettinger specifically tasked attendees to use his "What makes Python awesome?" talk as a sales tool with management and other Python skeptics. While he may have used the word "awesome" a few too many times in the talk, Hettinger is clearly an excellent advocate of the language from a technical—not just cheerleading—perspective.
He started the talk by noting that he teaches "Python 140 characters at a time" on Twitter (@raymondh). He has been a core developer for twelve years, working on builtins, the standard library, and a few core language features. For the last year and a half, Hettinger has had a chance to "teach a lot of people Python". Teaching has given him a perspective on what is good and bad in Python.
Context for success
Python has a "context for success", he said, starting with its license. He and many others would never have heard of Python if it were not available under an open source license. It is also important for a "serious language" to have commercial distributions and the support that comes with those.
Python also has a "Zen", he said, which is also true of some other languages, like Ruby, but "C++ does not have Zen". Community is another area where Python excels. "C is a wonderful language", but it doesn't have a community, Hettinger said.
The PyPI repository for Python modules and packages is another important piece of the puzzle. Python also has a "killer app", in fact it has more than one. Zope, Django, and pandas are all killer apps, he said.
Windows support is another important attribute of Python. While many in the audience may be "Linux weenies" and look down on Windows users, most of the computers in the world are running Windows, so it is important for Python to run there too, he said. There are lots of Python books available, unlike some other languages. Hettinger is interested in Go, but there aren't many books on that language.
All of these attributes make up a context for success, and any language that has them is poised to succeed. But, he asked, why is he talking about the good points of Python at PyCon, where everyone there is likely to already know much of what he is saying? It is because attendees will often be in a position to recommend or defend Python. Hettinger's goal is for attendees to be able to articulate what is special about the language.
High-level qualities
The Python language itself has certain qualities that make it special, he said, starting with "ease of learning". He noted that David Beazley runs classes where students are able to write "amazing code" by the end of the second day. One of the exercises in those classes is to write a web log summarizing tool, which shows how quickly non-programmers can learn Python.
Python allows for a rapid development cycle as well. Hettinger used to work at a high-frequency trading company that could come up with a trading strategy in the morning and be using it by the afternoon because of Python. Though he was a good Java programmer, he could never get that kind of rapid turnaround using Java.
Readability and beauty in a language is important, he said, because it means that programmers will want to program in the language. Python programmers will write code on evenings and weekends, but "I never code C++ on the weekend" because it is "not fun, not beautiful". Python is both, he said.
The "batteries included" philosophy of Python, where the standard library is part of the language, is another important quality. Finally, one of Hettinger's favorite Python qualities is the protocols that it defines, such as the database and WSGI protocols. The database protocol means that you can swap out the underlying database system, switching to or from MySQL, Oracle, or PostgreSQL without changing the code to access the database. Once you know how to access one of them through Python, you know how to access them all.
As an example of the expressiveness and development speed of the language, Hettinger put up a slide with a short program. In a class he was teaching, someone asked how he would deduplicate a disk full of photos, and in five minutes he was able to come up with a fifteen-line program to do so. It is a real testament to the language that he could write that program live in class, but even more importantly, he can teach others to do the same. That one slide shows "a killer feature of the language: its productivity, and its beauty and brevity", he said.
But, there is a problem with that example. A similar slide could be created for Ruby or Perl, with roughly the same brevity. That would be evidence for the "all scripting languages are basically the same, just with different syntax" argument that he hears frequently from software executives. But all scripting languages are not the same, he said. That may have been true in 2000, but "we've grown since then"; there are lots of features that separate Python from the pack.
Winning language features
First up on Hettinger's list of "winning language features" is the required indentation of the language. It was an "audacious move" to make that choice for the language, but it contributes to the "clean, uncluttered" appearance of the code. He claimed that Python was the first to use indentation that way, though he later received a "Miranda warning" from an audience member as the Miranda language uses indentation and predates Python. People new to the language sometimes react negatively to the forced indentation, but it is a net positive. He showed some standard examples of where C programs can go wrong because the indentation doesn't actually match the control flow, which is impossible with Python. Python "never lies with its visual appearance", which is a winning feature, he said.
The iterator protocol is one of his favorite parts of the language. It is a "design pattern" that can be replicated in languages like Java and C++, but it is "effortless to use" in Python. The yield statement can create iterators everywhere. Because iterators are so deeply wired into the language, they can be used somewhat like Unix pipes. So the shell construct:
cat filename | sort | uniq
can be expressed similarly in Python as:
sorted(set(open(filename)))
This shows how iterators can be used as composable filters. In addition,
Python has a level of expressiveness that is
similar to SQL, so:
sum(shares*price for symbol, shares, price in port)
will sum the number of shares times the price for all of the entries in
port, which is much like the SQL equivalent:
SELECT SUM(shares*price) FROM port;
Languages that don't have for loops that are as powerful as
Python's cannot really compete, he said.
One of his favorite things to teach about Python are list comprehensions. The idea came from mathematical set building notation. They "profoundly improve the expressiveness of Python", Hettinger said. While list comprehensions might at first appear to violate the "don't put too much on one line" advice given to new programmers, it is actually a way to build up a higher-level view. The examples he gave can fairly easily be expressed as natural language sentences:
[line.lower() for line in open(filename) if 'INFO' in line]
which creates a list of lower-cased lines that contain "INFO". The second seems
directly derived from math notation:
sum([x**3 for x in range(10000)])
which sums a list of the cubes of the first 10,000 integers (starting at zero).
Since list comprehensions can generally be expressed as single sentences,
it is reasonable to write them that way in Python.
The generators feature is a "masterpiece" that was stolen from the Icon language. Now that Python has generators, other languages are adding them as well. Generators allow Python functions to "freeze their execution" at a particular point and to resume execution later. Using generators makes both iterators and coroutines easier to implement in a "clean, readable, beautiful" form. Doing things that way is something that Python has "that others don't". His simple example showed some of the power of the feature:
def pager(lines, pagelen=60):
for lineno, line in enumerate(lines):
yield line
if lineno % pagelen == 0:
yield FORMFEED
Generator expressions come from Hettinger's idea of combining generators and list comprehensions. Rather than requiring the creation of a list, generators can be used in expressions directly:
sum(x**3 for x in range(10000))
From that idea, dictionary and set comprehensions
are obvious extensions, he said. Generator expressions are one way to combat
performance problems in Python code because they have a small memory
footprint and are
thus cache friendlier, he said.
But generators have a problem: they are a "bad date". Like a date that can only talk about themselves, generators can only talk, not listen. That led to the idea of two-way generators. Now generators can accept inputs in the form of send(), throw(), and close() methods. It is a feature that is unique to Python, he said, and is useful for implementing coroutines. It also helps "tame" some of the constructs in Twisted.
Decorators have an interesting history in Python. They don't really add new functionality that can't be done other ways, so the first few times they were proposed, they were turned down. But they kept being proposed, so Guido van Rossum (Python's benevolent dictator for life) used a tried and true strategy to make the problem go away: he said that if everyone could agree on a syntax for decorators, he would consider adding them. For the first time ever, the entire community came together and agreed on a syntax. It presented that agreement to Van Rossum, who agreed: "you shall have decorators, but not the syntax you asked for".
In retrospect, the resistance to decorators (from Van Rossum and other core developers) was wrong, Hettinger said, as they have turned out to be a "profound improvement to the language". He pointed to the lightweight web frameworks (naming itty, Flask, and CherryPy) as examples of how decorators can be used to create simple web applications. His one slide example of an itty-based web service uses decorators for routing. Each new service is usually a matter of adding three lines or so:
@get('/freespace')
def compute_free_disk_space(request):
return subprocess.check_output('df')
The code above creates a page at /freespace that runs df and
returns its output as a web page.
"Who's digging Python now?", he asked with a big grin, as he did in spots throughout the talk—to much applause. The features he had mentioned are reasons to pick Python over languages like Ruby, he said. While back in 2000, Python may have been the equivalent of other scripting languages, that has clearly changed.
There are even more features that make Python compelling, such as the with statement. Hettinger thinks that "context managers" using with may turn out to be as important to programming as was the invention of the subroutine. The with statement is a tool for making code "clean and beautiful" by setting up a temporary context where the entry and exit conditions can be ensured (e.g. files closed or locks unlocked) without sprinkling try/finally blocks all over. Other languages have a with, but they are not at all the same as Python's. The best uses for it have not yet been discovered, he said, and suggested that audience members "prove to the world that they are awesome", so that other languages get them.
The last winning feature that he mentioned was one that he initially didn't want to be added: abstract base classes. Van Rossum had done six months of programming in Java and "came back" with abstract base classes. Hettinger has come to embrace them. Abstract base classes help clarify what a sequence or a mapping actually is by defining the interfaces used by those types. They are also useful for mixing in different classes to better organize programs and modules.
There is something odd that comes with abstract base classes, though. Python uses "duck typing", which means that using isinstance() is frowned upon. In fact, novice Python programmers spend their first six months adding isinstance() calls, he said, and then spend the next six months taking them back out.
With abstract base classes, there is an addition to the usual "looks like a duck, walks like a duck, quacks like a duck" test because isinstance() can lie. That leads to code that uses: "well, it said it was a duck, and that's good enough for me", he said with a laugh. He thought this was "incredibly weird", but it turns out there are some good use cases for the feature. He showed an example of using the collections.Set abstract base class to create a complete list-based set just by implementing a few basic operations. All of the normal set operations (subset and superset tests, set equality, etc.) are simply inherited from the base class.
Hettinger wrapped up his keynote with a request: "Please take this presentation and go be me". He suggested that attendees present it to explain what Python has that other languages are missing, thus why Python should be chosen over a language like Ruby. He also had "one more thing" to note: the Python community has a lot of both "established superstars" as well as "rising young superstars". Other languages have "one or two stars", he said, but Python has many; just one more thing that Python has that other languages don't.
| Index entries for this article | |
|---|---|
| Conference | PyCon/2013 |
Posted Mar 27, 2013 19:03 UTC (Wed)
by kjp (guest, #39639)
[Link] (1 responses)
Exceptions are also great (cough cough GO), and the exception hierarchy in 3.x looks really good, although I haven't used 3.x yet. The async io and coroutines planned for 3.4 (yield from) also look really nice.
Also: never use import *, use pyflakes, be intentional about choosing function and module names so you can grep for them later, and life should be good :-)
Posted Mar 28, 2013 16:07 UTC (Thu)
by smurf (subscriber, #17840)
[Link]
In fact I wonder how many people, besides me ( see sqlmix on github ) wrote their own wrapper for the stuff?
Posted Mar 28, 2013 7:12 UTC (Thu)
by ncm (guest, #165)
[Link]
Every concentrated activity has Zen. To perceive the Zen of C++ requires great clarity of mind, perhaps greater than many can achieve. Fortunately there is important work for persons at every level of enlightenment to do.
Posted Mar 28, 2013 7:53 UTC (Thu)
by eru (subscriber, #2753)
[Link] (6 responses)
Maybe because it no longer needs a community, any more than the hammer or the screwdriver needs a community...
But I recall back when I was first learning C, there was a C community around magazines like The C User's Journal and Dr. Dobbs Journal. Later I learned a lot in the comp.std.c and comp.lang.c USENET newsgroups.
Posted Mar 28, 2013 15:43 UTC (Thu)
by ortalo (guest, #4654)
[Link]
Posted Mar 29, 2013 12:19 UTC (Fri)
by renox (guest, #23785)
[Link] (4 responses)
PC much?
Posted Apr 5, 2013 13:15 UTC (Fri)
by XTF (guest, #83255)
[Link] (3 responses)
Posted Apr 5, 2013 13:25 UTC (Fri)
by renox (guest, #23785)
[Link] (1 responses)
Posted Apr 5, 2013 13:49 UTC (Fri)
by XTF (guest, #83255)
[Link]
Posted Apr 5, 2013 19:47 UTC (Fri)
by andrel (guest, #5166)
[Link]
Posted Mar 28, 2013 9:58 UTC (Thu)
by jezuch (subscriber, #52988)
[Link] (2 responses)
Also, generators etc. are quite clearly an influence of functional languages that I'd like to see more of in the so-called mainstream languages.
Posted Mar 28, 2013 12:45 UTC (Thu)
by fsateler (subscriber, #65497)
[Link] (1 responses)
Posted Mar 29, 2013 8:10 UTC (Fri)
by marcH (subscriber, #57642)
[Link]
http://www.codinghorror.com/blog/2013/03/why-ruby.html
Posted Mar 28, 2013 11:54 UTC (Thu)
by marcH (subscriber, #57642)
[Link] (17 responses)
That's an incredibly weak promotion of readability that would be instantly dismissed by many managers.
Readability is critical because it helps maintain code faster, and with less bugs. => $$$$$ !
And as everyone here knows "Programmers are constantly in maintenance mode" ( http://pragmatictips.com/11 )
Posted Mar 28, 2013 13:28 UTC (Thu)
by dpquigl (guest, #52852)
[Link] (16 responses)
I personally find python much harder to read than any other language that I've ever used and I include prolog in this statement too. The lack of any type of type information in the language makes it so you hope someone names variables the right way so you have some semblance of how to use it. The do whatever and clean up the mess mentality of python is horrible too. No need to make sure that variable is actually a string. Just treat it as one and if it isn't catch some random exception and move on or let it blow up. Of course you won't know it blows up until after you're 500 lines into your script. Or worse you have a long running python process that hits a section of code after days of running and it blows up in there and you have to figure out wtf went wrong.
Posted Mar 28, 2013 13:47 UTC (Thu)
by tnoo (subscriber, #20427)
[Link] (8 responses)
Which never happened to me with C or C++... oh wait, segmentation faults, wrong dynamic casts,..
Posted Mar 29, 2013 8:31 UTC (Fri)
by marcH (subscriber, #57642)
[Link] (7 responses)
Comparing Python with C/C++ cannot go very far. They are at two completely different levels; completely different tools for different jobs.
It'd more interesting to know which _other_ high-level languages dpquigl is using on the WE.
Posted Mar 29, 2013 14:01 UTC (Fri)
by dpquigl (guest, #52852)
[Link] (6 responses)
Even though UE3 game logic is mostly written in Unreal Script the language itself was checked and some preliminary compilation was done before being cooked and packaged for deployment into the game. The most interesting feature that I found for unreal script was that classes had states and function overloading wasn't just on parameterization but also based on state. You could declare a function onFire in the default state but then also declare the same function in a state called currentlyFiring. Where onFire in the default state would start the gun firing and setup the animations and such calling onFire in the while firing state would endup being a noop for certain weapons to make sure that you couldn't fire during a reload. Alternative if your weapon was in the reloading state and you called onfire again certain weapons would cancel the reload like in the instance of a pump shotgun.
On top of that I've done enterprise work for Java and C# and have done web apps in both. I've been trying to learn ruby as well as python because even though I'm not a fan of weak typed scripting languages more and more is being written in it and standing still just means you get left behind.
One issue I have with python is that every time I've asked for the right way to do something the only thing I get from python advocates is that you're free to do it however you like. Except for the one time I did something which is apparently against the book in a language which from what I can tell is the free love movement of development. I needed to validate the types of data coming in from a json string and to do this I checked if the values I got back matched certain data types which apparently is a big no no in the world of python. Instead I'm supposed to use them as if they were those data types and wait for the world to explode when they aren't and pick up the pieces.
Another is that we see horribly written code which makes its way into the core of Linux systems being written in python. The initial code for all of the Xen services was written in python and it was a horrible mess and horrible to maintain. What did they do? They started transitioning it all into C system services. Python is great in that it makes programming accessible to people who never would have programmed to begin with. However python is also horrible for the same reason.
Posted Mar 29, 2013 14:06 UTC (Fri)
by dpquigl (guest, #52852)
[Link]
Posted Mar 30, 2013 3:57 UTC (Sat)
by nevets (subscriber, #11875)
[Link]
Another problem I have with Python is that if I don't use it for a while, I have to always get my Python book out and relearn it. I'm a C programmer and Python is just so foreign to me. I rather program in Perl.
Someone told me once that people who like to program in English prefer Python and those who prefer to program in math prefer Perl or C. I've also always had trouble reading pseudo code and preferred the actual code to look at.
Posted Mar 30, 2013 14:26 UTC (Sat)
by intgr (subscriber, #39733)
[Link] (3 responses)
I believe there's a misunderstanding there. You shouldn't do type-checking of data passed in internal APIs; if your function accepts a string parameter, you don't check that it's string every time -- just assume that the caller got it right. However, if you're decoding JSON received from untrusted sources, then that kind of type checking makes sense and is often required to prevent some kinds of security bugs. Case in point with Python 2: This hole is fixed in Python 3, but in general there are still surprises you can run into if you allow arbitrary types from untrusted input.
Posted Mar 30, 2013 20:53 UTC (Sat)
by tnoo (subscriber, #20427)
[Link]
Maybe I don't get it, but how should an undefined value d['age'] be compared to a number? The natural way is to compare int(d['age']) < 18. which won't give random behaviour. and which would be done in any sane language. Nice that it raises Type error in Python3.
Posted Mar 31, 2013 9:23 UTC (Sun)
by marcH (subscriber, #57642)
[Link] (1 responses)
> You shouldn't do type-checking of data passed in internal APIs; if your function accepts a string parameter, you don't check that it's string every time -- just assume that the caller got it right.
"internal" can mean internal to either: your host, your process, your jar, your file, your company, your department, your team,... where does the trust stop? The answer probably depends on the task at hand. There is no simple answer.
Searching for "Defensive Programming" should return a lot of simple - and extreme - answers. Make your own opinion somewhere in the middle...
Posted Mar 31, 2013 9:48 UTC (Sun)
by dark (guest, #8483)
[Link]
If you're parsing data from strings then by all means check that it's well-formed and that it's the kind of data you expect -- it's all under your control at that point.
If you're accepting a value from elsewhere, then it may make sense to do sanity checks on it, but those should be along the lines of "does it support the methods I expect to call on it", not "does it have the specific type I expect". The best example of this is file objects -- you really shouldn't enforce that it's a "file", you should let the caller pass in whatever file-like object is most convenient.
Most python code is simple enough that you can do those 'checks' just by calling the methods when you need them and getting an exception if they fail. But if you're about to insert such a received value into a complex system and you want to catch errors before they're deep in the stack then it may make sense to inspect the value a bit. Or just convert it -- calling int(value) or str(value) will throw exceptions right away, and the latter will let the value handle its own conversion.
Posted Mar 28, 2013 22:05 UTC (Thu)
by ibukanov (subscriber, #3942)
[Link]
Posted Apr 5, 2013 13:27 UTC (Fri)
by XTF (guest, #83255)
[Link]
Posted Apr 5, 2013 18:41 UTC (Fri)
by HelloWorld (guest, #56129)
[Link] (4 responses)
By the way: C is neither high-level nor strongly-typed. Sometimes it's better to remain silent, you know...
Posted Apr 17, 2013 21:56 UTC (Wed)
by dpquigl (guest, #52852)
[Link] (3 responses)
"I go home and code C or code in some other high level strongly typed language.".
That sentence does not mean that C is a strongly typed high level language.
Posted Apr 17, 2013 23:48 UTC (Wed)
by raven667 (subscriber, #5198)
[Link] (2 responses)
Posted Apr 17, 2013 23:51 UTC (Wed)
by rahulsundaram (subscriber, #21946)
[Link]
Posted Apr 18, 2013 16:03 UTC (Thu)
by dpquigl (guest, #52852)
[Link]
Posted Mar 28, 2013 12:58 UTC (Thu)
by mpr22 (subscriber, #60784)
[Link] (1 responses)
Posted Mar 29, 2013 8:51 UTC (Fri)
by marcH (subscriber, #57642)
[Link]
Mr Hettinger was not expressing his personal opinion. He was much bolder than that. The sentence "it's a beautiful" is a commonly accepted language short-cut for "most people find it beautiful".
(I'm not interested in arguing either)
Posted Mar 28, 2013 14:50 UTC (Thu)
by pspinler (subscriber, #2922)
[Link] (10 responses)
For example, I can't reliably count on being able to copy and paste code segments from my colleague's emails (especially email sent from outlook, bleah). I've even found this issue when attempting to read and reuse code published on some web pages.
otoh, for a language that uses syntax markers for flow of control, copied code will work as copied regardless of indentation, and auto-indentation tools will always correctly restore the code to a readable status.
-- Pat
Posted Mar 28, 2013 15:58 UTC (Thu)
by mpr22 (subscriber, #60784)
[Link] (9 responses)
Posted Mar 28, 2013 18:24 UTC (Thu)
by jwakely (subscriber, #60262)
[Link] (8 responses)
Posted Mar 30, 2013 12:25 UTC (Sat)
by thoeme (subscriber, #2871)
[Link] (7 responses)
Posted Mar 30, 2013 17:58 UTC (Sat)
by jwakely (subscriber, #60262)
[Link]
Posted Mar 30, 2013 18:44 UTC (Sat)
by smurf (subscriber, #17840)
[Link] (5 responses)
You use indentation in pretty much every other high-level programming language, otherwise you won't understand your code tomorrow.
Related to this, about everybody I know has written (or debugged) at least one piece of interesting C code like
Interestingly, the idea of indentation as primary syntax seems to spread to other contexts.
Posted Apr 5, 2013 4:16 UTC (Fri)
by welinder (guest, #4699)
[Link] (4 responses)
That's actually wrong.
When a tab sneaks in you so get to make those mistakes and there is
In C you don't get to make those mistakes. If it's important
Posted Apr 5, 2013 6:19 UTC (Fri)
by smurf (subscriber, #17840)
[Link] (2 responses)
The Python community has more-or-less agreed on the second option; personally I strongly prefer the third. But that's as much bikeshedding as whether a C open brace goes on the same line as the if statement, or below it (and if so, which indent does it get?)
This kind of mistake (mixing up tabs and spaces) is so easy to check for that Python actually has an option for it. Which C compiler checks for "wrong" indentation on nested statements?
Posted Apr 5, 2013 7:02 UTC (Fri)
by dlang (guest, #313)
[Link] (1 responses)
If you are a full-time programmer who works in a nice, dedicated environment, you may end up with a nice tailored config.
But, like most sysadmins, I have to support software on all sorts of systems, many of which I haven't ever touched 5 minutes before I'm working on the code.
by the way, this is why I'm a vi person. every system has some variation of vi that I can run to get the job done. other editors, it's not the same thing.
Posted Apr 8, 2013 21:08 UTC (Mon)
by wtanksleyjr (subscriber, #74601)
[Link]
That's why I stopped trying to learn APL, by the way. So I do agree with your basic concern.
But it's really not accurate to say that Python requires an editor with a specific configuration. I have to edit Python with Notepad from time to time, and nothing breaks. It's simply a matter of comfort and caution to use an editor that won't make it easy to do things that screw up code -- but the language doesn't care.
So many times I have to edit code that a hardware engineer or a skilled, dedicated sysadmin (who isn't a double-classed programmer-sysadmin like I am) has previously modified. Very commonly I'll find random indentation (hardware engineers are the worst -- I recall cases where every newly added line of C was added flush left, no indentation at all, in the middle of properly indented code; and then no attempt was made to bring the result back upstream).
It's a minor thing to note that Python CAN be told to error out if the indentation is mixed in any way; by default it only errors out if the indentation is completely ambiguous, or if it contains spaces before tabs on the same line.
> But, like most sysadmins, I have to support software on all sorts of systems, many of which I haven't ever touched 5 minutes before I'm working on the code.
Same here. And I'll also say that Python is usually not the first choice of sysadmins -- Perl is usually much closer to a sysadmin's basic toolbox, and much much further away from a programmer's, while Python makes all the sysadmin tools take more typing to use.
> by the way, this is why I'm a vi person. every system has some variation of vi that I can run to get the job done. other editors, it's not the same thing.
Hahahaha. You work with SANE systems. Healthy systems. I work with systems where sometimes the only choice is vi, and sometimes the only choice is notepad.exe.
Anyhow, if you can't install your editor, you can't install a language. You're stuck with what you've got. In my case, I switch between bash, powershell, and cmd.exe. If I took your complaint seriously, I would have to hate using powershell and bash because they aren't available on all the platforms. Naw... Better to simply and silently resent the corporate choices that made the better choice unavailable.
We're stuck with the corporate tools we're given. (Pun intended but unindented.)
(BTW -- I'm a vi guy too, given the chance.)
-Wm
Posted Apr 5, 2013 8:42 UTC (Fri)
by intgr (subscriber, #39733)
[Link]
Note that this is fixed in Python 3, it gives you a "TabError: inconsistent use of tabs and spaces in indentation"
Posted Mar 28, 2013 16:13 UTC (Thu)
by southey (guest, #9466)
[Link]
Posted Mar 28, 2013 17:22 UTC (Thu)
by wookey (guest, #5501)
[Link] (4 responses)
Posted Mar 28, 2013 19:12 UTC (Thu)
by serzan (subscriber, #8155)
[Link] (3 responses)
Python itself does not enforce any specific paradigm (OO was only added afterwards) and its idea of OO is very relaxed compared to java/c++.
Also, I find that perl/shell are terrible for writing non-trivial scripts because handling exceptions requires so much more discipline than with python.
Posted Mar 29, 2013 13:25 UTC (Fri)
by tnoo (subscriber, #20427)
[Link]
OO was at the core of the language from the very beginning. The oldest documentation I found was version 1.4 (1996) which makes frequent references to Modula and C++.
But I agree that Python does not enforce any specific paradigm, or rather, effortlessly combines all of them. This is an asset, especially getting students to program data analysis scripts, which probably have never seen anything else than Basic or Matlab. The power of OO is still there, and can be easily used even in procedural programs.
Posted Mar 28, 2013 18:49 UTC (Thu)
by jschrod (subscriber, #1646)
[Link] (18 responses)
And something like yield I've used in Barbara Liskov's CLU many decades ago. Good to see that it starts to arrive in mainstream languages, too.
Posted Mar 29, 2013 8:04 UTC (Fri)
by marcH (subscriber, #57642)
[Link] (17 responses)
Or rather: those who know it will "steal with pride" what's good in it and leave the rest.
Posted Mar 29, 2013 10:47 UTC (Fri)
by jschrod (subscriber, #1646)
[Link] (16 responses)
It doesn't mention the source of yield either, and even attributes it to Icon. (yield is called suspend there. And Ralph Griswold clearly knew the work of Barbara Liskov, made 3 years earlier, and published in relevant ACM SIG journals.) Even the ultra-short Wikipedia page of CLU acknowledges who came up with yield first - Barbara Liskov, the brilliant scientist who formulated the concept of abstract data types, exceptions, iterators, and many other things first.
Posted Mar 29, 2013 13:03 UTC (Fri)
by marcH (subscriber, #57642)
[Link] (15 responses)
http://mail.python.org/pipermail/python-dev/2005-May/0537...
Looks like C++' RAII was more influential though and much closer to the final feature.
You don't really think any serious language designer group reinvents the wheel without looking at other languages, do you?
Posted Mar 29, 2013 13:56 UTC (Fri)
by jschrod (subscriber, #1646)
[Link] (14 responses)
Well, no (designers), partly (documentation and review) and yes (evangelists).
In my experience, actual language designers know about the concepts. Then it's documented, and the influences are not part of the rationales, though they should be (witness the cited PEP). Then evangelists (witness the talk from the article) come and present 30+ year old stuff as innovative concepts that's the best thing since sliced bread. Reading the article, I couldn't refrain from commenting - you seem to take that much more as an attack as it's meant to.
My comments are not meant specific for Python, you could also look at Javascript with its obvious roots in Self (which pioneered prototype-instance based OOPL) mentioned in almost no documentation.
Posted Mar 29, 2013 18:04 UTC (Fri)
by marcH (subscriber, #57642)
[Link]
Fair enough.
> you seem to take that much more as an attack as it's meant to.
Well, it was an attack on "someone"... vague. Quite clearer now.
Posted Mar 30, 2013 14:49 UTC (Sat)
by intgr (subscriber, #39733)
[Link] (12 responses)
> Then evangelists (witness the talk from the article) come and present 30+ year old stuff as innovative concepts that's the best thing since sliced bread
Did he ever claim that these ideas were invented in Python? Did he say the word "innovative" even once in the talk?
All he said is that these features set Python apart from other "scripting languages", wtih Perl and Ruby brought out as examples. It's a true factual statement.
Lisp isn't even on the radar for being a competitor to Python.
Posted Mar 31, 2013 9:46 UTC (Sun)
by marcH (subscriber, #57642)
[Link] (7 responses)
> All he said is that these features set Python apart from other "scripting languages", wtih Perl and Ruby brought out as examples.
In such a promotion speech context omitting references/credits creates a very fine line between the two. I can imagine the speaker saying the latter and the most of the audience misunderstanding the former (of course we'll never know).
I don't think there should be things like "credits" in reference documents like PEPs (PEPs seem to have pointers to discussions which is more than enough).
On the other hand I (finally) agree with jchrod: I expect a "Python's awesome" talk to give credit where it's due. Not just for honesty but also to help me develop my general software engineering culture and better understand *how* to create awesome things, i.e., by standing on the shoulder of giants, recombining existing ideas in new ways, and not patenting trivial prior art.
Posted Apr 1, 2013 16:16 UTC (Mon)
by kleptog (subscriber, #1183)
[Link] (6 responses)
I hope people aren't just referring to lisp's ability to transform source code at compile time because that (IMO) trivialises what the with-statement adds to the language: the ability to factor out certain idioms that would otherwise require explicit handling of exceptions. There's a difference between "language X makes it possible to do idiom Y" and "language X includes explicit support for idiom X".
While it may be that lisp did it first Python is the only contemporary language I know that includes something like the with-statement, which does say something.
Posted Apr 1, 2013 18:16 UTC (Mon)
by nybble41 (subscriber, #55106)
[Link] (1 responses)
Both expressions execute a block of code with a guarantee that some other code will be executed when control leaves the block, no matter how that happens (e.g. normal exit, exception, calling a continuation). Operations built on top of this mechanism often start with "with-" by convention, e.g. "with-open-file" (Common Lisp) and "call-with-input-file" (Scheme) both ensure that the file provided to the inner block is closed afterward.
[1] http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node96.html
Posted Apr 1, 2013 22:57 UTC (Mon)
by nix (subscriber, #2304)
[Link]
Posted Apr 2, 2013 16:15 UTC (Tue)
by lab (guest, #51153)
[Link] (3 responses)
The C# 'using' statement?
Posted Apr 2, 2013 17:06 UTC (Tue)
by hummassa (subscriber, #307)
[Link] (2 responses)
Posted Apr 2, 2013 17:23 UTC (Tue)
by intgr (subscriber, #39733)
[Link] (1 responses)
1. Python's "with" statement is more flexible, it has access to the exception when it occurs. A "with db_transaction():" block can automatically decide to commit or roll back, unlike C++/C#. You can also implement something like "with ignore_exception(OSError):"
2. Python doesn't require you to create a local variable to hold the state; this always annoys me when using the RAII pattern to hold locks in C++.
3. Prettier syntax ;)
Posted Apr 2, 2013 19:13 UTC (Tue)
by hummassa (subscriber, #307)
[Link]
Posted Apr 5, 2013 12:59 UTC (Fri)
by gvy (guest, #11981)
[Link] (3 responses)
Posted Apr 6, 2013 16:01 UTC (Sat)
by pboddie (guest, #50784)
[Link] (2 responses)
Posted Apr 6, 2013 16:18 UTC (Sat)
by jake (editor, #205)
[Link]
http://code.activestate.com/lists/python-announce-list/9602/
jake
Posted Apr 10, 2013 11:09 UTC (Wed)
by gvy (guest, #11981)
[Link]
Posted Mar 28, 2013 23:26 UTC (Thu)
by man_ls (guest, #15091)
[Link] (6 responses)
That has happened to me: I have to confess I am infected too. I have used Python for several years and it has served me well. But something about it was a bit bland: at its core it did not seem to trust functional programming but had to disguise it with comprehensions and yields. It was finally the transition from 2.x to 3.x did me in: really shoddy engineering; and that is not even the point.
Now I have seen really intelligent people moving JavaScript forward, doing very interesting stuff on the client and creating one of the most incredible ecosystems in Free software with npm. Few people are missing anything in Python out there, and it is really astonishing to me as Python is quite elegant and JavaScript tends to be horrible. And yet JavaScript works better and seems to be better suited for anything in real life.
Posted Mar 29, 2013 8:27 UTC (Fri)
by marcH (subscriber, #57642)
[Link] (3 responses)
Functional programming in Python is a bit of a mystery. On the one hand it is seriously good at it and on the other hand the BDFL is not a big fan:
http://www.artima.com/weblogs/viewpost.jsp?thread=98196
Actually... by not scaring users away with functional syntax, Python might have done more for functional programming than functional languages, introducing many more people to it. Maybe that was Guido's secret or subconscious plan?
Oh and by the way: object oriented stuff is totally optional in Python and can be completely forgotten when not appropriate. A massive relief for anyone coming from... here for instance:
> It was finally the transition from 2.x to 3.x did me in: really shoddy engineering;
Care to elaborate a bit?
Posted Mar 29, 2013 11:07 UTC (Fri)
by man_ls (guest, #15091)
[Link] (2 responses)
I have spoken a lot about it in the past and received a lot of interesting feedback, so allow me to say just that a different solution would have been much appreciated and might have eased the divide, should such a divide be absolutely necessary (something that I am not sure).
On to the subject of the non-rivality with JavaScript: the PyPI has currently 29444 vs 26256 for npm; in a couple of years node.js is almost at the same number of packages, and that is without counting the huge number of browser-specific libraries. npm is still accelerating. It is hard to find comparable statistics of total downloads and such, but the most popular PyPI package is lxml which has seen about 8M downloads, while the most starred npm package (right on the front page), the web server framework express, has seen 1/17th as many downloads in the last month alone.
It is interesting how Python developers don't seem to see JavaScript as the competition and instead focus on Ruby. For me they cover a very similar space: both are scripting languages that have overstepped their boundaries, both multi-paradigm (although in the case of JavaScript "paradigm" is a bit charitable) and both contenders for the successor of Perl as "the duct tape of the internet".
Posted Apr 4, 2013 7:04 UTC (Thu)
by sayap (guest, #71380)
[Link] (1 responses)
Debian Python maintainer is not very good at his job: http://lwn.net/Articles/496335/ Be grateful that you even have Python 2.7. Also, a quick Google search shows that MacPorts has packages for Python3.
> On to the subject of the non-rivality with JavaScript: the PyPI has currently 29444 vs 26256 for npm
You are comparing a "batteries included" language with one that doesn't have a standard library.
Posted Apr 4, 2013 7:52 UTC (Thu)
by man_ls (guest, #15091)
[Link]
Posted Apr 4, 2013 20:42 UTC (Thu)
by joib (subscriber, #8541)
[Link] (1 responses)
In addition to the above, personally in python land I've used numpy/scipy/matplotlib extensively to do calculations and plotting stuff; AFAICT javascript/node/npm doesn't have anything coming close to those. But in the grand scheme of things that's perhaps a somewhat esoteric use case. Then again, servers capable of handling tens of thousands of concurrent connections seem pretty esoteric as well (to me, at least!)..
Posted Apr 9, 2013 5:59 UTC (Tue)
by marcH (subscriber, #57642)
[Link]
(The language matters, but the "ecosystem" matters probably even more.)
Posted Apr 5, 2013 12:26 UTC (Fri)
by ThomasBellman (guest, #67902)
[Link]
And occam a couple of years before that.
Posted Apr 6, 2013 12:16 UTC (Sat)
by Duncan (guest, #6647)
[Link] (2 responses)
I'm surprised nobody else seems to have commented on this so far. I thought most computers were running Linux these days, with Android pushing Linux over the top?
Not that I've cared enough to actually track it myself, but that's the impression from what I've read. But even if it's a plurality not a majority, I believe it has been awhile since the MS slogan of "A computer on every desktop" has been supplanted by (roughly speaking) "A computing device in every pocket", and most of those, as well as most of the servers serving them, as well as a good portion of the routers routing between the two, run Linux. MS may still rule the desktop, but the desktop's only a small portion of the computing world these days, and getting smaller literally by the minute.
Of course the claim wouldn't be our editor's fault, rather the fault of the guy doing the presentation (and thus making the claim) being covered. Tho it's still disruptive enough a claim as to merit an editorial parenthetical or footnote disclaimer, I'd think. It certainly was here.
Posted Apr 6, 2013 13:13 UTC (Sat)
by hummassa (subscriber, #307)
[Link]
Is it funny to remember that the first time I read something like that was in Bill Gates' book?
Posted Apr 9, 2013 6:05 UTC (Tue)
by marcH (subscriber, #57642)
[Link]
I like my Android phone and tablet very much but I don't use them to write Python code.
Yes the desktop PC market is shrinking fast yet it remains the only way to get work done. I don't see mobile or couch devices changing this any time soon.
Note: I wrote "desktop PC"; not "Windows".
Posted Apr 6, 2013 19:42 UTC (Sat)
by chrisV (guest, #43417)
[Link]
Except that it isn't. This has been available in spidermonkey's ECMAscript implementation for ages (since 1.7?). Any language which provides delimited continuations can implement this, which includes GNU guile's scheme implementation (where I have working code which does this), and no doubt most of the other functional languages can do something similar.
PyCon: Evangelizing Python
I have to second your gripe about the DB-API. It's fundamentally non-Pythonic in other way, too: I would like to write
DB-API
import Db
db = Db.connect(whatever)
for x,y in db.select("select x,y from foo where bar=${baz}", baz=123):
do_something(x,y)
"C++ does not have Zen"
Zen?
"C is a wonderful language", but it doesn't have a community,
PyCon: Evangelizing Python
PyCon: Evangelizing Python
Such things are far from finished.
PyCon: Evangelizing Python
C is probably the language I know the best, but I totally disagree that C is a wonderful language, it's a language which doesn't know whether it is should be a portable assembly language or a high level language, so it fails at both.
PyCon: Evangelizing Python
PyCon: Evangelizing Python
Unless by "wonderful" you mean "full of undefined behaviours just waiting to hurt the developers" ( http://blog.regehr.org/archives/category/compilers ) in which case I agree.
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
> I needed to validate the types of data coming in from a json string and to do this I checked if the values I got back matched certain data types which apparently is a big no no in the world of python. Instead I'm supposed to use them as if they were those data types and wait for the world to explode when they aren't and pick up the pieces.
def check_age(data):
d = json.loads(data)
if d['age'] < 18:
print "You must be 18 or older to continue."
else:
print "OK!"
>>> check_age('{"age": 13}')
You must be 18 or older to continue.
>>> check_age('{"age": "13"}')
OK!
PyCon: Evangelizing Python
PyCon: Evangelizing Python
It's not really about trust. It's about embracing duck typing.
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
In that case you've probably chosen the wrong tool for the job.
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
*sigh* Beauty is subjective, Mr Hettinger. Please do not mistake your opinion of the beauty of languages for fact - or, if you don't so mistake it, please don't speak in a manner liable to convey the impression that you do.
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
My main practical annoyance with Python's use of indentation as the exclusive syntax for block structure is that it interferes with convenient use of the REPL for testing code snippets (since rectangle select is approximately never as convenient to use as linewise select). I also find the whole business of needing to care about indentation, when in a delimited-block language my text editor can do 100% of the caring-about-indentation for me, a positively retrograde step.
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
Why should Python's indentation be a problem?
PyCon: Evangelizing Python
The only difference is that Python uses the indents directly, while most other languages require redundant clutter like braces or BEGIN-END keywords to tell the compiler what to do.
if (foo)
if (bar)
baz();
else
quux();
You simply don't get to make these mistakes in Python.
Cf. CoffeeScript or HAML.
PyCon: Evangelizing Python
nothing that visually tells you anything. Things line up neatly,
but don't actually work.
then you can see it.
PyCon: Evangelizing Python
Or tell your editor to not use tabs at all. Again, simple.
Or tell your editor not to use spaces (i.e. ony Python indent == 1 tab) and make the tabs wide enough that you can't miss any misalignment.
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
Since LWN.net will not do so and the video has the vague title of Keynote, the video URL isJust watch and listen to him!
http://pyvideo.org/video/1669/keynote-3
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
Those who don't know Lisp are condemned to reinvent it.
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
http://starship.python.net/crew/mwh/pep310/8.txt
PyCon: Evangelizing Python
> wheel without looking at other languages, do you?
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
PyCon: Evangelizing Python
[2] http://www.schemers.org/Documents/Standards/R5RS/HTML/r5r...
PyCon: Evangelizing Python
PyCon: Evangelizing Python
http://msdn.microsoft.com/en-us/library/yh598w02(v=vs.110).aspx
PyCon: Evangelizing Python
PyCon: Evangelizing Python
1. std::uncaught_exception() allows for your commit/rollback scenario, but not your ignore_this_exception scenario. The latter does not seem a good idea to me, but...PyCon: Evangelizing Python
2. the lock thing can be implicit... it's a matter of how you do it. Anyway,
{
some_lock_t lock(x);
x.do_something();
}
does not seem sooo wrong to me... although I usually put it on X and do
x.do_something_locked<some_lock_t>();
only, or even
some_locking_scaffold(x).do_something();
and this last one is really easy.
3. it's not! :-D
PyCon: Praising Python for all the wrong reasons
Yeah, especially given Steel Bank Common Python. Crap, the radar you use must be from '60s!
PyCon: Praising Python for all the wrong reasons
PyCon: Praising Python for all the wrong reasons
PyCon: Praising Python for all the wrong reasons
Python vs JavaScript
Python vs JavaScript
http://python-history.blogspot.com/2009/04/origins-of-pyt...
http://steve-yegge.blogspot.com/2006/03/execution-in-king...
Python vs JavaScript
Care to elaborate a bit?
Sure, it is just the incompatibility between Python 2.x and 3.x code: it forces library developers to choose to support one or the other, instead of offering a common ground (which developers have found on their own but is still a bit cumbersome). To this day the default packages carried by Debian and Mac OS X (the two operating systems I use) are 2.x, so there is little incentive to upgrade most libraries.
Python vs JavaScript
Python vs JavaScript
You are comparing a "batteries included" language with one that doesn't have a standard library.
True for JavaScript, but node.js does a good job of supporting a fair standard library.
Python vs JavaScript
Python vs JavaScript
PyCon: Evangelizing Python
Most computers running Windows?
Most computers running Windows?
Most computers running Windows?
PyCon: Evangelizing Python
