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

September, 2008

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Binary Number Game


    I love binary numbers. I was first taught about different number systems in grade school and was fascinated with them immediately. I used to convert decimal numbers into different base numbers just for the fun of it.  So I guess it is not surprising that I love computer projects that involve binary, hex, and octal numbers.

    I recently found this binary teaching game on a Cisco web site. The music is annoying but that could be my age. If you use it you may want to make sure the students turn off the music or your lab will be really noisy.

    But while playing games is fun I’m a “let me make my own game” sort of guy. So when I saw this program my first thought was how can I make that into a project. So while sitting through a conference call I started playing. I came up with the following (in Visual Basic .NET FWIW but I’m not sure language choice is a big deal here.):


    The way it works is that by clicking on a button one toggles the zero and one values and changes the decimal value that is displayed. It’s a pretty simple program. One could add some complexity by allowing a user to enter a decimal value and have the buttons change to represent the binary equivalent. One could also modify this to handle other number bases. One could either have multiple clicks of a button increment (and wrap) the value displayed or one could use text boxes to allow a user to enter a value. There are pros and cons to either option.

    The button option forces students to understand the counting in different number bases which is valuable. The text box option forces a student to do data validation and error checking. That’s a whole different but potentially more valuable lesson. It all depends on the goal of the project.

    What do you think? Will these ideas work in the classroom? How would you change them?

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Alfred VS Clint: C# versus VB debate


    Clint Rutkas (who is better than everyone) Twittered his distaste for Visual Basic and preference for C# today. Now C# is a great language and I really do think that the features they borrowed from Visual Basic (properties for example) make it the best of the C family of languages. Visual Basic also had edit and continue for years and years before C# developers were able to convince the Visual Studio that they wanted it too. But to me C# not as clean as Visual Basic. So of course I responded right away. This lead to an Instant Message conversation and discussion of a nerd off. So here now is my defense of Visual Basic. Clint’s opening statements are on his blog here.

    I have never been a fan of C style languages. To me the use of the semi-colon and curly braces are crutches for the compiler writers and hindrances for programmers. If we were going to go that way we could have stayed with APL – a very powerful language but confusing for programmers. And they are ugly and confusing too!

    The required semi colon is particularly a problem. How many times have programmers, especially but not exclusively beginners, terminated a loop accidentally by placing an extra, and hard to see, semi-colon at the end of a line? And a missing or misplaced closing brace is a lot harder to find than a missing End If. Contrary to Clint’s claims I maintain that the code samples he shows prove that VB is easier to read.

    And then these is white space. In Visual Basic white space means something and enforces some organization of statements. You don’t see contests to see who can write the least understandable Visual Basic code as you do for C (and could do in C#). Just because it was hard to write doesn’t mean it should be hard to understand.

    Oh and did I mention the My classes? Not strictly a language feature but they do make it very easy to do some powerful tasks in Visual Basic programs.

    Note: See also Line Continuation and Visual Basic – More on C# vs. Visual Basic and Visual Basic .NET and C# Side By Side

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Line Continuation and Visual Basic – More on C# vs. Visual Basic


    Clint has more on our Visual Basic vs. C# discussion on his blog today. Like Clint I am completely willing to let people choice the language of choice based on personal preference. One of the really great things about the .NET platform is how easily this is possible even when people on the same project choose different languages. And I do have a great deal of respect for C# and especially the people who designed it. I have a great deal of respect for Clint as well. But I still like Visual Basic better.

    In his more recent post Clint takes on the line continuation character which is needed in Visual Basic for breaking a statement across multiple lines. I was tempted to just say “any statement that is too long for one line should be broken up into multiple statements” but that would be both too simplistic and unfair. Many statements just make more sense as one long statement and for readability breaking them across multiple lives can be a good idea. I just thank the stars that we are not limited to 80 character punch cards anymore. And so it may be that coming from a background that includes FORTRAN and other punch card programming I do not find a line continuation character much of a strain. I also think that it helps for internal documentation. It makes it much less likely, in my opinion, that extra code will be inadvertently inserted in the middle of a statement. Or that a multiple line statement will get inadvertently cut in the middle during a cut/paste operation.

    And of course needing a line continuation character is an exceptional case with most statements fitting on one line nicely. At least I don’t need a semi-colon at the end of every statement so that the compiler doesn’t get confused.

    Some additional good news is that the Visual Basic team is actually thinking about changing this for the next version of Visual Basic. Here in a blog post Paul Vick from the VB team talks about the issues and the possibilities. Will this happen? Hard to say but I think it would be great if it did.

    I should address some of the comments on Clint’s last post while I’m at it. One commenter points out that in C# and other C family languages one can write something like:

    if (condition) { dostuff }

    and asks “try that in Visual Basic.” So I did. The following one line statement works just fine.

    If (condition) Then dostuff()

    in fact this line

    If (condition) Then dostuff() : dostuff()  ‘ Did you know you could have multiple statements on a line with Visual Basic?

    works the same as

    if (condition) { dostuff(); dostuff(); }

    Except of course in the C# version we have to remember the semi-colon after each call to dostuff (I created methods so I could be sure stuff compiled) and we use the key word “then” and the new statement coming colon on the VB code.

    Another comment says that one thing programming languages should not be is verbose. Well verbosity may be in the eye of the beholder. As someone who used to do a bunch of programming in COBOL, Visual Basic seems down  right terse at times. But more to the point, brevity has its place but too much brevity can lead to confusion. There are reasons we eschew single character variables for most things after all. The right answer is a balance and I think Visual Basic has a good balance.

    Note: See Visual Basic .NET and C# Side By Side for a look at some of the syntax of both.

Page 1 of 8 (22 items) 12345»