First of all, thank you all for your comments. I have to clarify the purpose of this library. I'm originally a JavaScript developer and I didn't write a single line of python code before this project.
I needed a project to learn python and I choose something I'm already familiar with. Underscore.js has almost everything you want to learn on a new language and it thought me a lot.
When I completed the project I figured I can post it online and other clueless javascript developers like myself can learn python from a familiar place.
I'm fully aware that python already has most of the tools underscore has and this code is not pythonic at all. It was built that way intentionally. I wanted it to be the same as underscore.js.
Now I need your advice to write a better python code and maybe create a useful library after all.
Thank you all.
PS: I wrote this comment from mobile phone so please excuse any errors.
My personal feeling is, that you would learn more about Python by trying to write something using the standard library and embracing Python's style, instead of porting a JavaScript library.
[w for w in ["foo", "hello", "bar", "world"] if len(w) > 3] == _.filter(["foo", "hello", "bar", "world"], lambda x, a: len(x) > 3)
sorted([i 2 for i in [10, 48, 56, 30, 20] if i > 20]) == _([10, 48, 56, 30, 20]).chain().filter(lambda x, a: x > 20).map(lambda x, a: x * 2).sortBy().value()
I hesitate to add to the negative response to what is surely a well-meaning free project for the world. But `_` is really a poor choice for a variable name in Python. It is already used as:
Please keep in mind that this is just a port of a javascript library, please don't get started with the "but it's not pythonic" stuff. This library has no intentions to be pythonic, infact it tries to bring same underscore experience from javascript to python.
You have to give the author credit for his candor at least.
That said, I like that the author of this is trying new things out. We can't let Python become petrified by rigid definitions of "pythonic".
But I think this port misses the point of Underscore.js, which is to make the same functional features of the language available to all browser implementations, because not all browsers have forEach, or filter, or reduce, etc. In Python, or other languages? The features are already there.
Haha :) I don't know what I was thinking by putting that comment.
Underscore.py is not trying to fill any gap in Python. It's just a port. Maybe a useful collection of tools. But I agree it's mostly pointless when there are itertools and functools.
There is absolutely no reason to use this. As far as I can tell, it's a direct port of underscore.js, and implements nothing but functionality that's already in python.
My opinion: Anytime you share code by posting it publicly, you should always be prepared for negative feedback. In some cases that might be the whole point of posting it: you want to learn from your mistakes.
Good job! I know that some of these functions maybe have already occurred to Python developers (map et al), but this probably lead you to a broader understanding of underscore.js itself.
While I can understand this might have been fun from a hacking/building experience, I don't understand why do it. Everything except the micro templating already exists in python.
This doesn't bring anything good to Python. Python can do those things nicely. I can't see any point of this library. Also, underscore already has its meaning in some places, such as for i18n. For example, _('Text to be localized'). Another use of underscore is to store the previous output in console. Although you can rename it, still, it's pointless.
This template language is only superficially the same, but the code between the <% and %> would need to be python in this version, not JS, so you can't actually share anything. You would need to combine something like this with a JS-to-Python transpiler for that to work.
How are collection functions not useful in python? I use map and sort (or the comprehension equivalent) daily. The rest I use at least once a week, with the possible exception of groupBy - as my workload doesn't really need it very often.
[+] [-] serkanyersen|13 years ago|reply
First of all, thank you all for your comments. I have to clarify the purpose of this library. I'm originally a JavaScript developer and I didn't write a single line of python code before this project.
I needed a project to learn python and I choose something I'm already familiar with. Underscore.js has almost everything you want to learn on a new language and it thought me a lot.
When I completed the project I figured I can post it online and other clueless javascript developers like myself can learn python from a familiar place.
I'm fully aware that python already has most of the tools underscore has and this code is not pythonic at all. It was built that way intentionally. I wanted it to be the same as underscore.js.
Now I need your advice to write a better python code and maybe create a useful library after all.
Thank you all.
PS: I wrote this comment from mobile phone so please excuse any errors.
[+] [-] anonymouz|13 years ago|reply
[+] [-] tebeka|13 years ago|reply
[+] [-] jmagnusson|13 years ago|reply
map(str.upper, ['foo', 'bar']) == _(["foo", "bar"]).invoke("upper")
[w for w in ["foo", "hello", "bar", "world"] if len(w) > 3] == _.filter(["foo", "hello", "bar", "world"], lambda x, a: len(x) > 3)
sorted([i 2 for i in [10, 48, 56, 30, 20] if i > 20]) == _([10, 48, 56, 30, 20]).chain().filter(lambda x, a: x > 20).map(lambda x, a: x * 2).sortBy().value()
[+] [-] rmc|13 years ago|reply
[+] [-] masklinn|13 years ago|reply
[+] [-] michaelhoffman|13 years ago|reply
* the value of the last expression in the REPL
* a conventional abbreviation for `gettext.gettext` (http://docs.python.org/library/gettext.html)
* a conventional throwaway variable (for `str.partition` and other functions that return a larger tuple than you want)
And for most of these features, invoking them through a object/class method rather than a standalone function is unwieldy (and unpythonic)
[+] [-] j_baker|13 years ago|reply
Please keep in mind that this is just a port of a javascript library, please don't get started with the "but it's not pythonic" stuff. This library has no intentions to be pythonic, infact it tries to bring same underscore experience from javascript to python.
You have to give the author credit for his candor at least.
That said, I like that the author of this is trying new things out. We can't let Python become petrified by rigid definitions of "pythonic".
[+] [-] sitkack|13 years ago|reply
[+] [-] djacobs|13 years ago|reply
Is this a parody?
[+] [-] serkanyersen|13 years ago|reply
[+] [-] masklinn|13 years ago|reply
At least it's not php.js
[+] [-] gbin|13 years ago|reply
[+] [-] stephen_mcd|13 years ago|reply
Also the underscore variable name conflicts with the common convention of using an underscore as the i18n translation function.
Those issues aside, the templating looks handy, and I'm sure the whole thing was fun to write.
[+] [-] FuzzyDunlop|13 years ago|reply
But I think this port misses the point of Underscore.js, which is to make the same functional features of the language available to all browser implementations, because not all browsers have forEach, or filter, or reduce, etc. In Python, or other languages? The features are already there.
[+] [-] serkanyersen|13 years ago|reply
Underscore.py is not trying to fill any gap in Python. It's just a port. Maybe a useful collection of tools. But I agree it's mostly pointless when there are itertools and functools.
[+] [-] draegtun|13 years ago|reply
Perl - http://vti.github.com/underscore-perl/
Lua - http://mirven.github.com/underscore.lua/
PHP - http://brianhaveri.github.com/Underscore.php/
Actionscript 3 - https://github.com/amacdougall/underscore.as
[+] [-] borntyping|13 years ago|reply
[+] [-] serkanyersen|13 years ago|reply
[+] [-] yoduh|13 years ago|reply
[+] [-] why-el|13 years ago|reply
[+] [-] serkanyersen|13 years ago|reply
[+] [-] masklinn|13 years ago|reply
Some? Pretty much all of them are already either builtins or in the stdlib…
[+] [-] mark_story|13 years ago|reply
[+] [-] victorlin|13 years ago|reply
[+] [-] sontek|13 years ago|reply
[+] [-] apendleton|13 years ago|reply
[+] [-] cpylua|13 years ago|reply
[+] [-] sophacles|13 years ago|reply