Posts tagged ‘Python’

Confusion over the forms of programming problems: Mathematics/Physics versus CS

I’m teaching Media Computation again this semester, about 250 students (over 50% female) in a huge lecture hall.  It’s hard to wander the room to answer questions, especially during peer instruction, but we do it anyways.

I’ve been thinking a lot about one question on the first quiz in week #2 of the class.  All my students are Georgia Tech undergraduates but not-CS majors, so, very smart, lots of math and science background, but almost no programming background.

Here was one of the two problems that had the lowest score. Students were to write down what this program would print.

def computeSalary():
  rate = 10.00
  hours = 40
  salary = hours * rate
  hours = 30
  print salary
  increase = 1.00
  salary = hours * (rate + increase)
  print salary

I suspect most teachers would think that this is a pretty standard first semester, even first couple weeks problem. I certainly did. I even discussed almost the exact same program in lecture.

The most common wrong answer was to write only what the second print statement generated. The first print statement was ignored.

During the last 5-10 minutes of the quiz, almost everyone was gone, and I answered lots of questions from the remaining students — picking my way through the narrow aisles in the lecture hall. They were struggling, so one might expect that they would try to get clues by asking questions. This was a problem that they asked lots of questions about.

I was struck by the words that students used when they described what was the one number that they were writing. One told me that the number she wrote down was the “result” of the function. Another told me that that was the “answer.” I came away with the sense that the students were thinking about the program as a mathematics function or a physics story problem.

We often talk about how computer programs might lead to misconceptions for students because of flawed transfer from mathematics. For example, Python functions have mutable data, use the “=” sign in a non-mathematical way, and have side effects. I wonder if the confusion here is about the similarity in form of the problem. Students see a series of equations in math, or a description of a situation in physics, and the answer is a number, an answer, a single result. Not so with programs — it’s a series of statements (like those others), but there may be more than one thing that the program does. We’d need to do real research to see if there is anything to this, not just me noting anecdotal comments from a half dozen students.

February 26, 2018 at 7:00 am 11 comments

Stanford CS department updates introductory courses: Java is Gone

See update here: Stanford is NOT switching from Java to JavaScript: I was mistaken

Stanford has decided to move away from Java in their intro courses. Surprisingly, they have decided to move to JavaScript.  Philip Guo showed that most top CS departments are moving to Python.  The Stanford Daily article linked below doesn’t address any other languages considered.

The SIGCSE-Members list recently polled all of their members to talk about what they’re currently teaching.  The final spreadsheet of results is here.  Python appears 60 times, C++ 54 times, Java 84 times, and JavaScript 28 times.  I was surprised to see how common C++ is, and if Java is dying (or “showing its age,” as Eric Roberts is quoted below), it’s going out as the reigning champ.

When Java came out in 1995, the computer science faculty was excited to transition to the new language. Roberts wrote the textbooks, worked with other faculty members to restructure the course and assignments and introduced Java at Stanford in 2002. “Java had stabilized,” Roberts said. “It was clear that many universities were going in that direction. It’s 2017 now, and Java is showing its age.” According to Roberts, Java was intended early on as “the language of the Internet”. But now, more than a decade after the transition to Java, Javascript has taken its place as a web language.

Source: CS department updates introductory courses | Stanford Daily

ADDENDUM: As you see from Nick Parlante’s comment below, the JavaScript version is only an experiment.  From people I’ve talked to at Stanford, and from how I read the article quoted above (“more than a decade after the transition to Java, Javascript has taken its place”), I believe that Stanford is ending Java in CS106.  I’m leaving the title as-is for now. I’ve offered to Marty Stepp that if CS106 is still predominantly Java in one year, I will post a new blog post admitting that I was wrong.  Someone remind me in April 2018, please.

April 21, 2017 at 7:09 am 36 comments

Where are the Python 3 Libraries for Media Computation

My Blog@CACM post for this month is on JES, the Jython Environment for Students, which at 14 years old and over 10,000 downloads, is probably one of the oldest, most used, and (by some definition) most successful pedagogical Python IDE’s.

