59 points · by mattdw · 16y ago · 80 comments
Compared to older scripting languages (Perl), Python offers a sane language and a rich programming environment.
Compared to other current popular scripting languages (Ruby), Python offers a solid runtime and better out-of-the-box performance at the expense of some elegance and fluency.
Comprare to some very interesting languages (Haskell, Erlang, Scala) Python is more widely available and allows you to produce good, portable, well-performing code quickly and easily.
It's a state of flux. Right now Python is my language of choice (after ten years of Ruby) and it touches that sweet spot of expressiveness and performance. However, the bolted-on features (verbose object system, clumsy metaprogramming) deliberate crippling of language (e.g. one line lambdas) and the underlying message of "there's one way to do it" (which is my way, because I know better than you) will, for me, mean that eventually I will move on. More expressive, coherent and flexible languages will eventually reach Python's current level of maturity and performance, and then it will be time to switch. It could be MacRuby, Scala or F# (but probably not Haskell or Erlang). Who knows.
But, for now, Python is a good choice.
Edit: typos.
Although, Ruby doesn't have any iteration constructs as nice as Python's generators. (You could create them using call/cc, but I expect the performance would be awful).
Scala code compiles to Java bytecode, and performs comparably to Java code. It's just as portable and performant as Java, which means very portable and fairly performant.
Yeah, absolutely not true. You need to do a little more research before you say very silly things like this.
the author has a good point about pure functional languages being better-suited for concurrent programming, though
Those of us who use python are often coming from C++, perl, etc. and know all too well what happens to languages that try to add every feature that someone might find useful.
If you want to use a lazy purely functional language, you know where to find one. It's not python.
If you want a language that allows you to express your inner emotions by using your personal pet programming style, this isn't it either.
That would be Lisp. ;-)
My own Python code, over time, became more and more functional in style until eventually I jumped ship to Clojure and Yeti (and over the past week, F#).
[1]: http://github.com/mbrubeck/outline-grep
But there wasn't anything in Python that I found compelling so I never came back.
As a scripting language, Ruby seems so much more compelling, despite it's friendliness seeming to doom it to eternal slow bugginess. I'd go back to Ruby before Python.
But I'm more likely to add Python support to an app I'm developing, since I know it's more sensible.
Python's functional aspects seem chronically undeveloped so leaving it for a real functional language makes sense. But functional approaches seem limited in the "real world".
Then again, Python doesn't have rake.
But I'm certainly ready and interested in moving toward a more functional language -- I've always been interested in the Lisps, and have always tended to write code in the functional style, where possible (even though my first language was Java...)
i think you must mean "false", then.
Then again he's programming in a hot bed of programmers in that well known programming mecca of Hamilton, New Zealand. Oh, wait...
Point the first: Python 2.x to Python 3.x if you already have to make a transition, there is more impetus to make a transition to something that suits how you actually work.
Point the second: itertools is partly a catalyst, partly an indicator. Once you get fluent with it, it illuminates pain points.
Point the third: There is a new batch of functional languages that support the style that is a pain point, as well as fixing other issues that hurt in python.
Lastly, not all python programmers will want to make the shift. But the ones fluent with itertools are more likely to be the subset that will.
I did in fact switch during the 2.x->3.x transition, though I haven't given up on Python entirely - I still know the language, I'm fine with working in it, It's just not my first choice anymore. If there were one factor (and there isn't, my switch to Lua was gradual* ), it would be GvR's insistence that Python will never get tail-call optimization, because it's "unpythonic". (http://neopythonic.blogspot.com/2009/04/tail-recursion-elimi...) That has major implications for the expressiveness of the language.
* I think what happened was that I had been reading Lua's source to see how a small, clean implementation of a bytecode compiler worked, and along the way discovered that it suited my preferred development style better. Lua feels like a minimalistic hybrid of Python and Scheme, with the "good parts" of Javascript (prototypes, object literal notation) harmoniously integrated, but designed with embedded and multi-language development in mind. Also, the whole language can be installed with a DLL smaller than SQLite (!), which makes deployment rather easy.
When I say in this position, I mean that I would like to switch but won't in the next future (too costly).
In the real world, suffering a few weeks of diminished output due to learning new syntax, idioms and best practices is not always (dare I say, rarely) feasible so making an existing language more powerful through the addition of functional constructs can only extend their productive life.
I disagree. Functional programming is about as far away from the machine as you get. When I write functional code, I feel like I am describing the problem I want to solve in great detail, just as I would if I were writing about it. (And despite being "far away from the machine", the code still runs quickly. There is something to be said for describing a solution to your problem instead of telling the CPU which bits of main memory to flip.)
As you go down the spectrum from FP to OOP, your code becomes more code-like. Create object. Call method. Save return value. Pass value to another object. Get result. This is still pretty abstract, though, and a fine way to code.
Then you get to procedural programming (C), and then your code truly is code. Allocate memory. Move bits from register to memory. Set interrupt. It's hard to even see an algorithm in there, there's just so much code.
In functional programming, things are often so abstract that you define functions in terms of other functions without even mentioning the data you are processing. Let's face it; that's not "code".
(from the Scheme quotes file at http://community.schemewiki.org/?scheme-fortune-cookies)
Having written non-trivial programs in Haskell, ML, and Python, I agree with this, but I would add: Functional programming is more like mathematics.
English expresses some ideas more clearly, while mathematics is better for others. And notations that are more "mathematical" often have other nice properties like composability and equational reasoning.*
*The best example of what I mean by equational reasoning is the Sudoku functional pearl: http://www.cs.tufts.edu/~nr/comp150fp/archive/richard-bird/s...
sudoku = map (map head) . search . prune . choice
Note how the "code" never mentions the data to which it is applied, namely the Board object. This is why I can't agree with the GP's argument that FP is closer to "code" than anything else -- I think it's as far from "code" as you can get. There are no "instructions" here, just an equation representing something complex ("the solution to sudoku"), in terms of slightly simpler parts. The simpler parts are, earlier in the paper, the complex parts; and are of course described there by simpler parts.And, this is not just something that's useful for esoteric mathematics papers; my "enterprise" code in Haskell looks very similar.
However, from a readability standpoint, english is better than mathematics, and readability counts for quite a bit if you aren't planning on throwing away your code.
That depends on what you are reading. Try reading differential calculus in English, without using notation.
Not to take anything away from your point (and I think it is a good one), but there are all kinds of code. Functional Programs can be astonishingly elegant.
I have used much of itertools. When you need to do some complex iteration through lists, itertools is great. When you need to pull an address out of a web page, itertools does absolutely nothing to make that easier, nor does any other functional programming technique.
So here is the difference. Procedural style is better for dealing with a problem. Functional style is great for applying a solution to lots of pieces of data in a structure that can be iterated over or recursed into. The hard part is dealing with each problem, not the part where you apply it.
I'd say an approach like "iterating through all nodes, filtering for the one(s) you want" is quite functional. Add lazy iteration to that, so you're only parsing/consuming as much of the document as necessary, and on-demand, and you've got a really nice, _functional_ solution.
[edit: toned it down a little.]
What is the functional way to get the 3rd - 8th li in the 2nd ul where the ul has id="foo" and is in a div (either directly or as a decedent) where the div is directly before the 'comment' <-- content area --> ?
You use XPath, or CSS after finding the comment with a regex. People get incredibly retarded about functional languages, but in reality the only software that I have used that is written in one is XMonad. So in your mind everyone who actually gets things done is using the 'wrong language'? Or an inferior one?
Name one big success story of functional programming. There isn't one. Nobody uses it who actually cares more about getting things done than reading self congratulatory blogs between CS classes.
[in no way toned down]
Map Reduce. It is implemented in C++ (and other languages) but MapReduce itself is very functional. The users of mapreduce do "functional programming". Maybe you wanted success stories of functional programming languages? (which is a different question).
Another : SpreadSheets
Yet Another: SQL . SQL is (at the core) relational rather than functional, but functions are relations. This keeps getting rediscovered every now and then (witness all the noise around Rails3 and Arel)
"Nobody uses it who actually cares more about getting things done"
It must be nice to be so certain and knowledgeable about such things. You are a lucky man ;-)
I want to give a special mention to FFWT, the gold standard for Fast Fourier Transform libraries. If you use any audio or video software, you probably use this library without knowing it. An OCaml program generates the C code that compiles to the FFTW library.
just curious. Our team met perf problem in the past and each time, a rewritten code or even a rewritten module was all it took to get back on track.
Or if you mean Jython with the speed-critical bits written in Java...well, there's always C for that.
Weave Cython SIP
Python is really easy to tie into other languages for the slow parts.
Python is seeing some heavy use by the scientific community due to tools like NumPy, matplotlib, libsvm and what not. Good luck finding that range of independent libraries for a new FP language. I am not dropping Python in the near future, but I am watching.
F# can use anything available for the CLR/.NET.
Libraries are not really an issue.
Despite knowing Pythons functional tools, it wasn't Python that introduced me to that style. I find Pythons mix comfortable and happily switch between programming in Python 3 and Python 2. Maybe the OP hopes to start a trend?
- Paddy.
My guess is that after using functional languages in real projects, most of them will go back to Python.
Show us the code.
Haskell is really quite adequate for real work these days. It has the libraries you'd expect, and it's a nice language with a nice runtime.
It's also worth noting that blog-popular languages are blog-popular for a reason. The people that blog about programming are the ones that need tools that give them a bit more productivity between the occasional nap or meal; the people that use the more esoteric languages want to solve so many programming problems that a sharper tool is essential to their survival. (There is only finite time, after all, and programming languages are easier to build than time machines.)
In contrast, the "popular" languages are mostly used by people whose goal is to warm their chair for 8 hours and receive a paycheck. There are a lot more people that want money than that want creative time with a cold, unloving machine, so it follows that the languages where you can get paid and not care are going to be most popular.
But if you are the second type of person, there is little advantage in worrying about what is "popular" in "the real world". You don't want to be in the real world.
Maybe people now blog about python because the community has always tried to be friendly. It is usually nice to blog about Python, and have fellow enthusiasts give measured, polite feedback.
"... so it follows that the languages where you can get paid and not care are going to be most popular."
But it does not follow that there are less caring, articulate, and productive souls in a more popular languages camp.
- Paddy.
True: There is an observable trend that more and more people are using Python, and there is a smaller set of people that is not a subset of Python in any way that is toying with functional programming, usually for academic or masturbatory purposes.