In the new Higher, parameter passing is part of the required knowledge including passing by value and by reference (as it was in the old Higher). However, Python doesn’t actually allow you to pass a variable in this way; what you pass is a reference to a variable (and that reference can only be passed by value). Then there are other issues such as mutability/immutability and functions that can return multiple variables etc., all of which are messing with the usual answers that appear in exam marking instructions.
So the question is: should Python be used as the programming language for Higher Computing?
I feel that Python is a great language and I know that many schools in my area are choosing it for N4/N5 and Higher, but teaching parameter passing (in the way the SQA want you to understand it) will be a bit of a nightmare with it.
I’m just going with if data is only input to the “procedure” and used they should see it as pass by value and if it is input/output or output at the return they should see it as pass by reference.
I’m seeing pupils getting the data flow much better with Python with the clear data arguments input and returns output.
I have been teaching that to pass by reference parameter needs to be a Python list. It works but is a bit abstract.
for x in range(len(my_list)):
my_list[x] = my_list[x] + 1
group = [10, 20, 30]
This should print:
Session 2013-2014 was my first year using Python – with N4/N5 and Higher. I really like it – so much easier to debug programs – and intend to continue using it with new Higher.
In the same way that implementation of an algorithm will vary depending on language choice, so will the implementation of data flow.
The new Higher arrangements do not include “passing by object”. As Python does neither passing by reference nor passing by value, as understood by the SQA, I taught it by looking at the *effect* on the passed parameter. As such, immutable types are “passed by value”, whereas lists appear to be passed by reference (as long as the list parameter is not reassigned in the function).
I’m not a Java programmer, but reading up suggests that Java has a similar problem. All parameters in Java are passed by value, but if the parameter is (pointer to) an object then it appears to be passed by reference.
One test of a language’s ability to pass by reference is “Can you write a subprogram that swaps the values of two parameters?”
Although Python does not have a CASE statement, I can still teach the concept. Similarly we can teach the concepts of parameter passing.
As the arrangements specify that pupils implement parameter passing by value and by reference, a quick visit to Visual BASIC might be in order.
Another Python problem is that the SQA define functions as returning a single value (using definition from BCS Glossary), whereas Python functions return multiple values.
A lot of programming languages cannot pass by reference, including some very popular languages such as Python. This does pose a problem if pupils are to implement both passing by reference and passing by value. Perhaps this needs to be raised with SQA.
Pointers in C and Java are examples of passing by reference, but actually using pointers is ‘frowned upon’ in programming circles and seen only as a last resort way to tackle a problem.
I have raised a similar issue with a HNC unit where pointers must be used in the implementation of a computer game. This immediately discounts the use of certain languages that do not have pointers, even though the languages may be widely used in industry.
I have been in contact with SQA on this issues and another regarding a procedure/function question (which those of us teaching python are going to have to rewrite). I agree that it is frustrating to have to teach pupils things that they can’t actually do in the language they are learning.
Back in November 2013 I asked…
I just wanted to query a few things about the new Higher Computing Science course…Neither Python or Java allow you to choose how parameters are passed…
One of the questions for the SDD unit assessment… asks pupils to explain why a parameter has been passed by val or ref. Questions like this will be impossible to ask in Python. I thought it might be better to clarify this now than next year when hundreds of teachers will face the same problem.
Then in February I asked…
I’ve just taken a look at the most recent version of the new Higher SDD unit assessment. I was pleased to see that the byref/byval question has been taken out… I can’t see a way of asking the following question in python since python only really has functions (unless we are using methods in object oriented programming).
(Question set 1 Q1b)Explain why the programmer chose to use a function rather than a procedure to calculate the bonus score?
This was the reply I got in February:
As with all of the Unit Assessment Support Packs (UASPs), these are suggestions for ways that centres could assess and you are always free to adapt these as appropriate to your own circumstances. In this specific example, where a given question doesn’t suit the programming language that you use, you can develop other questions that do – as long as the assessment standards are being met.
I wondered if anyone had adapted the questions in unit assessment pack 1 for Python and, if so, if they’d be willing to share?
Questions 1a, 1d and Sets 2 and 3 can be easily adapted for Python, however questions 1b and 1c are a problem since Python does not pass parameters by value/reference, and does not differentiate between functions and procedures.
I still intend to use Python for programming, but will use Visual BASIC to exemplify parameter passing, and teach them the SQA expected definitions of function/procedure.
Split Question Set 1 into two parts – 1a&d (converted to Python) and 1b&c (use the Visual Basic version)
Q1b is an exam type question that can be answered by rote learning:
*Functions return one value, procedures can return many values (Yes, I know this is not true for Python, but it what the SQA expect to hear, as in the sample pupil answers, and SQA exams 2011 & 2012)
*functions can be used inline, eg as part of an assignment, rather than being called as a separate line
Q1c can also be answered by rote learning
This is only a minor change to the assessment, so should not require prior assessment.
Schools teaching Java also have similar problems – there is no such thing as “pass-by-reference” in Java.
Schools teaching True BASIC have the opposite problem – True BASIC subroutine variable parameters are always passed by reference – it is the calling line that can fudge a parameter in to “pass by value”.
You must be logged in to reply to this topic.