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

September, 2010

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    How Many Letters Are There in The Alphabet?

    • 0 Comments

    You saw the title and a single number came to mind. If you are English speaking your probably thought “26.” If your native language is not English you may have thought of other numbers though. Even in European languages there are letters such as é è ö ᴂ å ø. And that is just the start. So what does this mean to a programmer or a web developer? Well it means you have to be pretty careful if you are writing code to validate that only letters have been entered into a field. I recently read a series of email messages by someone who could not enter their name in a form because it included the letter “ö .“ That is a frustrating thing to happen. And honestly asking them to change the “ö”  to an “o” is at best culturally insensitive and more likely outright insulting. So what is a programmer to do?

    A typical, old school answer to looking for a non-letter in a string might look something like this Visual Basic code.

    Dim t As String = TextBox1.Text.ToUpper()
     
    For i As Integer = 0 To t.Length - 1
        If t.Substring(i, 1) < "A" Or t.Substring(i, 1) > "Z" Then
            MessageBox.Show("Alphabetic characters required")
            Exit For
        End If
    Next

    Looks good but if you test it you will find that all of those non-English characters that are letters are reported as not alphabetic. Not good.

    Well often the best way is to rely on system/language functions to do it for you. One has to do their homework though to make sure those functions will do what you want though. I tried this C# code and it didn’t work. You'd probably not expect it to work if you are thinking about international letters because those other letters are outside the range of “A” to “Z” in most encodings. If you are not thinking about international letter this may feel right  though. A reminder that testing is important.

    {
        if (t.Substring(i, 1).CompareTo("A") == -1 | t.Substring(i, 1).CompareTo("Z") == 1)
        {
            MessageBox.Show("Alphabetic characters required");
            break;
        }
    }

    Then I tried the IsLetter method in the Char object as follows and it works.

    string t = textBox1.Text.ToUpper();
     
    for (int i = 0; i < t.Length; i++)
    {
        if (!Char.IsLetter(t,i))
        {
            MessageBox.Show("Alphabetic characters required");
            break;
        }
    }

    This works because the IsLetter method understands what “a letter” is. Reading the documentation was pretty helpful here. This reminds me of one of my favorite things to say to students – reading the documentation is the shortcut!

    There is not typically a lot of room in most high school CS curriculum of course but I think there is room to talk about it in context from time to time. It’s important that students start thinking about this early.

    Oh one last tidbit from the recent email conversation I read – some people don’t have first and last names. They just have one name. Forms that require entering both a first and last name are problematic for them as you can imagine. Solving that problem may be a little more complicated. It’s something to start a conversation about though.



  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Objects When? If Ever?

    • 2 Comments

    This post started as a comment on Mark Guzdial’s blog (Moti asks: Objects Never? Well, Hardly Ever!) but I decided to elaborate some. I think this is an important discussion to have both in education and in industry. Mark’s post was inspired by an article by Moti Ben-Ari Objects Never? Well, Hardly Ever! | September 2010 | Communications of the ACM. (That is premium content so if you are not an ACM member it will not be fully visible – sorry about that) The key comment from the article is probably:

    I claim that the use of OOP is not as prevalent as most people believe, that it is not as successful as its proponents claim, and, therefore, that its central place in the CS curriculum is not justified.

    In computer science education today it is taken pretty much as an article of faith that object oriented design is THE design paradigm to teach. The only debate most of the time is when in the curriculum to introduce it. It took me a while to grok OOP. I'm old school and remember the move to structured programming in the early 70s. There was a lot of discussion back them about having to bend designs to make them fit the “new” structured methodology. Programming  languages changed to reduce that problem but the "go to is bad" argument still remains - albeit somewhat underground. :-) But by and large the benefits were obvious enough that structured programming "won. We got a lot of good things from this change. Loops became more powerful and flexible for example. Design got easier and program maintenance got much easier.

    Some say that OOP is the next step but I'm not so sure. I think it is an additional step that can co-exist with other paradigms. Proponents want to replace other ways of designing software and that is where the object first or objects later debate comes in. There is a third way that is to use objects in parallel. This argument that gets lost in the shuffle though. That is the school of thought I find myself in.

    The way I see it objects fit into more traditional programs and make some things easier. Making everything an object often adds unnecessary and even unhelpful complexity to what can be simple designs. One only has to look at "hello world" written as an OOP program, say in Java. Compare that with the same in old languages like BASIC or even dynamic languages like Python. I don’t see why objects can’t be used with great efficiency when appropriate in a more traditionally designed program but always and for everything? Not so sure about that.

    The problem as I see it is that objects are great tools for what they are good at but poor tools for many other things. Everything doesn’t have to be an object. Not every target in carpentry is a nail and so you need other tools than hammers. Programmers should be about having a full toolbox and not a limited one. To many people this means knowing multiple programing languages and I agree with that. I also think that programmers should be comfortable with multiple paradigms. That means functional programming as well as procedural or object oriented. It means that people should be able to use multiple tools (languages and paradigms) in the same over all project. Why not use F#( a functional language) along with C# and Visual Basic and maybe even Iron Python (a dynamic language) in the same project? Use the right tool a the right time. (This is easy with Microsoft’s .NET framework and Visual Studio of course. I’m not sure how easy it is in other tools and platforms.)

    Anyway I am tired of language wars. You may want to read Old Geeks Never Die, They Just Get Grumpier on the Blog@CACM to better understand that point of view.



  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Students And Intellectual Property Rights

    • 2 Comments

    Earlier this week a friend sent me a couple of links to articles on intellectual property and students. One was about piracy (Future Tense: Piracy Revisited) and it consists of an author explaining how “getting stuff for free” can be stealing. This article mirrors very closely conversations I had with students over the years. It doesn’t often go well. Very often students don’t see how these issues (piracy) really impact them. And lets face it for many students, especially in high school and earlier, it is “all about them.” That is where the second article comes into play.

    The second article is about students being able to retain the rights to their own work. (Analysis: Solutions to Student Ownership and The DigiPen IP Problem) The issue here is that some of the top game development educational programs retain the intellectual property rights of the students in their programs. In other words, students who create games as part of their course work are not permitted to sell or otherwise distribute what they create. So if a student creates a game for a course and wants to submit it to the Xbox Live Marketplace they can’t. I would imagine that a lot of students would like to recover some of that tuition money this way.

    Now this is not limited to game development or even computer science courses. Take a look at the WPI IP rules for students. I have heard stories of students deciding that they had a school project that had real money making potential and dropping out of college to go into business. I don’t see this as a great win for anyone. The school loses good will and tuition for no return. The student may or may not make money from their project but they do lose out on more education.

    This issue comes up with competitions by the way. The Imagine Cup competition from Microsoft tries to make very clear that students retain the rights to their intellectual property if they enter. Though, admittedly,  sometimes the legal talk makes that confusing. A number of teams have taken their Imagine Cup projects and made them into businesses though. And that is a great thing! Also as I wrote about the other day, students who take advantage of the DreamSpark program (and are over 18) can enter projects into the Windows Phone 7 market place. Encouraging that entrepreneurial spirit is a good thing.

    In the long run I think most schools would benefit most by letting their students retain intellectual property rights. But you should read some of those articles to see all sides of the issue. It’s not all black and white.



Page 1 of 6 (18 items) 12345»