<p>I know this is coming a week after you wanted it... but, I am an APCS-A teacher and I have been a AP Reader in the past.</p>
<p>The scoring guidelines are applied thusly:</p>
<ol>
<li>mistake in the code causes bounds error  - Deduct the point for accessing array</li>
<li>having deducted a point, pretend the problem is fixed</li>
<li>continue scoring with fix</li>
</ol>
<p>The goal is to not have a single issue rob a student of all the points.</p>
<p>The one exception is the &quot;did they get it right&quot; point. This would be the result of debate with your elbow partner, the table leader and the question leaders.</p>
<p>In your specific example the student would probably lose both points as the guideline is specifically mentioning a completed condition that was never reached.</p>

CC BY-SA 4.0
2022-05-11T16:26:59.087Z
2022-05-11T16:26:59.087Z
codingCat
<p>I don't educate on the AP level, but let me trot out one or two of my hobby horses^W^W things that I try to teach my students.</p>
<p>One. I object to this code structure. Semantically, a loop serves to compute something, so you want a code structure</p>
<pre><code>int your_result;
for (whatever) { do something }
return your_result.
</code></pre>
<p>By having the return in the loop you subvert this structure, conflating the loop and the surrounding function.</p>
<p>I try to prevent this sort of construct by showing how to derive code by textual refinement. You go from</p>
<pre><code>// compute a result
</code></pre>
<p>to</p>
<pre><code>result = compute_result()
</code></pre>
<p>to</p>
<pre><code>function compute_result() {
    result = init;
    // do all tests
    return result;
}
</code></pre>
<p>to the full code. (This principle of textual refinement also postpones introducing local variables to the last moment, so they automatically are in the correct scope!)</p>
<p>Two. Loops that serve some test are (usually) either a for-all predicate or a there-is predicate. So, with the above structure, this is a there-exists problem:</p>
<pre><code>bool element_is_present = false;
for ( elements )
  if ( condition )
     element_is_present = true;
</code></pre>
<p>and then you can jump out of the loop prematurely because a single true test is enough for the conclusion. And then refine this loop to suit the problem.</p>

CC BY-SA 4.0
2022-03-28T14:27:22.957Z
I disagree, actually. See: https://cseducators.stackexchange.com/q/4427/1293. On the other hand, I write very short methods where it isn't an issue. I strive for [Cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity) = 1.
Buffy
CC BY-SA 4.0
2022-03-28T14:49:32.170Z
I see your point about minimizing mentally retained state. However, in my above distinction of eixsts/forall loops this presupposes that the student has already recognized that there is a exists problem, where indeed early return is possible. In this case, the question asks about accessing "all" elements so an early return is not possible and the whole code structure is wrong. So my second point stands that they need to start by analyzing the propositional status of the for loop.
Victor Eijkhout
CC BY-SA 4.0
2022-03-28T14:51:14.823Z
Addressing your objections to my first point explicitly: I like deriving code by textual refinment. And your early returns are not amenable to such an approach. In fact, I find early returns kind of a hackerish solution with the main justification that "it works". How do *you* teach when early returns are possible and when not?
Victor Eijkhout
CC BY-SA 4.0
2022-03-28T16:31:23.037Z
@Buffy Another thought: most programming language lack introspection so data is the only thing that is visible. With early returns you're teaching students a pattern that they need to process completely mentally, and the code is either all right or all wrong, with no visual indication as to the structure of that pattern. So I think you *are* overloading their mental capacities: they have to consider code paths entirely in their head. Whereas in my approach the code is clearly leveled, with each textual refinment having a clear function.
Victor Eijkhout
CC BY-SA 4.0
2022-03-28T13:43:43.853Z
2022-03-28T13:43:43.853Z
Victor Eijkhout
<p>I am also not an AP Grader, though I have taught the class for well over a decade now, and I am pretty sure about this would be approached on the actual AP test.</p>
<p>(If you pursue this further, and I do turn out to be wrong, please post a new answer with a correction.)</p>
<p>There are two considerations:</p>
<ol>
<li><p>My understanding has been that every area of code is examined in isolation, and examined as if all of the code around it were good.</p>
</li>
<li><p>Furthermore, the first rubric point concerns itself with the loop, and the second point with the return.  This is a philosophical separation in addition to the code separation I outlined above.</p>
</li>
</ol>
<p>For both reasons, then, since the loop itself is fine, the student would receive that point.  However, the student would lose the second point, since they are returning the wrong answer much of the time.</p>
<p>The reason for the separation of concerns in point 1 is because otherwise you get into sudden death scenarios where one small mistake brings you from 5 points on a large item to 0, since none of the items are ever actually fulfilled.  Such scores are clearly out of line with the work produced by the students.</p>

