Friday, May 18, 2012

Python vs. Processing as a First Language

When I asked my social networks what they thought was the best language to learn to program with, most said Python.  I've always heard great things about this as a first language, so I went along with it.  But one person said Processing, a language / tool I have been using for a while.  After learning a few basics of Python, I'm wondering if Processing really would be a better choice.

I started learning Python from the official beginner's guide (specifically, the Python Tutorial), designed for those who know how to program.  They also have a list of tutorials for non-programmers, but I didn't look at any of those.  Almost right away, I found myself thinking, 'Really? This is supposed to be easier for beginners?' The tabbing to define blocks, the somewhat frightening look of the official interpreter, the strange syntax with colons and range functions in loops... I just imagined myself saying, "Trust me, you'll understand this later" to an awful lot of things.

But, to be fair, I was looking at the documentation for experienced programmers.  Maybe if I read a source for beginners I could see the value a bit more easily.

So I put a copy of Invent Your Own Computer Games With Python on my Kindle and started reading.  This book aims to teach programming from the ground up in the context of games.  Considering how most programming books work, this one seems to approach things in a more interesting way.  Even still, the author has to pause from the context of the game being made and discuss the programming concepts for pages.  And he still has to note that certain syntaxes are beyond the scope of the book, or that you'll understand some particular thing later on.

I thought Python was supposed to get rid of this problem!

You could argue that Python is a good choice because it lets you do things quickly.  But I'd argue that Processing lets you do things even faster.  That games programming book? So far I'm more than halfway through and nothing has moved beyond text-based games.  But in Processing, your first program is almost certainly going to be entirely visual.  I love that with very little code you can get up and running in Processing right away and have something feels like an accomplishment.