The SIGCSE Members list recently had a discussion about moving from Python 2 to Python 3. Here’s a description of differences. Some writers asked about MediaComp. With respect to the Media Computation libraries, one wrote:

I’m sad about this one, because we use and like this textbook, but I think it’s time to move to Python 3.  Is there a compatible library providing the API used in the text?

Short answer: No. There are no compatible Media Computation libraries for CPython 2 or 3.

We keep trying. The latest attempt to build Media Computation libraries in CPython is here: https://github.com/sportsracer48/mediapy. It doesn’t work on all platforms yet, e.g., I can’t get it to load on MacOS.

We have yet to find a set of libraries in Python that work cross-platform identically for sample-level manipulations of sounds. For example, PyGame’s mixer object doesn’t work exactly the same on all platforms (e.g., sampling rates aren’t handled the same on all platforms, so the same code plays different speed output on different platforms). I can do pixel-level manipulations using PIL. We have not yet tried to find libraries from frame manipulations of video (as individual images). I have just downloaded the relevant libraries for Python 3 and plan to explore in the future, but since we can’t make it work yet in Python 2 (which has more mature libraries), I doubt it will work in Python 3.

I complained about this problem in my blog in 2011 (see post here). The situation is better in other languages, but not yet in Python.

  • I have been building Media Computation examples in GP, a blocks-based language (see post here).
  • Jeff Gray’s group at U. Alabama has built Blockly-like languages Pixly and Tunely for pixel and sample level manipulations.
  • Cynthia Lee at Stanford has been doing Media Computation in her classes in MATLAB and in C++
  • The Calico project supports Media Computation in IronPython (based on Python 3) and many other languages, because it builds on .NET/MONO which has good multimedia support.
  • We’re able to more and more in JavaScript-based Python implementations (like Pythy and Runestone), because JavaScript has excellent cross-platform multimedia support.

When we did the 4th edition of our Python Media Computation textbook, I looked into what we’d have to change in the book to move to Python 3. There really wasn’t much. We would have to introduce print as a function. We do very little integer division, so we’d have to explain that. The focus in our course (non-technical majors, first course) is at a higher level than the differences between Python 2 and 3. I am confident that, at the end of our course, the majority of our students would understand the differences between Python 2 and 3. As we move more to browser-based IDE’s, I can support either Python 2 or 3 syntax and semantics. Preparing students for industry jobs using exactly CPython 3 is simply not a priority in our course.

August 19, 2016 at 7:46 am Leave a comment

Do blocks equal “making” and text equal “coding”? Doing MediaComp in Blocks-Based Languages

Interesting perspective from a blogger in the Scratch community, liked below.  I do frequently hear the pattern described in the post quoted below.  “I’ve started by daughter/niece/local-school on Scratch, and now I want to know how to move them into something ‘real’ (e.g., text).”  I typically point them to amazing things that can be done in Scratch (like Alex Ruthmann’s beautiful livecoding of music in Scratch).

I recently got a chance to play with GP, a new programming language from John Maloney (of Scratch fame), where all blocks and texts are isomorphic.  There’s a slider that lets you switch from one to the other.  Even the debugger and class browser show up with tiles.  Where does that play out in this debate?  GP is the first blocks-based language I’ve used with the right primitives to do MediaComp, so I built one of my examples in it.  Took me about three times as much time to write and four times as much space (in screen real estate) as in Python (even with John looking over my shoulder guiding me).  Maybe that’s not a bad thing — maybe that encourages a different style of use.  Next time I try something like that, I’m far more likely to think about building my own blocks and using more abstraction to save on dragging-and-fitting effort.

I’ve been a part of the Scratch community for about 8 years now (yes, really). During this time, I’ve noticed a pattern that seems to apply to a lot of people:

join Scratch => create projects => discover text-based programming => quit Scratch because of “real programming”