CC BY-SA 4.0
2022-03-26T11:18:05.823Z
Actually the loop doesn't access all necessary entries.
Buffy
CC BY-SA 4.0
2022-03-26T12:32:00.200Z
@Buffy Only if you neglect point 1 it doesn't.  If you begin to get overly technical with these rubric wordings, they stop working entirely.  Students can give outright incorrect answers to questions, but still get awarded every point on the rubric.  These all have to be taken in a spirit of intentionality, or they just stop making sense.
Ben I.
CC BY-SA 4.0
2022-03-26T23:01:55.720Z
Thanks for sharing your experience. I like the idea that I can treat the points as separate concerns and award them accordingly.
ThisClark
CC BY-SA 4.0
2022-03-27T13:40:36.330Z
What am I missing here? The method/function that contains this code returns after examining only one element. It clearly doesn't "access all necessary elements". The returns short circuit both the loop and the containing method. The student is clearly confused. I'd like to see what an official ruling would be. This seems clearly wrong to me.
Buffy
CC BY-SA 4.0
2022-03-27T14:23:58.743Z
@Buffy We can ask on the listserver. I would be surprised if it came out differently.  Separate the loop (basically just the declaration) from its contents. Each major component should be read as if the other code  around it was appropriate.  I believe that the rationale for this is that it avoids point cascades. Under the stricter reading you are using, for instance, the second point is always inaccessible if the first point is unearned, no matter what else the student does.
Ben I.
CC BY-SA 4.0
2022-03-28T09:17:14.383Z
@BenI. But you have to treat a premature return or break or whatever as part of the loop declaration: `while(i<array.size)` is NOT equal to `while(i<array.size && !found)` . And I'd argue it's easier to construct code that makes the return part correct than the loop part. So I'd rather give credit for the second part depending what the focus should be, the actual return or the correct array access.
Max
CC BY-SA 4.0
2022-03-28T15:06:17.193Z
@Max I can see that way of thinking about it, too.  I'm not sure how the AP graders would come out on it specifically, though I am reasonably confident that one (and only one) of the two points would be awarded.
Ben I.
CC BY-SA 4.0
2022-03-26T03:32:05.310Z
2022-03-26T03:32:05.310Z
Ben I.
<p>If a question (eg free response 2015 #3) has the following criteria:</p>
<blockquote>
<p>+1 Accesses all necessary elements of entries (No bounds errors) <br><br>
+1 Returns identified value or returns 0 if no entry exists in entries with row index row and column index col</p>
</blockquote>
<p>... and the student prematurely exits a loop with this common if-else return mistake:</p>
<pre><code>for(SparseArrayEntry entry : entries) {
    if(entry.getRow() == row &amp;&amp; entry.getCol() == col) {
        return entry.getValue();
    } else { // mistake, loop will only ever run once
        return 0; // should do this return after loop
    }
}
</code></pre>
<p>Does the student lose both of the above points because 1) the premature return prevents accessing all necessary elements, and 2) a zero might be returned in spite of the fact an entry does exist.</p>
<p>It feels like double jeopardy but I was hoping an AP grader or someone with more experience teaching the course could weigh in on the decision.</p>

