Coding

With technology everywhere and growing around us, it surprises me that coding classes are not required for all younger kids. Take a browse through the App Store and you’ll see so many varieties, from all types of games to art pieces to drawing software to productivity helpers, and so much more. If kids learned to write programs earlier on, imagine the things they could produce when they’re older.

Sure there are programs like Unity that allow a non-programmer to create a game. There’s a learning curve to that too. I have always wanted to create an RPG like the old Final Fantasy games. I went through a first tutorial for Unity and it was tough to grab onto. (If you’re really interested in it, check out Groupon and LivingSocial because Unity sometimes does a promotion where their suite is offered for just $50.)

I remember programming the Commodore 64 back when I was in elementary school. Waaaay back at an early age. I still remember many of the things I was shown then. Remember LOGO? That triangle you could control onscreen? You make it go forward or backward, turn, lift the pen or put it down. You could only draw line shapes, but getting the program to do what you wanted was impressive. You also needed to learn about angles and planning your moves so you didn’t draw nonsense. The problem-solving behind it all is part of me.

I loved learning BASIC. I wrote programs with it all the time as a kid. They started simple:

10 INPUT “WHAT IS YOUR NAME?”;N$
20 INPUT “WHAT IS YOUR FAVORITE NUMBER?”;U
30 FOR X = 1 TO U
40 PRINT N$,
50 NEXT X

If your favorite number was 17 then this would print your name 17 times. There were shortcuts, like using ? for PRINT, and being able to just say NEXT (instead of NEXT X) unless there was a nested loop. You could also put a colon and have multiple commands on a single line. I used to like making things look nice onscreen, so I would add things like this line:

45 IF X/4 = INT(X/4) THEN PRINT

The original PRINT statement with the comma (line 40) separates the NAME with a tab (5 spaces) and it will keep doing that across the screen until the name wraps and continues on the line next. It often creates a neat diagonal display unless the name you input is a certain length. By adding line 45, after the fourth column of writing the name, it forces the computer to go to the beginning of the next line and start again, therefore lining up all the columns (unless you’re using a long name).

A form of BASIC programming is a great place for kids to start learning problem-solving skills. I would come up with my own challenges all the time. I remember in a high school computing class we had to make a Mad-Libs game. I wanted to make sure it was readable. I checked the word length of every word to be written on the screen by adding them one at a time to a string variable, with spaces between words. If it was more than 39 characters long, then it wouldn’t fit across the screen. The screen itself was 40 characters but I learned that printing to that 40th spot caused the next line to be skipped, therefore inserting breaks I didn’t want. So for each word that I was adding, I checked the length of the string and the length of the word, and if that was less than 38 (accommodating for a space in between words), then I added the new word to the string and used the READ/DATA or INPUT command to fetch the next word. If the string length would surpass 38 then that line was done. I could PRINT it and start the next string with the word that had hadn’t fit.

My point is that programming can be a lot of fun and once you get the knack of the basics, if you let yourself be a little creative, you can do interesting things.

One of my first “jobs” was creating a program that would keep a record of times for the girls track team. My seventh grade science teacher commissioned me to write it for her. It took me some time, especially because writing to a disc and reading from a disc was very intricate then, but I made a workable program. No idea if she actually used it, but she was one of those teachers who knew how to inspire her kids, as she did me.

So why don’t more schools have programming? I believe it should be mandatory, but should be taught in a more open, freeform manner. Not everyone needs to start with just printing their name to the screen, then having to wait for ten minutes while the teacher makes sure everyone has it. Talk about the basics first, then give a small program a try. While kids who figure it out move on, the teacher then helps the ones who are tripped up already. When I first learned BASIC, I bought a book about it because the class in school was too slow-paced.

Today, I’m trying to get into C#. Part of this is because Kevin codes in it all the time for work and play, and I’d like to be able to keep up with deeper conversations about it. If he talks about methods and classes, I want to understand what he means. (He doesn’t mean learning about acting!)

I recently took a free online course at Microsoft Virtual Academy (MVA) and I feel like I have a decent understanding of the basics. But my working knowledge is very limited so I need reference material while I’m working. The MVA videos are inconvenient (to say the least) when you’re trying see what a snippet of code is supposed to look like. What was the time stamp for that? Granted, there is a whole library of specific information on the Microsoft Developer Network (MSDN) website, so the written reference material actually is there for me. This is just one of those cases where I’m channeling the classic “old fogey” and I’m grumbling because it isn’t presented how I want to see it. For instance, the MVA lessons should have a page with links to the commands being used so I don’t have to get caught up in the video to recall what’s going on.

