UoPeople Week 5

UoPeople – Term 2: Week 5

Hello again! Yesterday was theĀ beginning of week 5 for my second term at UoPeople. Regretfully I have not been keeping up with my blog as consistently as I would like. For those who have found my posts enjoyable and interesting, I apologize.

I stated in my last update that this term has not been very challenging to me, but last week it changed. I had no issues completing my assignments or anything like that, but I was just challenged to make sure I really understood a couple concepts very well. I chose to write about those challenges in my learning journal assignment last week so I’ve decided to share that assignment with you guys here.

Here it is.


 

This week there were a couple of interesting things that came up. The first was understanding the scope of parameters in Python, and the second was understanding recursion.

In the discussion forum, it was brought up by another student that arguments to a function are passed by reference not value. In programming passing by reference means that the new variable name for the object points to the same location in memory as the original object. This means that if I change the value of the new variable name, it also changes the value of the original one too.

The student suggested that this implies the parameters of a function in Python are in fact global, contradicting not only the readings from Chapter 3 in Think Python: How to Think Like a Computer Scientist, but also the Python documentation. Although the conclusion that parameters are global is incorrect, the fact that they are passed by reference is not necessarily inaccurate.

The claim lead me to research the proper answer and it seems to me that there is a misunderstanding of what it means for a variable to be local. Even when a variable, or object in Python is passed to a function as reference, this does not make the variable in that argument global nor does it make the parameter so. Global implies that the name of the variable can be accessed from any other code block in the program.

In Python I could make a mutable object such as a list, and call it myList. If myList is defined inside of a function called function1, I can not access it from another function without passing it as an argument. This is what being local means. Even though passing myList to another function called function2 means passing by reference and can result in any changes made by function2 to change the value of myList in function1, it does not mean myList is global. myList can’t be accessed from any other place in the program other than function1 without the use of parameters.

In other words, the memory location that a particular variable name points to, does not define its scope. Its scope relates to how and where the variable can be referred to.

I think it’s also important to understand that a parameter in a function represents a new name for the argument that gets passed to it. That name can’t be accessed from anywhere else, other than inside the function where it is created.

The next interesting thing this week was learning about recursion. In question 8 of the self quiz there was a bit of code that used a recursive function. At first I really didn’t understand it, and it’s been something I’ve chose not to use very much in my own code. After reading a few tutorials online I was able to wrap my head around it, and understand what was happening in the code included in question 8. I then was able to alter the code to successfully output the recursion depth, by changing the “while” loop to an “if-else” clause and adding a return value to both conditions.

After learning more about recursion I’ve discovered that many iterative algorithms I’ve used in the past can be greatly optimized by using recursive algorithms instead. It’s definitely a new avenue of discovery for me and I plan on exploring it further, by considering the efficiency of a recursive function before using an iterative one.

In conclusion to this unit, I think it’s the first time in this course were I was challenged to understand something related to programming. I really had to do my research for my assessment post in the discussion forum, to explain my opinion. I also had to spend some time understanding recursion (something I’ve neglected in the past) well enough to modify the code in a way that works as I intend, rather than just memorizing the answer in the self quiz.


That learning journal submission sums up my last week very well. This week in class I’ve already finished my programming assignment assessments, and my discussion assignment assignment. I’m definitely off to a good start this week for my own studies.

One new thing I started doing today is helping another student from school with her CS1102 class. It’s called Programming 1 and is one class ahead of what I’m learning now. I started by trying to help over text messages through Yammer, but today we used Skype.
Skype is a much better way to teach someone, as it allows me to draw stuff out on my black board. It also challenges my knowledge more, because I can’t just google her questions. I definitely look forward to doing more lessons, as it gives me the opportunity to really understand concepts that I’ve previously learned at a much deeper level. It also provides the student with an opportunity to learn in a one-on-one environment, so it’s a win-win relationship šŸ™‚

 

That’s it for now.

 

Cheers,

 

Dan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.