CC BY-SA 4.0
2022-03-25T19:54:01.557Z
This question is better asked on the APCS mailing list. The people there know the rules. But IIRC, for free response questions there aren't "forbidden but correct" constructs. I hope that is still true. But the student has, in fact failed both tests unless they get a hit on the first element. But I'm not a grader.
Buffy
CC BY-SA 4.0
2022-03-26T03:20:29.920Z
@Buffy I would not direct AP teachers away from this site; we have plenty of AP expertise here, I think.  And our format is *much* better than that mess of a mailing list for addressing such questions.
Ben I.
CC BY-SA 4.0
2022-03-26T15:30:50.540Z
@BenI., I disagree for questions like this one. The advice given there for questions like this reflect official policy due to the folks that answer there.
Buffy
CC BY-SA 4.0
2022-03-26T16:54:32.823Z
@Buffy I mean, we're not the official college board site, though questioners here would presumably know that. AP teachers all have to sign up through the college board process, and register through AP Classroom.  But the listserver there is a morass, difficult to use, and practically unsearchable.  Answers here remain searchable, and can be fixed at any time.
Ben I.
<ap-computer-science-a>
APCSA 2015 Q3, grading criteria
# APCSA 2015 Q3, grading criteria

(Asked by: username_0 on 2022-03-25)

If a question (eg free response 2015 #3) has the following criteria:

+1 Accesses all necessary elements of entries (No bounds errors) 
+1 Returns identified value or returns 0 if no entry exists in entries with row index row and column index col

... and the student prematurely exits a loop with this common if-else return mistake:
for(SparseArrayEntry entry : entries) {
    if(entry.getRow() == row && entry.getCol() == col) {
        return entry.getValue();
    } else { // mistake, loop will only ever run once
        return 0; // should do this return after loop
    }
}

Does the student lose both of the above points because 1) the premature return prevents accessing all necessary elements, and 2) a zero might be returned in spite of the fact an entry does exist.
It feels like double jeopardy but I was hoping an AP grader or someone with more experience teaching the course could weigh in on the decision.

**Tags:** ap-computer-science-a

> **Comments:**
> **username_1**: This question is better asked on the APCS mailing list. The people there know the rules. But IIRC, for free response questions there aren't "forbidden but correct" constructs. I hope that is still true. But the student has, in fact failed both tests unless they get a hit on the first element. But I'm not a grader.  
> **username_2**: @username_1 I would not direct AP teachers away from this site; we have plenty of AP expertise here, I think.  And our format is *much* better than that mess of a mailing list for addressing such questions.  
> **username_1**: @BenI., I disagree for questions like this one. The advice given there for questions like this reflect official policy due to the folks that answer there.  
> **username_2**: @username_1 I mean, we're not the official college board site, though questioners here would presumably know that. AP teachers all have to sign up through the college board process, and register through AP Classroom.  But the listserver there is a morass, difficult to use, and practically unsearchable.  Answers here remain searchable, and can be fixed at any time.  

---

## 3 answers

### Answer by username_2 on 2022-03-26. Score: 2 | Accepted answer

I am also not an AP Grader, though I have taught the class for well over a decade now, and I am pretty sure about this would be approached on the actual AP test.

(If you pursue this further, and I do turn out to be wrong, please post a new answer with a correction.)

There are two considerations:

1. My understanding has been that every area of code is examined in isolation, and examined as if all of the code around it were good.
2. Furthermore, the first rubric point concerns itself with the loop, and the second point with the return. This is a philosophical separation in addition to the code separation I outlined above.

For both reasons, then, since the loop itself is fine, the student would receive that point. However, the student would lose the second point, since they are returning the wrong answer much of the time.

The reason for the separation of concerns in point 1 is because otherwise you get into sudden death scenarios where one small mistake brings you from 5 points on a large item to 0, since none of the items are ever actually fulfilled. Such scores are clearly out of line with the work produced by the students.

