Thursday, December 12, 2019

Explain This Confusing Code

My major task today has been finishing off the semester exam for my Advanced Placement Computer Science Principles students. They’re not happy about having an exam but that’s life. Writing a good exam is difficult. Fortunately I have some previous exams to work with. Some I wrote, some other AP CS P teachers wrote. I’m getting close to done. I want to have AP exam style questions to help my students prepare for the actual AP exam in the spring but of course the main purpose is to put a grade in the grade book. OK I’m half kidding. I seriously want to get a handle on what information they have learned and what I should review before we move on.

Coincidently someone posted a question for the AP CS A question bank on Facebook asking for help with explaining it.

How does this evaluate for Java: x / 10 % 2 ?

This is exactly the sort of question that had one of my APCS A students some years ago say there were a lot of examples of poor coding practice in the AP Exam. And this, in my opinion, is a terrible coding practice. I can understand why the question may be attractive to some. The whole order of operations thing. Students should understand it. But good coding practice is to avoid ambiguity and this code is loaded with ambiguity.

Is this integer division? 10 looks like an integer to me. Making it 10.0 would make it look like a floating point number of course. How do you make “x” look like a specific data type? This is not FORTRAN IV where it would be a double since it doesn’t start with a letter from “i” through “n.” And remembering the order of precedence between modulus and division? Who has room in their brain for that to be top of mind?

This makes a great discussion question. A great question to emphasis the need to use parentheses to remove ambiguity. There is no way it would pass code review in a professional development environment though. At least not a review I want to be part of.

Well, I should go finish writing my test and trying to avoid writing horrible questions.

No comments: