Thursday, August 26, 2021

IntelliCode Completion In Visual Studio (Preview) 2022

There is a preview out for Visual Studio 2022 available and since I a) love to try new things and b) am not limited to by what is on the student computers I have been trying it out. Normally, I don’t see a lot in new versions of Visual Studio that impact me personally or me as a teacher. That is not the case with this new version of VS. The new feature is called IntelliCode Completion. (you can read more about it here)

Basically what it does is try to help you write code faster and with less typing.

IntelliCode now predicts the next chunk of code based on your current context, and presents it as an inline suggestion to the right of your cursor. If you like it, just hit tab-tab to accept it; otherwise simply keep on typing to adjust the completion further.

Take the following code for example. I have a string array declared. In my btnGet_Click method I typed “foreach (“ and Visual Studio showed my the code in gray as a guess of what I wanted to write. In this case, it was right and by hitting the tab key the code was in place. Continuing to type would have replaces the suggestion.

For me this has been awesome. It's helped me start all sorts of loops and even helped build Boolean expressions. What does it mean for the classroom and beginners? That is the big question for teachers.

I know that teachers are divided on Intellisence which helps with understanding and suggestions with variables and methods. I suspect that if you don’t want your students using that sort of predictive information you’re going to really hate IntelliCode. Even if you like Intellisence, as I do, you may have concerns about IntelliCode. I admit to having some concern myself.

My first impression was that it could prevent a lot of typos and badly formed code. It does have that potential. On the other hand, will students put too much faith in the AI and assume code it suggests is correct for their particular program? That could be a big problem. I have had students blame to tools for their own mistakes for years.

Teachers can use this for a good discussion of artificial intelligence. What do you think of the information was used to train the AI? (Spoiler – lots of code in GitHub) How well does the AI really understand the context of a specific student project?

Clearly, students need to be prepared for using this feature. Students need to know that it is not prefect and that they need to be careful what suggestions they accept.

It does look like this feature can be turned off by specific area of help. Maybe there will be a way to turn it completely off easily on release. It’s on by default right now. So what do you think? A helpful feature for beginners or more potential for harm than help?

Monday, August 23, 2021

Hexapawn–An Interesting Programming Project

I'm cleaning up and finding interesting things. Well, actually, interesting books. One find is called "A Collection of Programming Problems and Techniques." Copyright 1972  So obviously, continued cleaning up is on pause while I code up solutions to some of the problems.

One of the problems in the book is Hexapawn (Hexapawn on Wikipedia) I remember this being a sort of challenge program when I was an undergraduate student. I didn’t take it on back then and forgot about it until running into it the other day.

I decided to take this on. I think it will be a good project for students. As did my old professor.

Hexapawn is played on a grid, often a 3 by 3 grid, with “pawns” on the top and bottom rows. Pawns, as in Chess, can move one square forward or diagonally right or diagonally left to capture pieces belonging to the other player.


A player wins by advancing their pawn to the opposite side of the grid or by preventing the other team from making a legal move.

It’s a simple game to play but takes some work to program.

One of the issues is that there are some tricky edge cases to be aware of. While pawns in the center column need to check for three possible moves, pawns in the left and right columns only have two possible moves. That can be a lot of special casing. It gets even worse if one uses larger boards. Trying to check for a move to the left for the left most pawn will create an error in many cases.

Years ago I ran into a boundary condition like this and a member of my team made a suggestion that I have used many times since. She suggested boxes outside the visible grid that, along with not showing, were marked as illegal moves. This means that one can check for straight, left, and right moves for all pawns without getting a subscript out of range error.

An other project I have used this technique is with the lights out game. In that game there are four squares that have to be checked in interior squares, three for edge squares, and only two for corner squares.

Using an outline of invisible squares outside the main set of squares allows the same code to be used for all squares.

I wrote a bit about the Lights Out project some years ago at The Complex Question of Complexity in Programming by the way.

I’m not quite done with my Hexapawn project but I am really understanding how it makes for a good programming project. One can set student requirements low or high. One can assign a two player game or ask students to write an artificial intelligence to play against a computer. It’s a game that lends itself to creating a heuristic program (think machine learning) for more advanced students. Low floor, high ceiling.

Friday, August 20, 2021

Playing With Code–Recursion

Recursion was never a big part of my toolbox but I am starting to appreciate it more recently. Regular readers know that I have been writing about and writing code for some older, simpler cryptography systems. For one of them I needed a list of letter in the alphabet without duplicating previous letters.

I needed to take a letter from the alphabet (I had a string of it) and see if it was in a list of used letters. If the letter was used already I wanted to check the next letter. It’s pretty straight forward if you can assume that not two letters in a row are used in the previous string. There is probably a decent iterative way to do this but I was coming up blank. Until it occurred to me that a recursive solution might be just what I needed.

I came up with the following code. It checks of the letter at location k in the alphabet list is in the string to check. If it has not been used it returns the index of the letter to use. If it has been use the same function is called again looking at the next letter index. This continues until we find an unused letter.

private int getNext(int k, string check)
     if (check.IndexOf(alpha.Substring(k, 1)) < 0)
         return k;
         return getNext(k + 1, check);

I really like this solution because it emulates the way I think about the task. It’s also easy to understand. Recursion is not always hard and confusing. Sometimes it really makes things easier.

Program note: The nice people at Feedspot have compiled a Top 20 Computer Science Blogs list. Yes, I made the list but there are a lot of very good blogs on that list. They cover computer science more broadly and many will be worth a follow.

In cryptography news, the NSA Codebreaker Challenge 2021 is now open.

While you are here, I have been regularly updating my Tiny Book of Simple Cryptography. The current list includes:

Caesar Cipher
Vigenère cipher
One Time Pad
Polybius Square
PigPen Cipher
Columnar Transposition Cipher
Keyword Columnar Transposition Cipher
Random Block Transposition Cipher
Bacon’s Cipher

Monday, August 02, 2021

IoT, Python, and Raspberry Pi–Oh My

Trying learn too many things can be a risky proposition. But sometimes it feels like the way to go. Regular readers of this blog know that I have been trying to learn Python and that I have been experimenting with the Internet of Things with Phidget devices. Mixing the two is a pretty obvious step but since I really want to set up some autonomous systems without tying down my laptop, it seems like the Raspberry Pis I have accumulated would be the way to go. So mixing a new programming language (Python), with a new development domain (IoT) with a new operating system (the Raspberry Pi OS is built on Linux) seemed like something I should give a try.

Fortunately for me, the Raspberry Pi OS installation comes with the Thonny, Python IDE for beginners and the Phidgets software has downloads and installation instructions for the Pi and Thonny. I had a little trouble getting the Phidgets library to install at first but the Thonny IDE had the ability to get the library and install it for me which was a big help.

Thonny feels like a very nice IDE for beginners BTW. I am surprised I hadn’t already known about it. It installs in Windows, Mac OS, and Linux. And it is free which is also nice. Visual Studio Code also installs on Raspberry Pi so if you are using that on other platforms it could be an easy move on the Pi.

My experiment involved using the Phidget Plant Kit because water and electronics go so well together. Seriously though I like the idea of having a computer controlled watering system for plants. That’s something I have wanted to do for a while. Plus it is something that lends itself to cross curricula work in schools.

Initially I plugged in a monitor, mouse, and keyboard. Not a bad desktop if a little slower than I am used to but fine for what I am needing. Next step was connecting over the network with VNC (Virtual Network Computing). This is the step I need for setting the Pi up without tying up my monitor, keyboard, and mouse.

Well, I have some more experimenting to do. More posts when I have some projects fully completed.  I’d love to hear what other people are doing with Raspberry Pi and IoT as well as where you like to go for connectable hardware.