> **Comments:**
> **username_1**: Actually the loop doesn't access all necessary entries.  
> **username_2**: @username_1 Only if you neglect point 1 it doesn't.  If you begin to get overly technical with these rubric wordings, they stop working entirely.  Students can give outright incorrect answers to questions, but still get awarded every point on the rubric.  These all have to be taken in a spirit of intentionality, or they just stop making sense.  
> **username_0**: Thanks for sharing your experience. I like the idea that I can treat the points as separate concerns and award them accordingly.  
> **username_1**: What am I missing here? The method/function that contains this code returns after examining only one element. It clearly doesn't "access all necessary elements". The returns short circuit both the loop and the containing method. The student is clearly confused. I'd like to see what an official ruling would be. This seems clearly wrong to me.  
> **username_2**: @username_1 We can ask on the listserver. I would be surprised if it came out differently.  Separate the loop (basically just the declaration) from its contents. Each major component should be read as if the other code  around it was appropriate.  I believe that the rationale for this is that it avoids point cascades. Under the stricter reading you are using, for instance, the second point is always inaccessible if the first point is unearned, no matter what else the student does.  
> **username_5**: @BenI. But you have to treat a premature return or break or whatever as part of the loop declaration: `while(i<array.size)` is NOT equal to `while(i<array.size && !found)` . And I'd argue it's easier to construct code that makes the return part correct than the loop part. So I'd rather give credit for the second part depending what the focus should be, the actual return or the correct array access.  
> **username_2**: @username_5 I can see that way of thinking about it, too.  I'm not sure how the AP graders would come out on it specifically, though I am reasonably confident that one (and only one) of the two points would be awarded.  

---

### Answer by username_3 on 2022-05-11. Score: 2

I know this is coming a week after you wanted it... but, I am an APCS-A teacher and I have been a AP Reader in the past.

The scoring guidelines are applied thusly:

1. mistake in the code causes bounds error - Deduct the point for accessing array
2. having deducted a point, pretend the problem is fixed
3. continue scoring with fix

The goal is to not have a single issue rob a student of all the points.

The one exception is the "did they get it right" point. This would be the result of debate with your elbow partner, the table leader and the question leaders.

In your specific example the student would probably lose both points as the guideline is specifically mentioning a completed condition that was never reached.


---

### Answer by username_4 on 2022-03-28. Score: 0

I don't educate on the AP level, but let me trot out one or two of my hobby horses^W^W things that I try to teach my students.
One. I object to this code structure. Semantically, a loop serves to compute something, so you want a code structure
int your_result;
for (whatever) { do something }
return your_result.

By having the return in the loop you subvert this structure, conflating the loop and the surrounding function.
I try to prevent this sort of construct by showing how to derive code by textual refinement. You go from
// compute a result

to
result = compute_result()

to
function compute_result() {
    result = init;
    // do all tests
    return result;
}

to the full code. (This principle of textual refinement also postpones introducing local variables to the last moment, so they automatically are in the correct scope!)
Two. Loops that serve some test are (usually) either a for-all predicate or a there-is predicate. So, with the above structure, this is a there-exists problem:
bool element_is_present = false;
for ( elements )
  if ( condition )
     element_is_present = true;

and then you can jump out of the loop prematurely because a single true test is enough for the conclusion. And then refine this loop to suit the problem.

> **Comments:**
> **username_1**: I disagree, actually. See: https://cseducators.stackexchange.com/q/4427/1293. On the other hand, I write very short methods where it isn't an issue. I strive for [Cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity) = 1.  
> **username_4**: I see your point about minimizing mentally retained state. However, in my above distinction of eixsts/forall loops this presupposes that the student has already recognized that there is a exists problem, where indeed early return is possible. In this case, the question asks about accessing "all" elements so an early return is not possible and the whole code structure is wrong. So my second point stands that they need to start by analyzing the propositional status of the for loop.  
> **username_4**: Addressing your objections to my first point explicitly: I like deriving code by textual refinment. And your early returns are not amenable to such an approach. In fact, I find early returns kind of a hackerish solution with the main justification that "it works". How do *you* teach when early returns are possible and when not?  
> **username_4**: @username_1 Another thought: most programming language lack introspection so data is the only thing that is visible. With early returns you're teaching students a pattern that they need to process completely mentally, and the code is either all right or all wrong, with no visual indication as to the structure of that pattern. So I think you *are* overloading their mental capacities: they have to consider code paths entirely in their head. Whereas in my approach the code is clearly leveled, with each textual refinment having a clear function.  

---