My biggest challenge right now is translating my old knowledge of BASIC into the new way of doing things. Off the top of my head, I can’t remember when I need to use certain tags, like “public,” or if I can just get to the keyword “string.” I also don’t know what things are already included in the .NET framework. In other words, do I have to create a method for finding the length of a string or is there an object modifier I can just use? (Yes, .Length, I’m looking at you.)

Here is my program from above converted to C# with my limited expertise. I imagine this could be optimized somewhere. I also didn’t invoke any method or class setups which could shorten the Q&A process that gets information from the user.

            string tab = ”     “; //one way of handling the tab

 

            Console.WriteLine(“What is your name?”);

            string name = Console.ReadLine();

 

            Console.WriteLine(“What is your favorite number?”);

            int number = Int32.Parse(Console.ReadLine());

 

            for (double i = 0; i < number; i++)

            {

                Console.Write(name + tab);

                if (((i + 1) / 4 % 1) == 0)

                    Console.WriteLine();

            }

            //Keep console window open to see results.

            Console.ReadLine();

Let’s break it down…

I didn’t know if there was a way to write onscreen with the tabs like the comma on the BASIC PRINT command, so I made a tab string that simulated the five spaces. I realize I could have just put Write(name + ”     “) instead. 

You’ll note the WriteLine and ReadLine methods for getting the name and number. Originally, I kept the string creation separate from the assignment ReadLine method, but then I remembered I could define the string “name” and also declare its value, in this case information typed by the user via ReadLine(). In other words, I originally wrote it like this:

            string name; 
            name = Console.ReadLine();

About the favorite number part… in BASIC, you put the dollar sign $ on a variable to denote that it was text and you left it off if it was a number. In the original program way up top, if you typed text for a number, like spelling out “four” for some reason, the computer would scold you for an invalid data type and it would ask you again until you gave it a number.

For ReadLine(), you can’t get a number back. It is set up only to give you a string. (I didn’t know that until I tried and the compiler scolded me.) So the whole Int32.Parse() method converts the ReadLine() information into a number and stores it as an integer called “number.” (I had to look up how to do that for this post, as it wasn’t in my working memory.)

The “for” loop is similar to the old one. By default it usually says “int i” not “double i” but I’ll get back to that. That line says to start a loop counting from zero, up to the selected “number”, counting by one (i++ adds 1 to the value of i each turn in the loop).

To keep with the added-on line 45 from my BASIC example, I wanted to only have four columns. I had to look up how to do that, and using the mod command (think: find the remainder) seemed the easiest way to go. In BASIC I checked to see if dividing the counter by four was equal to diving the counter by four while cutting off any decimal. The INT command in BASIC just snips the decimal off with no rounding. So if the division goes in evenly then there is no decimal and therefore it is a multiple of four.

For C# the mod command (%) does the opposite of BASIC’s INTeger. It only keeps the decimal. So I still do the division but this time I check to see if there is no decimal. It’s a different thought process than what I’m used to. That double equals sign == is asking the computer to see if the mod calculation is equal to zero. It returns either a True or a False. If it’s true, then the WriteLine() command kicks in and forces the next Write() command to start on the next line. Incidentally, because i starts at zero, the first iteration would cause the WriteLine command to kick in, so I added the (i + 1) to fix that during the mod command. This was something I didn’t consider until I ran the program.

The final ReadLine command is just to keep the window open onscreen so we can see the results. It doesn’t need to be there otherwise.

C# Result – Code Sample

So comparing the two sets of code, I completed the same task, but it took me more command lines in C# than in BASIC. Again, I’m sure this could be optimized some, but I’m just glad I was able to take an old type of example and bring it into the new type here.

It’s going to take work before I’m ready to sit and code on my own without feeling like I’m a total neophyte. But there are some things I’d like to do, like making that Red Jade game, and getting them done through the computer is the way to go.

So I went off topic here but the crux of it is this… I was shown computing language when I was in elementary school and had other classes where we used it in middle school and high school. Technology is advancing, not degrading. Kids today need to get involved with this line of thinking and get their hands on coding experience. Sure, they may never do anything with it, but I feel it’s a vital skill they need to see. Even just the problem-solving practice would benefit us all.

Leave a Reply

Your email address will not be published. Required fields are marked *