Both have a long history of "standard" modules for common cases and well-maintained (if not "standard") modules for alternative approaches to the common cases, or for the uncommon cases.
More importantly, both languages have a well-established culture of boringness. This is a quality I actively look for, because it tells me someone wrote code to solve a problem, not because it was the hip thing to do.
As Erlang and Haskell show, it's totally possible to combine an event-driven I/O subsystem with lightweight user-space preemptive multithreading that supports a huge number of threads, takes advantage of multiple cores, and doesn't need to worry about blocking-vs-nonblocking magic. I would love to see that in a more mainstream language.
There are a lot of libraries to check out on each language before you can make that claim!
Here for example are just some of the Javascript libraries on CPAN:
* JavaScript (SpiderMonkey) - https://metacpan.org/module/JavaScript
* JavaScript::SpiderMonkey - https://metacpan.org/module/JavaScript::SpiderMonkey
* JavaScript::V8 - https://metacpan.org/module/JavaScript::V8
* JE (Pure Perl JS engine)- https://metacpan.org/module/JE
* JSPL (SpiderMonkey) - https://metacpan.org/module/JSPL
With Python 2 strings you have to be proactive about it and - always use u"" unless you know what you're doing - segregate non-unicode data to boundaries by decode()ing early and encode()ing late, or you're guaranteed to shoot yourself in the foot sooner or later
but if you do it it's quite smooth sailing.
Also,
#/usr/bin/env python
# -*- encoding: utf-8 -*-
helps a lot.All that just brings you closer to Python 3 anyway and really helps when using 2to3.
incompatible character encodings: UTF-8 and ASCII-8BIT
gets pretty tiresome! Using 1.9.2 at least you have .force_encoding ... feels pretty wrong but sometimes it's just needed to get the job done..http://98.245.80.27/tcpc/OSCON2011/index.html
Specifically the third talk:
http://98.245.80.27/tcpc/OSCON2011/gbu.html http://98.245.80.27/tcpc/OSCON2011/gbu.pdf
Excerpts:
Its String functions like upcase or capitalize won’t even look at
anything but ASCII.
It’s completely missing a whole lot of critical Unicode
functionality:
casemapping & -folding
grapheme support
normalization
collation
text segmentation, &c &c &c.
Every Ruby string carries around its encoding, instead of sanely
unifying into Unicode internally like nearly everything else does.
Also: > baked right in to the language
is not synonymous with "intelligently implemented"Note that I wasn't implying that "half-ass," "partial," and "just plain wrong" necessarily all apply to Python and/or Ruby's implementations. Some may apply to some areas while others may not, and really this extends outside of just Python and Ruby, but I'm trying to stay in context here.
Net::HTTP.get_print 'www.gun.io', '/'
That's it! In only two lines of ruby, you can grab a whole webpage and print it to the screen. Awesome! - and it's in the standard lib ;)
I agree, when I left PHPland I chose Ruby over Python because the (web) community was larger, there were just more books, blogs, screencasts, etc for Ruby/Rails.
There seems to be more ideas generated out of the Ruby community, I'd add Sinatra and HAML to the list above, like Rails they've both been ported to other languages.
OF course Heroku was Ruby first and it's so good that my PHP/Java/Python friends jumped for joy when their language became supported.
echo file_get_contents('http://www.gun.io')
you lose even more of the line noise of the other languages.For a language that claims to be "batteries included" it amazes me how many Python tutorials begin with "go get and install this or that package..." How much of the Python standard library is no longer the "Pythonic" way of doing standard things? Why aren't APIs with more refined design, like Requests, pushed back into the standard library, and made the real one way to do it?
Well, OK, you'd have the problem of redundant libraries starting to stack up--it's already looking tiresome. For instance, Requests would have to be urllib3, since there is already a urllib2 and urllib. This article wants me to install simplejson, but there's already a Python json module: oh I see, it was merged in from simplejson, and now they are developed in parallel, so using simplejson may still be better, wtf? Why is there an htmllib in the standard library if I'm always going to use lxml instead? Let's not even discuss eyesores like the heritage of the subprocess and threading libraries...
Because it takes time. It takes time to add things to the stdlib, especially if the are replacing "an old reliable." In the case of Requests, it is just a wrapper on the stdlib. There is nothing in Requests you can't do in the stdlib, ditto pretty much everything.
As far as lxml goes, there are a ton of XML parsing/query libraries out there. In lxml's case it is built on libxml2. I believe there is another library that is also build on libxml2, however lxml has better syntax for the most part. Should it be in the standard library? Probably not, it depends on a pretty heavy weight C library and most people don't really need it. When you do, you use it.
I have no idea what is going on with the simplejson business. I just use the json lib.
I don't see anything wrong with subprocess or the threading libraries. They do what they need to do. I use subprocess quite often, it works fine. It is way better than the actual legacy version (in the os library).
> echo file_get_contents('http://www.gun.io)
I thought it had to be "too good..." - links are broken. And since src links are broken, too, images do not display.
(development)ross@debian:~/hntest$ python download.py > download.py.html
(development)ross@debian:~/hntest$ php download.php > download.php.html
(development)ross@debian:~/hntest$ diff download.py.html download.php.html
242c242
< <div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='b0c35970dfd374f2b138ed89a4f83a76' /></div>
---
> <div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='018fe81570d710d88ca3f46d1db4c8b7' /></div>
303d302
< import urllib
the_page = urllib.urlopen("http://www.gun.io/")
print ''.join( the_page.readlines() )
I could jam it all into one line, but in Python we prefer readable code ;) ;)The Python community also tends to be quieter than those raving Ruby fanbois - if you'd said appeared to be larger, then I would have agreed with you...
print the_page.read()[1]: http://docs.python-requests.org/en/latest/ [2]: http://news.ycombinator.com/item?id=3094695
When a language has multiple viable implementations, it means the language has a good specification. It also means that it doesn't depend too much on platform-specific characteristics. It means it is more portable. Python is both blessed and cursed with a couple of problems ... its behavior is sometimes related to the CPython implementation (e.g. reference counting, __del__), and also some libraries are too big and important to live without them.
One such library is NumPy. Currently you cannot talk about an alternative Python implementation if you don't have NumPy running on it, and that's a fact.
I'm a Python developer in my day job and I never used Pypy for anything. I only played with it and became frustrated that libraries I relied upon don't work on it.
Btw, if you're a fan of Pypy, checkout http://rubini.us/
I disagree. I didn't need to read it, but I did, and I still feel that way.
The statement says language, but the actual points made are about the libraries and the community (i. e. the ecosystem).
I think the ruby ecosystem is actually better, for a few reasons:
* Deep integration with JavaScript (ExecJS and TheRubyRacer are way ahead of what is available in Python, Perl, and PHP)
* Many different excellent choices for talking to HTTP APIs, including the highly innovative Faraday
* A top-notch JVM implementation (JRuby has had more traction than Jython over the last five years)
* Lots of good auth libraries: OAuth (for authenticating with a plethora of outside services), Devise (pre-built auth with confirmation emails, password resets), and OAuth2 provider (server) implementations
* Ruby has evented programming too. Goliath is pretty good.
Python is great but I take issue with saying that it's the best web dev language out there.