Note the scare quotes around “real programming”. Generally, a “real” programming language is text-based (C, Python, etc.) and apparently qualifies as real because it’s used by well-known developers for something.

Obviously I disagree with disqualifying Scratch as a real programming language.

via Making vs Coding | byte.

July 8, 2015 at 7:14 am 23 comments

JES 5.02 Now Released, and Media Computation 4th Edition Slides Available

JES 5.02 is now released at https://github.com/gatech-csl/jes/releases/tag/5.020.  I have links to all the main downloads at http://mediacomputation.org .

This is a maintenance release.  Thanks to Nina Koch’s student, Henry, we have fixes for colorizing and some other problems.  Henry has also written code to allow for capture of keystrokes and mouse movement in a picture window, so that you could build some simple games.  I’ll save that for JES 5.10.
I don’t do JES releases that often, so in-between, I forget how painful cross-platform development is. JES is all written in Java and Jython, which means we “write once, test everywhere.”  I developed mostly on Mac OS X, but makensis (for Windows Installers) doesn’t work on Mac OS X.  So I ran Ubuntu in VirtualBox to build the Windows installer and test the Linux version.  But I still had to test on Windows (e.g., to make sure that the Sound Explorer was fixed).  It’s all details —  ls here vs. dir/w there, can’t install Oracle Java from Ubuntu installer, remembering sudo apt-get, Lenovo toolkit updater interrupting installations…
From Github:
 Fixes in JES 5.02 (with many thanks to HenryStevens and sportsracer48 for fixes):
  • Fixes a problem if you quit during raw_input that you can’t do another raw_input
  • Makes the Sound explorer fully functional again
  • Fixes colorizing
  • Makes autosave work again
  • Fixes a threading error if you hit return too rapidly in the Command Area
  • Unicode characters in input file get flagged. (Jython can’t execute a line with unicode characters on it.)

In addition,

You can find all the fourth edition Powerpoint slides (including a 68Mb zip of all of them) at http://coweb.cc.gatech.edu/mediaComp-teach/60. I’ve put some of the Peer Instruction question slides into the chapter PPT slide decks, but you can find more at the instructors-only website (see the Media Computation website for more on the teacher website).

Most of the changes are in the early chapters. Chapter 3 on text and language manipulation is all new. The latter chapter PPT slide decks have a few new slides in each deck, including:

  • Creating state-preserving versions of picture manipulation functions in Chapter 16 on Functional Programming
  • Subclassing Picture and Sound to move functions into methods in Chapter 17 on Object-oriented Programming
  • Recursive turtle patterns, which are possible with an improved Turtle class in JES 5 in Chapter 17

May 15, 2015 at 7:59 am Leave a comment

Fourth edition of Python Media Computation released today: Teacher resources and desirable difficulties

Python-4ed-MediaComp-cover

According to Amazon, the Fourth Edition of the Python Media Computation book is released today (see page here). That’s the new cover above. I’ve been working on the 4th edition for most of the summer. Some of the bigger changes are:

  • Before we manipulate pictures, we manipulate letters, words, and language, e.g., build “MadLib” and “koan” generators, and encoding and decoding keyword ciphers. Language is a medium, too, and it’s easier to get started (for some folks) with the smaller-iteration loops of text before getting to the thousands-of-iterations loops of pixels in a picture. It’s an optional chapter — everything introduced there gets introduced again later.
  • Since the new version of JES fixed a round-off error in the Turtle class, we can do recursive turtle manipulations now (which tended to get messed up in earlier forms of JES).
  • I juggled content around so that we do more with conditionals and querying the pixel for its position, before we introduce nested loops. Nested loops are really hard for students, and I learned (from seeing the code that my students wrote) that they can do far more than I’d guessed with single loops — even with multiple pictures. I included more of that.
  • I have tried (for the last two editions) to provide screen-scraping examples, e.g., writing code to pull weather, news, or friends’ information from websites.  It’s getting harder and harder to write that kind of code.  Instead, I decided to provide more code that parses CSV files, as can be found at Open Data Journalism sites (like at The Guardian) and sources like the US Census.  The examples are still about parsing out useful information, but it’s a lot easier to parse CSV and encouraged at these sites.
  • There are more end of chapter problems, and new pictures.  And trying to catch all the errors in the Third Edition that master teachers like Susan Schwartz (at West Point) found.