Furthermore, I think that the syntax of Processing is more straightforward in many ways.  You can do a lot with some basic math, one or two types of loops, and standard method calls.  You can add literally one line of code to your project and get a visual result right away (as seen in this beginner's tutorial).  Yes, you will need to implement a method or two to really get going (setup and draw), but these actually make sense in a logical way, more so than the main of many languages.

It's true that Processing isn't interpreted like Python is, potentially introducing some issues with compiling.  But the compile and run process is abstracted quite nicely with the play button, so it's not all bad.  You can get errors in either type of language, of course.

I admit that I may be biased at this point since I'm not a Python expert yet, potentially making the comparison unfair.  On the other hand, now is really the best time for me to analyze Python fairly given that I don't know it well at all, just like other beginners.  Either way, I'll have a chance to learn more about how well Python works as a beginner's language as we work on our book on CS for beginners, since that's the language we've decided to include.

28 comments:

  1. I taught basic programming concepts using Python as my medium for two years in a high school setting and I would almost certainly have transitioned away from it this year had I continued teaching there. I think a lot of what makes it fantastic for experts -- multiple paradigms, concise syntax, duck typing, many ways to do one thing -- make it a difficult context for teaching and for novice productivity in general.

    I had students do a little bit in Processing then but not very much. I'm pretty sure it's the medium I'll use for middle/high school summer camps coming up. I'm looking forward to it!

    ReplyDelete
  2. Interesting! I look forward to seeing how Processing works for you in that context. Our undergrad curriculum started using Processing for the first programming course, and though I don't have specific information on how well that's gone, it seems to be a good thing.

    ReplyDelete
  3. Casey Reas and Ben Fry (original authors of processing) agree. They argued as much in their book, Processing: A Programming Handbook for Visual Designers and Artists. It's definitely not for everyone, but the idea of producing beautiful images can be a very significant motivator for some new programmers.

    ReplyDelete
  4. You could also get the best of both world and look into NodeBox http://nodebox.net/code/index.php/Home it is awesome fun ;)

    ReplyDelete
  5. May I suggest that you also take a look at Kojo, a Scala based learning environment for children that I have been working on for the past couple of years.
    It's real easy to get started, and you can go on to explore very many rich areas like:
    - Recursive Drawing
    - Fractals and L-Systems
    - Animations and Games (see included samples)
    - Storytelling (see the included Stories)
    - Basic to Advanced Computer Science (you have access to Scala, after all!)

    If you get a chance to look at Kojo, any feedback that you might have would be very welcome.

    ReplyDelete
  6. My learning path looks like this:

    1. Scratch http://scratch.mit.edu
    2. Processing
    3. Java or/and Python
    4. ...

    And at this moment I'm in point number 2.
    I think for the most of people Python won't be a good start. It's to overwhelming, to complex, to abstract. Processing has everything you need to start: a simple IDE, at least 3 books for people like me, with no programming background, humanists I would say, really simple syntax.

    ReplyDelete
  7. I found Processing the easiest to get started with, because you can write one line of code and see the resulting shape on the screen. With two lines you get an animation.

    But not having to declare types and avoiding HashMaps and iterators makes Python easier in that sense. I wish the standard Processing was Python-based.

    This is my attempt to teach using Processing: http://funprogramming.org

    ReplyDelete
  8. I've been teaching myself programming for a while and even though I tried python and processing roughly at the same time (when I didn't know anything but html), Processing is what gave me my first "A-ha!" moment and made me realize that programming could be fun (thus motivating me to go on). There's something about pressing that play button and seeing what you write translate inmediately into something that gets you over the fear of code very quickly.

    As soon as I got a bit better and I felt Processing was asking me to do more complicated java structures though, I stopped using it, and nowadays I get that same kick out of trying new things in the python interpreter. Processing works very well as an introductory rite - but I think if you want to progress beyond the category of "designer that knows a bit of processing" you eventually need to let go of the visual crutches and start loving the play of numbers and data by itself without the eye candy. Maybe that's just me though.

    ReplyDelete
  9. Thanks all for the comments! Very interesting. :)

    ReplyDelete
  10. If your only gripe with Processing is that it requires compilation, try Processing.js. Using a Web IDE, like hascanvas or sketchpad, your students can start creating directly from their browser, no download nor compilation required.

    I think that Processing is better than Python, because motivating students with quick results is much more important than the difficulty of the language; if they are motivated enough, I bet they can learn anything.

    ReplyDelete
  11. I guess I would want a better definition of "learn programming". I prefer Scratch and Small Basic for a beginning language but that is for total beginners which is what I deal with mostly. After that I use Corona. It really gets the kids involved when they get to make a game they can save on their own device. I need to take a look at Processing.

    ReplyDelete
  12. I'm a *huge* fan of processing pedagogically speaking. The community is great for beginners, and beginners can quickly join in the fun of helping others easily. Many of the people who have written books about it are great teachers in and of themselves. That there is a visual example for every word in the reference was invaluable to me when I first started learning. Having said that, you can have it both ways these days: https://code.google.com/p/pyprocessing/wiki/QuickReference

    ReplyDelete
  13. Hi everyone! I thought I'd take a few minutes to respond more directly to at least some of your comments.

    I just discovered that this post was linked on Hacker News, so you may also be interested in seeing my responses there (I posted as gailcarm). Some of my comments might add some context to where I was coming from with this post, since on its own it might not be entirely clear.

    I've seen a couple of mentions of NodeBox now, so this is something I definitely have to check out sometime soon.

    Abe: It seems that there is a Processing variant that is Python based. I have not looked into it myself, but pyprocessing came up on HN and above in the comments.

    A few of you mentioned Processing being the motivation you needed to continue to learn programming. That's one of the things I find really important in a first language, especially for non-traditional CS students. I also think that specifics of a language can cause those students to give up or feel like they are failing before they deserve to; we need to find languages that help transition them into the right mindset. Where you go from there (or maybe even where you start) depends on who you are and what your goals are.

    gelisam: I'm not convinced that compiling is necessarily bad, but I did recently have an interesting conversation with a friend who quickly got away from programming after the first course. She understood the concepts (as proven by her exam mark), but got hung up on being unable to compile her programs for some small reasons. She later learned interpreted languages because they are more forgiving that way.

    Garth: I often use Scratch as well, actually. I have found it even works well with adults. I was really trying just to compare Python and Processing here, but certainly there are arguments for many other languages being good as starters too.

    ReplyDelete
  14. Personally, I've been recommending Scratch to start, and Python as a second language (then Java, C, or C++ depending what the student wants to do).

    Scratch provides all the instant gratification that Processing supposedly provides, with a much lower entry barrier.

    Python provides a very simple, elegant language in the Algol-derived family that allows teaching more advanced concepts like object orientation.

    ReplyDelete
  15. I got wrapped up in the "first language" excitement. I have tinkered with Python and found it cumbersom to get set up and not idiot friendly. Processing is a piece of cake to get running and provides nice instant gratification, something a true beginner likes. I also like the true beginner tutorials that are online for Processing.

    ReplyDelete
  16. If you learn Scratch, I would like to suggest trying BYOB instead.

    http://byob.berkeley.edu/

    UC Berkeley version of Scratch (soon to be updated to Snap).

    Scratch is limited, and BYOB introduces Lambda and creating functions. This makes it turing complete, and a fully viable programming language.

    ReplyDelete
  17. Wouldn't it be useful to smoothly transition from Scratch to Processing without changing anything but the language? We are working on a system which allows that... we have a generic "Processing" library which can be used by any of our supported languages (including a Scratch-inspired language, called Jigsaw, and Python). Check out http://calicoproject.org/

    ReplyDelete
  18. I learnt to program almost 30 years ago. Using *LOGO*. I was 10 years old back then, and I can tell you it was rather impressive to have a result out the first sentence I wrote at the interpreter's prompt.

    Sure, the language is quite dated, but if you want "something visual" from the very beginning, nothing that I've seen so far beats it, which I'd say is a quite impressive for a language created in the late 60s.

    And people tend to disrespect LOGO as a "children's language", forgetting that it's a proud LISP descendant, and that it's still a much more powerful language than it looks like.

    ReplyDelete
  19. If you want quick python gui start with kivy.org
    It's cool python libraries set. You can design UI using kv language there.
    Just one line in kv file will create button:

    from kivy.core.builder import builder
    builder.load('''
    Button:

    #Later you can ad some details to it..
    id:button1
    text:'my button'
    on_press: button1.text='now I am pressed'
    font:
    font_size:

    ReplyDelete
  20. It really depends. If you are more artistic and visual then Processing in really fabulous. But if you want something for general purpose programming that hook into a vast array of existing code bodies and tools then python or ruby. Either of these is much easier to learn than Java, C, C#, c++.

    ReplyDelete
  21. I use processing to teach into students, especially artists and people with computer and math problems,. Works exceptionally well. Processing can do anything Java and C++ can do, of course, but there's no need to get into complex computations at first. Processing handles the weird syntax of Java very nicely and with no magic, Difficult things like drawing to a window and getting mouse coordinates are dead simple. Can't see any reason NOT to use processing - I've taught Fortran C, Java, C++, PL/1 all as first languages: Processing is by far the best.

    ReplyDelete
  22. Only tangentially related, but I just ran across this [http://pythontutor.com/] and thought you might find it interesting (considering how much easier it would have made some of the examples I've seen you run through in class).

    ReplyDelete
  23. Funnily enough I happened to bump into that myself just the other day! I've got it in my list of resources. I'm pretty sure I'll stick with Python for the arts/social science class since that's what everyone in the field uses, but I think I'll use Python turtle (drawing) as the thing everyone has to learn, and then make the rest a choice or bonus.

    ReplyDelete
  24. i've been learning python for awhile. i discovered processing last night when looking into some supercollider stuff (really awesome musical programming lang) i wanted to recommend "how to think like a computer scientist" on openbooks.
    it just teaches cs and uses python 3 to illustrate. i will say about python, it really is easier to learn because it's just so much less clunky than java or c. the simplicity helps get the point across. the book also ramps up to programming some py games etc it's really very good.
    http://openbookproject.net/thinkcs/python/english3e/

    ReplyDelete
  25. Hey, Processing supports Python mode (see "Add Mode") ;)
    and there are some similar alternatives for Python
    http://secondcomingforprocessingpy.blogspot.com/

    ReplyDelete
  26. I started teaching Snap this year for my beginning programming class and it was excellent. I am curious how processing compares to snap.

    ReplyDelete
  27. I'm teaching a two-semester course now that starts with C/Arduino and goes into Python in the second semester. I'm finding Python is a great language syntax-wise for students. But the problems are twofold:

    1. dismal multimedia support: getting graphics and sound up and running is a huge kludge, tkinter is a nogo.. I've been using PyQt5 which is pretty understandable once we've moved past the OOP hurdle, but still, it's a GUI language and its not easy to build interactive graphics (at least not that I've been able to figure out yet) - let alone work with sound!

    2. dismal distribution methods: students want to share their work, packaging stand-alone apps in python is a nightmare. Processing really has the advantage here. Although I've heard PyQt5 has a new deployment system.

    That being said, python has things going for it:

    1. There's no sandbox like with Processing. Students can learn to use the command line and really be down & dirty with their computers. I find this valuable as a learning experience.

    2. the language is extremely elegant, my students have had no problems picking up the syntax, despite what others have said above. They find it a total pleasure vs. the clunkiness of C.

    3. net connectivity to various APIs and modules is very good (just not graphics & sound! :-( )

    I'd love to hear what you all think about this.

    ReplyDelete
  28. @hairbear I just wrote a nice long comment and accidentally pressed the wrong button and lost it. :( I really should do an updated post now that I've used both Python and Processing with beginners for several years. I still choose Processing as my favourite beginner's language.

    I prefer Processing for all your points above, even the ones that you list as pros for Python. For example, I don't want to use the command line in my first intro to programming; I prefer to save that for later. I find it can be too intimidating for some first timers, especially those from underrepresented groups. Processing is Java, but with the uglier parts abstracted away. Processing has lots of cool libraries available for it, and you can use whatever is available in Java too.

    ReplyDelete

Comments are moderated - please be patient while I approve yours.

Note: Only a member of this blog may post a comment.