Neat project. One critique: I don't like having only five lines of the snippet visible at any given time, it makes it harder to easily understand what's going on in some of your longer snippets.
I suspect that the five line limitation was done so that the "Give me another one!" button was always in relatively the same place and easily clickable (I appreciate that), but perhaps there could be a small, duplicate text link up above the snippet for this purpose too, thereby also letting you make the snippets longer.
I like the idea. Yes, there's the need for both. I'm thinking about just making the text size variable according to the number of lines in the snippet - I think that makes more sense.
That's a thought, but even moderately sized snippets might get hard to read. I think this concern is especially valid because the rest of the text on the site is large and easily readable from a distance, so making the most important text–the snippet–smaller would be out of place.
Just change the layout. The 'play' button and execution results are equally logically placed under the code. That should give you enough space for snippets of any size.
Can it be true that the Python coverage on HN is overproportional compared to its real world usage?
If I look around the world is full of Ruby and Rails. Sites, libs, meetups, developers, everything is on Ruby or Ruby on Rails. Python and Django devs are so damn rare in real world -- I just know two of 100.
Not that I don't like Python but I am really wondering why Python gets such a strong coverage on HN. Every second day there's some Python thing on HN. BTW with Clojure it's the same but Clojure is something new, so I understand the visibility there.
Please don't downvote -- it's nothing against Python, I just want to see if the Python base increased or something happend I've missed. Thanks
How can it be?
EDIT: Thanks to all for the replies. What's interesting about this thread: I got tons of downvotes (besides upvotes) for the first comment. So, I assume this Python vs Ruby discussion seems to be a very emotional topic. Thanks to the replies I have now a better understanding that Python is older and dominant in a many non-web environments. My impression is still that especially in web environments we have much more pace and development in Rails than Django (just compare what DHH put in 3.1, Coffee, Sass, etc. -- no flame war just a questions dear downvoters, don't freak out again)--Rails feels just more vibrant regarding web dev. But Rails is not Ruby ;-) It's just that I see all the Python stuff on HN -- which is slightly focussed on online/web/Internet -- and I really considered learning Python for web dev until I checked http://www.google.de/trends?q=python+django%2C+ruby+rails...
As far as I can tell, Python has a much broader base than Ruby, at least in the english-speaking world, but is generally quieter about it. As a few examples:
Thanks to SciPy, NumPy, Sage, and so on, Python is extremely popular in scientific computing and academia in general, drawing hundreds each year to Enthought's Scientific Python conference.
Apple's iCal Server is written in Python with the aid of the Twisted async library, the same library used by LucasFilm for communications in its render farm, or Justin.tv's caching engine.
Google has found great success with Python: YouTube, for instance, is written in Python.
Thousands of undergraduates have their introduction to computer science each year taught in Python, even at MIT.
And let's not forget the sizable Django, Pyramid, and Plone web development communities, all of which seem to have surprisingly little overlap.
The thing is, Python's been around for a long time -- longer than Java -- and it's been useful for a similarly long time, especially in the same domains that Perl traditionally excelled at. Thus, its growth was bottom-up: Many sysadmins were eventually expected to simply know Python just as they were expected to know Shell and Perl, and thus being functionally proficient in Python wasn't really a defining characteristic.
In this way, Python's expansion has been more of a slow burn as it creeps into more and more corners of software development. Rails, by contrast, came coupled with a wonderful promoter in DHH, and brought scores of front-end talent and PHP refugees into the fold from day one. That audience seems to simply be more innately talented at vocalizing the cool things they're doing, and making sure they mention that they did it all "...with Ruby!"
So while I'd wager that the Python community is larger than the Ruby community, it certainly seems less concentrated, and less vocal about it.
To wit, did you know that Dropbox is primarily written in Python? And that the same goes for Eve Online?
As someone who uses Python (as well as C# and various others where appropriate) often outside work, this has been exactly my experience.
I only recently discovered a Python meetup in my area and have been extremely impressed with everybody there.
Python is an amazing language with a powerful module system and vast community to rapidly prototype and research almost anything. That said, I care less about its "beauty" and more about its minimalist, lack-of-magic Pythonic philosophy backing the language that lets me get things done quickly and collaborate with others with little overhead.
And this were all the factors that got me into Python when I was pondering whether to go down the Rails or Python road, when I wanted to crossover.
And I was carrying quite a torch for Ruby before. But when you realize how much broader Python is - Ruby doesn't look that good any more, no matter the hype.
But when you realize how much broader Python is - Ruby doesn't look that good any more, no matter the hype.
It's not all about "hype," of course. There are many distinctions and comparisons that can be made over which language is best for the job beyond the number of people using it or how much hype it has.
Ruby looks great at things Ruby is much better at. Python looks great at things that it's better at. For the rest, it's a wash.
But it's kinda like Porsche 911 Turbo vs Aston Martin DB9. Where AM is arguably a prettier sight, but Porsche can do all the driving of DB9 while offering a far superior dealer network.
I would say that the opposite is true; Ruby on Rails is hyped in the startup community, but Python has a lot more real-world traction. Not every programming task is to build a web application, after all. scipy is a particularly popular application of Python.
I will agree that the Python culture is very different than the Perl or Ruby cultures. Python is a bunch of scientists and bankers writing private software for themselves and not talking much about it. Ruby is a bunch of designers making open-source projects with pretty logos and talking about them constantly. And Perl is a bunch of people that did all this 10 years ago and wonder why everyone is so excited about fast math libraries or web app frameworks.
Python and Django developer here. So you have met one more!
Interestingly, though, I find Ruby more beautiful. Possibly one of the reasons for that is it inherits a lot from the UNIX culture awk, perl roots; and also much more from Lisp and Smalltalk.
Also, my observation is that Ruby seems again very popular for OS X / Linux devs, but for Python, developers using Windows is significant. (I am not claiming that Ruby is more popular than Python for Unix users, though, just that the percentage of Windows Python users is more than Windows Ruby users.)
Rails community is definitely greater for web development as you said. One of the major differences is 37Signals, and they do a great job in pushing the project forward. The Rails project also includes several important assets which Django leaves to the developer. For example, there is no builtin migrations for Django (though most people use South), no builtin API support (tastypie/piston is commonly used).
The upside of Django is probably that things are more clear since there is less convention. This is also in accord with the languages, Python is more explicit, Ruby more magical.
One other difference that comes to my mind is that some prominent developers, like the Pragmatic Programmers Dave Thomas, or Thoughtworks' Martin Fowler prefer Ruby, while there doesn't seem to be such prominent vocal authorities speaking for Python.
Thanks for your comment. I strive to be a great maker, so I love programming languages!
You are right in some sense, though. I think about the parent's and your questions from time to time. The thing is, I actually do love Python too. It's just that, as an outsider, I find the the Ruby community much more vibrant, and I sometimes envy the stuff over there.
I have a deep affection to most programming languages in general though, I do not think that I should choose one of them over the others. For example, contrary to general opinion, I find some parts of Perl beautiful too, and even this year have read a few Perl books.
As to why I happened to choose Python over Ruby, there are historical reasons. The first reason is that, as a previous academic, I first learned Python for SciPy, considering it as a replacement as MATLAB. Being that Python was backed by Google was a plus at the time.
It was when the App Engine was announced with Python support that I started making a few websites with Python, only to discover shortly that Django was the most popular way to go for making websites in Python (I would also highly recommend Flask as an alternative too, now).
Now, at this point I was proficient enough in Django, and started looking at Rails. I was immediately struck by some of its aspects, but still web programming was not my full-time job; and I feared that since Rails was moving so fast at the time, and that it relied on convention more than the explicitness of Django, I thought that after a week of not working on my project, I would forget some of that implicit stuff.
This, I believe is also the major reason why most people don't like Perl -- a chicken and egg problem. My impression is that those who do not like Perl are not people who code full-time on Perl (surprise!) and so view Perl programs incomprehensible after they maintain the code after a break. It is similar to natural language in that if you do not use it, you tend to forget some of the stuff that makes things very easy; while I would describe Python as more like solving a maths/geometry problem - easier to recall, easier to maintain.
So, I love Python, but it's just that I also love most of these languages, and some parts of them more; Smalltalk, amazing in its world concept, Lisp (and now Clojure) beautiful with their flexibility. But where do I find a Clojure job, if I don't create that job opening myself with a personal project? I believe it is a general feeling on HN, most people have an affection for Lisp, but for some reason, do not (or can not) use it in their daily jobs.
Regarding your comment about Peter Norvig though, actually, he is a prominent guy speaking for Lisp; it is just that Python is more comprehensible by students (as it is closer to pseudo-code), that he has chosen to use it.
Python has a very large community, but it tends to be a lot less vocal (for better or worse) than the Ruby or Rails communities. Python is a widely used language (quite possibly much more popular than Ruby since Python is taught to undergraduates at MIT, Berkeley, and other "top tier" schools).
It's pretty much certain, given the widespread acceptance python has in scientific computing, an area where Ruby penetration is minimal-to-nonexistant.
It's kind of the same as node.js hipsters. A whole bunch of people worship concepts that existed long ago, thinking that node.js is the holy grail for having them, and that is why node.js is the best language in the world.
I am wondering why you are offending node.js and Ruby users. We all try to get a clue of Pythons real-world usage in this thread and you (the original poster) just brand them as hipsters (btw you could also be labeled as one of those who worship "an aging language which lost track in the web world, again and again on HN", just an example, so keep calm). Imagine some Ruby or node.js folks would offend Python, you and your learnpython site.
Through this thread I got again closer to Python and in particular Flask, so use such discussions as opportunity to educate us. Such posts that offend rather scare us that python is used by some intolerant old-school fanboys.
I don't think so. I know mostly Ruby developers, but that's because I'm in the Ruby world. As far as I can tell, the Python community is somewhat larger—and there are certain communities where it will likely stay that way (e.g., scientific computing is a bit of a travesty in Ruby, but substantially better in Python).
Ruby makes me happier than Python does, but Python is widely used.
I'm always skeptical where people post stats from jobs websites.
I think allot of the advertised jobs are either duplicates or recruiters who just advertise there in order to harvest CVs, so it may be more a barometer of what is perceived to be popular rather than what actually is.
I did get same for my region. But the question is: do these figures show the real-world usage or rather a resource lag of aging languages--e.g. you have more PHP jobs than Ruby because PHP devs moved to other languages and there are still tons of legacy systems to maintain. There was also an interesting article (I forgot the author, Spolsky?), who said that there's a reason why resources for aging languages are more expensive than others => The developers have more opportunity costs when developing for aging languages.
Don't get me wrong: Java, C#, C++ are maybe not aging but their user base isn't growing anymore or not with the same strong growth rate like newer languages
All languages are ageing languages so i think a better term to use would be mature languages. That conjures up a completely different emotion :)
> Don't get me wrong: Java, C#, C++ are maybe not aging but their user base isn't growing anymore or not with the same strong growth rate like newer languages
Is this anecdotal? Because its very hard to know what is going on with absolute certainty and trends vary from place to place and over time.
Just thought I'd take a snapshot of Stackoverflow question metrics:
It's important to not take these figs has gospel outside of Stackoverflow.com. However considering Stackoverflow only started in August 2008 then these figures do suggest that mature languages have been growing at a very healthy rate.
I know Python (and Lisp and Java), and have been looking for a summer internship. There was recently a startup fair in my hometown...and of the five or so internships available, 100% of them require Ruby (and Rails), 0% really care about Python (or any other language I know).
I know Python has a huge userbase and has tons of software written in it...but it doesn't seem to be too trendy right now.
That's the point: "but it doesn't seem to be too trendy right now" and still, it's pops up every 2nd day here on HN. I am fine with Clojure, Haskell and the new functional trend but just don't get it with Python.
I know many more Python developers than Ruby developers (although Rails is the best MVC framework I know of).
My personal opinion, though, is that Python is and will continue to grow in popularity because of its emphasis on what I call "cognitive compatibility" - very strong emphasis on readability and consistency. The Ruby community doesn't have the same commitment.
At my workplace (a large game developer), Python is one of three or four primary languages we use for everything. C++ for the games themselves, C# for UI heavy tools (this is relatively recent, C++ is also still used for a lot of tools), and Python for gluing it all together. (Lua would be the fourth, for in-engine scripting only).
In my world, Python replaced Perl as the language of choice for anything in a very broad "miscellaneous" category of tools. Mostly that happened 10 years ago, I haven't seen any Perl in a long, long time. Additionally, as it makes more sense to have web-based tools for certain things, Django has found its way in too. Since Python already has a strong foothold, Django makes a lot more sense in our environment than Rails.
I can find a smattering of things in other languages in our code bases, including Ruby and Erlang, but for the most part Python is the language of choice for things that aren't actual game code or Windows tools.
re: "rising star" demonstrated with google trends search of "python django, ruby rails, node.js"
I don't think is quite right; I never hear people say "python django" whereas I do hear "ruby on rails" at least as often as "rails". Note also rails is a general term and django is either the web framework or the jazz artist it is named after.
Not that I think this google trends data really mean that much, I think the following queries give context to help interpret the meaning of the parent's link.
[edit: someone else make the same point several hours ago, and this argument was not persuasive http://news.ycombinator.com/item?id=3277694 I just can't see making a serious decisions based on google search trends unless your job is SEO or something like that]
Ok I must admit that my original G-Trends queries don't help a lot but give a least some tendency. Your queries have also shortcoming in giving a good context: don't forget Django is a very popular word, just check Wikipedia and remember the very popular movie among lots of meanings.
"View All" only give me the titles, I still need to look at each individually. It's a bit like a FAQ that doesn't put multiple Qs and As on the same page; a pain. Part of the benefit would be scrolling through at speed, no comments interspersed, learning quickly, skipping already-known at a glance. Could be N per page to handle when total number is large as long as N >= 20. I'm looking at View All thinking some look interesting but I haven't the time to click round it all.
Not just PEP8-compliant. Some of these are just plain bad.
The first one I was greeted with when I opened the site was:
> print eval('+'.join(map(str, [1, 1])))
If I ever saw this in production code, I would lose my mind.
It's the kind of one-liner I'd expect to find in an obfuscated code competition. It's not intuitively understood, shows a lack of basic Python functionality (the builtin sum() function), and most of all, it's SLOW. As in, 54 times slower than a simple sum -- tested on xrange(1,10) -- on my development Macbook Pro.
That said, clicking through some other examples, there are a lot of great Python examples on this site. Just beware of some of them, and always make sure you test new code yourself.
You could show the output of this to the submitter (somewhat bad -- barrier to submission) or flag them yourself so you can correct them occasionally.
Examples:
$ pep8 optparse.py
optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1
optparse.py:88:5: E301 expected 1 blank line, found 0
$ pep8 --show-source --show-pep8 testsuite/E111.py
testsuite/E111.py:2:3: E111 indentation is not a multiple of four
print x
^
Use 4 spaces per indentation level.
For really old code that you don't want to mess up, you can
continue to use 8-space tabs.
Why? It's longer and requires an extra check to make sure that it's the same variable mentioned twice (i.e., you read to read it carefully to distinguish from [int(x) for y in "10 20 30".split(' ')]). Is it just that since comprehensions are more commonly used you think some people might forget what map does nad have to look it up?
import os
print os.listdir('.')
print open('turtle.py').read()
Edit: It seems like you're doing some; i can't inspect any directories outside the "jail", but being able to list the source code of your scripts is a security risk.
The problem is that sandboxing wasn't designed into the language so they don't give users a false sense of security with a bad sandbox.
To see the legacy of the sandbox, open an interpreter and run 'del __builtins__' to activate the restricted execution mode. Now, a lot of simple things like the import statement should fail. A good exercise in python internals is to manage to execute unrestricted code from this state via clever use of introspection.
Note: 'del __builtins__' is more than just removing access to builtin objects:
>>> f = file
>>> del __builtins__
>>> f('a.txt','w')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: file() constructor not accessible in restricted mode
Sorry, I think I broke your site. I realized based on one of the comments here that you seem to be running a persistent interpreter and then just running the code snippets. So I decided to see what would happen if I changed one of them...
So I found the snipped that did something like
import collections
foo = collections.defaultdict
and added
collections.defaultdict = None
to the end of it.
Next time I ran it the original snippet just gave a stack trace. Oops :) Anyway, looks like you need to work on sandboxing the snippets some more.
I would have sent this to you via email or other means, but I couldn't find any other way to contact you in your HN profile or on your site.
Output:
Traceback (most recent call last):
File "/base/data/home/apps/s~learnpythonjail/1.350338289496947596/main.py", line 99, in post
exec(cmd, safe_globals)
File "<string>", line 2, in <module>
TypeError: 'start' is an invalid keyword argument for this function
cool initative! seems like snippet numbers are random: 1 works but 2, 3, 4 don't. it would be nice to have categories or tags and a place to let others contribute snippets. i like the fact that the snippets are small and communicate one thing, otherwise it's comparable to the ActiveState website. It would be nice to make it downloadable in a pdf.
A small bug: Go on any random fact, eg: http://facts.learnpython.org/3007
Click on "Add your own", and then click go Back in your browser.
The snippet is blank.
This is Chrome 15 on Windows 7.
Love this idea, I think one small way to look some snippets look nicer would be to remove the absolute width/height on the snippet text box (to prevent the need for scrollbars).
It looks like you're using GAE. Not having much experience with it, I'm wondering if GAE provides the CPU jailing, or did you have to write some voodoo yourself?
I ask because it's trivially easy to send a statement containing a single bytecode that takes a really long time to execute, at least in CPython:
>>> print 999 * 0 # => 0, so not a bandwidth issue
If I send this to your backend in a bunch of tabs (I didn't) could that be a DoS?
Also, are you thinking of putting the backend code on github?
EDIT: HN swallowed my exponentiation. That should read "print nine to the nine to the nine, times zero". Without the times zero, that's a huge number.
Text after a blank line that is indented by two or more spaces is reproduced verbatim. http://news.ycombinator.com/formatdoc (the help link is in the bottom-right corner)
"There should be one -- and preferably only one -- obvious way to do it. If the implementation is easy to explain, it may be a good idea." AFAIK there is not a JavaScript version of Python which is fully compliant with the Python 2.6 specification.
Yes, and I meant that it would not be better to do this in JavaScript: It's far eaiser and simpler to have a real Python interpreter be doing the heavy lifting.
I suspect that the five line limitation was done so that the "Give me another one!" button was always in relatively the same place and easily clickable (I appreciate that), but perhaps there could be a small, duplicate text link up above the snippet for this purpose too, thereby also letting you make the snippets longer.