I definitely wish I was writing something other than python. I did choose it, but it's not the language I want to be writing in. It's just the language that happens to have numpy, django, etc.
While writing it, I often wish it were statically typed with pattern matching. The write/test/type error or undefined variable cycle is very frustrating to me. The lack of pattern matching makes my code verbose and also makes it harder to spot edge cases I missed.
I also wish functional programming in it were as easy as in Javascript. I often find myself writing a bunch of front end code, finding it elegant, then thinking "damn, back to python to update the api". (This includes multiline lambdas.)
It's still my go-to language for most purposes, but I constantly feel that it could be a lot better. I'm looking forward to the day when javascript completely subsumes the niche python occupies.
Do you have pylint integrated with your IDE? It greatly, greatly speeds up the cycle around fixing basic problems like undefined variables or wrong method arguments. I don't know how I ever coded in python without it.
Is there another specific language that you would prefer to code in, or is it that python is simply your only, albeit inferior, option (i.e. the worst programming language except all the others that have been tried)?
I agree with you on static typing and functional style being strongly preferable, and that Python makes that style of programming irritatingly difficult, but it's not like JavaScript has static typing or pattern matching either, so it seems odd that it would be your preferred replacement. Why not wish for a replacement that actually has all of the features you want?
Haskell is my preferred replacement, but I don't really expect Haskell to replace Python. It might replace C++ or Java, however, or form it's own new niche.
People seem to want a simple, dynamically typed scripting language. Javascript can fill that niche while being a big improvement on Python. (Particularly if we accept some breakage of backwards compatibility, add a module system, and clean up the warts.)
I'm going to try and say this carefully, because I don't want to start a language war. Quite the opposite: I desperately want to change my views on programming languages.
I've only recently started in Javascript, so I'm probably missing something, but I've been finding it a large step backward from Haskell when compared to Python. Specifically, list comprehensions and generators give Python a more functional feel. Meanwhile, the object system in Javascript has had me generating far more state than I ever would have in my Python code, while also requiring more manual type checking than I ever needed in Python.
I'm new to the language, so I'm sure that I'm missing something. I've read _Javascript: The Good Parts_ and it's helped me grow less frustrated, but I'd love to find out that this language is better than Python.
So, how do you write functional code in Javascript?
I wrote poorly, I wasn't meaning to imply js is haskell-like. It's scheme like.
I write js using underscore and backbone, so while I have state, it's pretty well encapsulated.
So I've got a few stateful backbone models. The inside of their methods tends to be primarily functional, followed by a stateful update:
var intermediateResult1 = _.map( input, function (ss) {...});
var intermediateResult2 = _.map(input, function(ss) {...});
var intermediateResult3 = _.intersect(intermediateResult1, intermediateResult2);
....
this.setState({ "my_attribute" : result })
My views are almost entirely functional - take a model as input, create some dom elements as output, and one side effect when updating the view.
They may be just syntax, but multiline lambdas certainly help. And some of this is just library support. But all put together, it makes my js code far more functional than my python code.
Thanks for the response. As I told Kibwen, the underscore library looks pretty neat. Also, my problems may have just been some brain damage on my part. I'd gathered that object hierarchies were the more idiomatic way to code javascript.
I've been trying to write Javascript and then make it functional. I think I need to start writing functionally and just fit that into the Javascript. From what you've written, that looks pretty doable.
I can't answer your question, but if you're looking to emulate a functional style in Javascript I'd be remiss if I didn't point you toward Underscore.js:
How likely is this hypothetical cleanup of JavaScript to happen, though? It seems about as likely to me as the likelihood of Haskell replacing C++ or Java; i.e. not very likely at all (even though I share your opinion that it would be a wonderful thing if Haskell were more popular).
The main advantage that JavaScript seems to have over Python is multi-statement lambdas. In other respects it seems no more Haskell-esque than Python is. Python at least lets you do a very limited form of pattern matching on tuples. And JavaScript brings along so much hastily-designed ugliness that it seems like it would take ages to break free of its historical warts.
I'd personally be happy if some flavor of Scheme became the dynamic language du jour, though I realize I'm living in a fantasy world there.
Javascript isn't Haskell-esque, it's scheme-esque. I didn't mean to imply it was a substitute for Haskell, merely that it's a better version of Python.
Javascript also has proper closures, and it's support for event driven programming (admittedly, not part of the language) is also quite nice.
[edit, since I can't reply. By proper closures, I mean this shouldn't happen:
> x = 0
> def foo():
> x = x + 1
> print x
> foo()
UnboundLocalError: local variable 'x' referenced before assignment
]
When you say "proper closures", do you mean anonymous functions? I can't think of any other reason why Python's closures wouldn't be considered proper.
EDIT: Interesting, I've never run into that behavior before. Looks like you'd have to explicitly mark that variable as global if you want to mutate it:
x = 0
def foo():
global x
x = x + 1
print x
foo()
However, after reading the rationale[1], I tend to agree with this requirement:
"This isn't a bug; it's by design. Because there's an assignment to 'a' in the function 'y', 'a' is considered local to that function. (It doesn't matter where the assignment happens within the function; the presence of an assignment anywhere is enough to make 'a' local for the entirety of 'y'.)"
This is an annoying behaviour, but it is consistent with Python's design . It is not exactly caused by broken closure, rather by the object model of python, and how named are bounds to objects. While this does not make it less annoying, it explains why the difference between using x vs x.val is logical from python POV.
While writing it, I often wish it were statically typed with pattern matching. The write/test/type error or undefined variable cycle is very frustrating to me. The lack of pattern matching makes my code verbose and also makes it harder to spot edge cases I missed.
I also wish functional programming in it were as easy as in Javascript. I often find myself writing a bunch of front end code, finding it elegant, then thinking "damn, back to python to update the api". (This includes multiline lambdas.)
It's still my go-to language for most purposes, but I constantly feel that it could be a lot better. I'm looking forward to the day when javascript completely subsumes the niche python occupies.