We’re working on teacher resources now. Currently in development (aiming to have ready in the next couple months) the Powerpoint slides for each chapter of the book, a collection of all the code in the book for teachers, and a solutions manual for every end of chapter problem. These are surprisingly controversial. There are lots (mostly University) teachers who think that I shouldn’t provide any of these resources — teachers should be able to develop all of those themselves. Most of the high school and community college teachers I know appreciate having them.

In searching for the Fourth Edition on Amazon, I read the comments on the Third Edition (see here). Authors probably shouldn’t read the reviews of the book — they’re painful. But I did, and even worse, I actually responded.

Here is a quote from one, titled “False Advertising.”

Its biggest problem: false advertising. This is NOT a book on Python, it’s about JYTHON – A Java based imitation of Python.
Why? Well, there’s some pretty software, available to download, which uses the the JRE. The author chose to stick with this “easy learning environment” and basically cripple anyone wanting to write Python code for Blender, Maya, Android etc.

You may learn to program from this text, but don’t expect a trouble-free life when you get exposed to the real language.

Here was my response:

Everything in this book is useful when wanting to write Python code for Blender, Maya, Android, etc. This is an introductory book on data, loops, conditionals, and objects. Those parts of Python are identical in this book and in the Python that you’ll use in Blender, Maya, and Android. For introductory Python programming, Jython and CPython are exactly the same.

I was surprised to see the original commenter responded. His point was that some kinds of friction, in dealing with the “real world” is desirable:

As an introductory book, I would expect a section on how to install and configure Python. Written covering Windows, Linux, and the Mac OSX. There is no such section; the whole point of Jython is to “hide” this technical level. Which is fine for learning loops etc. but leaves a student lost when encountering Python out in the real world.

It’s an interesting perspective, kind of a “rugged individualism” approach. I do agree with the notion of desirable difficulties in learning (see more here),  but don’t agree that installing Python is one of those.  Do most Python programmers install Python themselves, or is it already installed on the servers, computers, etc. that they will be programming? Is it a critical part of learning a language? Is it significantly different than installing JES (try that here)? Are you “lost” and unable to program if you don’t install it yourself first?

A sad addendum to this story: Our Media Computation data structures book (see the Amazon page here) has gone out of print. The publisher didn’t notify us. Someone approached us about using the book, and was told that it was out of print. When I queried Pearson, they admitted it. More, because it’s not out of print everywhere (I guess it’s available in some non-US markets), Pearson won’t let us post the content anywhere. It’s a dead book now.

January 26, 2015 at 8:28 am 10 comments

African-American students preference for graphical or text-based programming languages depended on career goals

One of the results from Betsy DiSalvo’s dissertation on Glitch (see a post on that work) that I found most interesting was that there wasn’t a clear winner between graphical, drag-and-drop programming (Alice) and text-based programming (Python).  She has now written up that part of the dissertation work, and it’s linked below.

Cursor_and_Betsy-Alice-Python_pdf__page_3_of_4_

To determine appropriate computer science curricula, educators sought to better understand the different affordances of teaching with a visual programming language (Alice) or a text-based language (Jython). Although students often preferred one language, that language wasn’t necessarily the one from which they learned the most.

via IEEE Xplore Abstract – Graphical Qualities of Educational Technology: Using Drag-and-Drop and Text-Based Programs for Intro….

January 12, 2015 at 8:39 am 7 comments

Older Posts


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 4,306 other followers

Feeds

Recent Posts

Blog Stats

  • 1,564,714 hits
October 2018
M T W T F S S
« Sep    
1234567
891011121314
15161718192021
22232425262728
293031  

CS Teaching Tips