Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

March, 2006

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    New Computer Science Education Blog at On10

    • 8 Comments

    Kevin Schofield has opened up the discussion about computer science education at On10.NET with a new Education blog. His first post there asks about the kinds of information teachers and others interested in promoting CS education need to have on hand to make the case to students, guidance counselors and parents. He is particularly interested in how to get the right message to guidance counselors who seem to all too often tell students to go into anything but computer science. Jump on over and join the conversation.

    BTW I see that the CSTA blog is taking up one of my favorite causes "Computer Science for all Students?" The thoughts expressd there are quite in harmony with Kevin's statments and questions at On10.net.

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Visual Studio Hints and Tips #3 - Visual Studo Class Designer

    • 5 Comments

    One of the really exciting new features of Visual Studio 2005 is the Class Designer. The Class Designer allows the programmer to quickly and easily set up the basic structure of a new class using a graphical interface. Using the Class Designer you name fields, properties, methods and events that make up a class. Fo each item you can specify the data types and parameters involved. The code will be created automatically. Not only that but if you add code in the code window and add, for example, a new field it will show up in the Class Designer window automatically.

    To use the Class Designer select a class from from the Solution Explorer or from the Class View window and click on the View Class Diagram icon  from the icon menu. You can also right click on a class and select iew Class Diagram from the drop down menu. When you open the Class Designer you will open the Class Diagram from and the Class Details form (at the bottom of the IDE). Click on add method, add property, add field or add event to add an item to your class. Type in a new name and then add values for the type, modifier and summary information which will show up in the comments. Click on the plus sign next to a named item to open up a new line for parameters.

    It's all really easy to use but easier to show than to describe. For that reason I have created a 7 and a half minute demo of this on the MainFunction website that you can watch if you'd like.

    This and the previous entries in this series may be found in one place at this article.

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Show Me the Money - Floating Point Numbers and Accuracy

    • 4 Comments

    Floating point numbers have some accuracy problems. The reason for this is because of fractions that covert to repeating values. Most students understand that 1/3 translates to .3333333 in an infinite sequence. But not many of them know, until it bits them, that in the binary system used by computers 1/10 is a repeating fraction.

     

    This really shows up in comparisons. Take a look at the following code:

    For y as Double = 1 to 2 Step 0.01

    That is an infinite loop because y will never equal 2. You’ll have to use a while or do until loop and use a greater than or equal ( >= ) operator to make it work. This is the kind of thing that makes using double or floating point numbers in loops a generally bad idea.

    There have been a number of different ways that have been used to handle the round off problems caused my binary repeating fractions. Years ago Perkin-Elmer (a company better known for other things) had a computer that used a "sticky bit" to help round both up and down which resulted in much more accurate numbers. That was done in hardware floating point operations.

     

    While keeping track of large numbers of decimal places is important in science, in business it is all about the pennies. And pennies can be hard to track as well.

     

    In programming languages, DIBOL (the "B" stands for "Business") didn't support floating point numbers at all. Programmers used integers and had to keep track of where the decimal point was supposed to be. It was accurate to quite a few digits as I recall. You paid for that accuracy with performance and with requiring smarter programmers.

    COBOL had a decimal type for money operations as was mentioned. Other languages and platforms still do. The .NET Framework (and all of the languages - VB, C#, etc - that run under it) have a Decimal data type which gets special processing to not lose those pennies. For performance reasons you don't want to use them for non-money operations as a general rule.

     

    I used to use a change making program assignment (for x dollar amount break it down to pennies, nickels, dimes, etc) to help students see the difficulties involved in handling round-off errors. I assume that is fairly common. If you have them do it once with doubles and then let them do it again with decimals it can be an eye opener especially if you have a class discussion about why the difference.

     

    BTW banks still worry about lost fractions of a penny. A program manager from a large New York bank told me about a programmer who looked for transactions that resulted in fractions of a penny and rerouted those fractions to his account. Even small numbers add up if you add them billions of times. The programmer ran off with millions after a few months. I believe they did catch him though.

Page 1 of 11 (31 items) 12345»