Friday, January 15, 2021

Comments on Commenting Code

Comments sometimes seem to be a hot button for software developers. Opinions range from the manager I had who actually did want a comment on every line of code to the people who think comments are completely unnecessary. I tend to fall somewhere in the middle as I think most people are. We may draw the line differently but most people think there is a sweet spot for how many comments are a good idea.

Some people don’t see the value in comments. They believe that code should be self documenting. The variables and functions should have descriptive names for example. To some extent that is a valid goal. Code should be understandable by itself. That’s not always as easy as it seems. When we write code we do so with some specific, obvious to us at the time, information. This might not be the case for others who come to the code later. Or even to the original programmer after some time has passed.

When I talk to students about comments I often relate an experience of my own. I wrote a really cool (in my opinion) program while I was a university student. It drew pictures on a drum plotter. Pictures took about a half hour to draw on that device. Some years ago, decades after I wrote the original program, I decided to write the program again for a modern display device. I wrote the program, compiled it, and ran it. It didn’t look right at all. I stared at the screen and thought “that looks familiar. I think I made that mistake the first time.” Now it turns out that I still had the punch card deck (yeah, I’m that old) and could read through the original program. I came across a comment that read “this function takes degrees in radian” Ah, ha! That is what I got wrong both times. I simple fix and my program worked as I wanted.

Clearly writing comments, especially that one, paid off big time.

Something that took a while to figure out should always be commented in my opinion.

When ever the subject of comments come up someone brings up the case where code changes mean that comments do not match the code. There is no doubt that this happens but frankly I have no sympathy for the situation. A serious professional should be mindful of details like that in their code. When the code and comments do not match it means someone was in too much of a hurry to do a complete job.

Comments should document difficult things, non-obvious things (parameter lists to called methods are a good example, and anything that required some involved logic.

Student projects in a first programming course often don’t have the sort of complexity that a larger professional program might have so it is hard to get students to comment code. I always insisted on a complete header of comments at least. And a comment that describes the purpose of each method written. As I think on it today, I wish I had produced some larger piece of well commented code to have students read.

How do you feel about comments in code? And how do you communicate it to students? Please share some ideas in the comments.

Monday, January 11, 2021

Early Registration Open for the CSTA Annual Conference

Just registered for the 2021 CSTA Annual Conference Early discounted registration for CSTA+ members is now open https://web.cvent.com/event/354be991-0b98-48e0-b4d3-0e32b72a6e49/summary

If you are a CSTA+ member you should have the email.. If you’re not a CSTA+ member maybe you should think about becoming one!

I think its going to be a great conference. We learned a lot from last years conference on many levels.

Saturday, January 02, 2021

Recursion–How and When to Teach

I’ll start with a confession. Recursion is one of those concepts that I struggled to understand in the beginning. Was it me or was it how it was taught? An open question that I don’t want to look for blame. A recent article by  Shriram Krishnamurthi, CS Professor at Brown University, called How Not to Teach Recursion suggests that maybe I was taught badly and worse still that I taught it badly.

Adam Michlin wrote an interesting, related, post called Why you shouldn’t teach recursion (yet)

The teaching of recursion is one of those topics that really gets people talking. I hope thinking as well. Certainly I have been thinking about it lately.

Teaching it early, teach it late (as Adam suggests), not teach it at all? All question people ask and answer differently.

My key takeaway is that recursion has to be the natural solution to a problem for it to really make sense to students. Navigating a tree structure, file directories for example. This implies a prior understanding of the related data structure is also required.

Some languages and teachers use recursion for iteration. I guess for some that feels natural but it never has for me. Perhaps I am to old school and too deep into for statements and while loops. When I started programming there were languages that didn’t support recursion at all!

I have had several students discover recursion (and stack overflows) by having the main function call itself. Very instructive.

I’ve been programming for about 48 years now and very seldom have I had a real need to use recursion. By need, I mean that was the bests and only way to code a solution. One time I wrote a really cool recursive method which I was writing code for a living. Upon code review the rest of the team made me rewrite it as an iterative method because they decided it was too complicated and no one else wanted to try to debug it some day. Most of the teach was fairly young and were recent graduates from top CS universities too!

How important is recursion really? The AP CS A exam tests it lightly in the multiple choice questions (as I understand it). The AP CS Principles didn’t test it at all. SO if you are basing decisions on those exams (which is a whole other problem IMHO) its not that important. Do an advanced data structures course on the other hand it is probably fairly important.

If you are teaching it though I think the important things are outlined in Shriram ‘s article. The popular examples are problematic at best. From the post:

Where does recursion come from? HTDP argues that it arises from self-references in data. That is, recursive data suggest recursive solutions. This is the key insight you need for understanding recursion. Not only does it make sense once you think about it, it also demonstrates why most other approaches to teaching recursion are essentially incorrect.

But do read Shriram’s article. He explains it much better than I can.

[Edit: Mike Zamansky gives some thoughts on teaching recursion at On Teaching Recursion
Worth the read. ]

[Edit: Michele Lombardi gives here thoughts at Chiming in on Recursion

Friday, January 01, 2021

Looking Forward to 2021 in CS Education

What a strange year it has been. The pandemic and more took a lot of the steam out of what I had hoped to dig deeply into in 2020. Surviving is success in these times I guess. I taught online for the winter/spring semester of 2020 and then retired. Teaching online was not so bad but it didn’t leave me with much time to improve on things. Running as fast as possible to stay in the same place seems to have been the norm for most teachers.

But this is time to look forward not back. One thing that seems to have grown among the teachers I see on social media is cybersecurity. While we have seen cyber security at the CSTA conference the last several years is feels like 2020 was the year teachers started teaching it in larger numbers. I think that is only going to continue.

I see a lot of teachers looking for new courses that are relevant to students and cybersecurity certainly counts as that. We can also fit more of it into other CS courses. Students love it. Well, mostly.

CYBER.ORG (formerly NICERC) is one of several organizations supplying curriculum and professional development. And it is all free.I love that team.  Teach Cyber  is  another group as is TryHackMe There is a pretty active Cybersecurity Educators group on Facebook where a lot of teachers are sharing ideas and resources. I highly recommend that group.

Other than cybersecurity what am I looking to see more of in 2021? Well, online IDEs which really came into their own in 2020 are going to only get better. We’ll probably see more competition there as well. In fact, any option for teaching online will see growth even if, as we all hope, schools all return to in-person learning. Giving access to students outside of computer labs is just too powerful a tool to avoid.

I expect computer science, indeed most, conferences to retain a virtual component in 2021. Will they be mixed with both in-person and virtual aspects? I’m not sure but I see more and more conferences having the ability for people to attend virtually. The cost of that is coming down for the conferences and the ability of teachers to spend money for airfare and hotels is not growing as fast as the need for more teachers. There is also a growing interest in reducing carbon footprints on that part of many people.

Computer science education research has been gaining traction in universities. That’s pretty exciting to me as I think there is still a lot we can learn about how to teach CS more effectively. I am hoping that learning about the results of this research will be more available to teachers as well. We can’t all go to conferences or afford expensive peer reviewed journals. The real value of CS Ed research is getting the knowledge to actual teachers.

I see reason to be optimistic about CS education in 2021. We made it through 2020 and it is all going to get better. I can’t wait to see what happens!