This letter is associated with the following article:
Letters
Thursday, September 14, 2006 12:00 AM

Why Johnny can't code

BASIC used to be on every computer a child touched -- but today there's no easy way for kids to get hooked on programming.

Read other letters about this article

  • Thursday, September 14, 2006 10:13 AM

    An example of a Basic program

    This is written in a console app in Visual Basic Express, which is a really cool IDE and FREE to download from Microsoft.

    'In the Monty Hall Game

    'you are given three doors, behind

    'one door is a brand new Cadillac,

    'behind the other two doors are goats.

    'You win the Cadillac if you can guess

    'which door the car is behind.

    '(You would rather win a Cadillac than a goat, wouldn't you?)

    'Before opening the door you've picked,

    'Monty Hall opens one of the other two doors

    'and shows you a goat.

    'Now there are two closed doors.

    'Monty then gives you a choice;

    'You can stay with your original pick

    'Or you can switch to the other door.

    'Now, what should you do?

    'Most people assume the chances are equal either way.

    'This program proves that you should switch doors

    'because then your chances of winning the Cadillac

    'will in fact be two out of three,

    'as opposed to one out of three.

    '

    '--Believe it or not--

    Sub Main()

    'declare the values

    Dim x, car, guess1, choice, WinStay, LoseStay, WinSwitch, LoseSwitch As Integer

    Dim strinput As String

    'seed the random generator

    Randomize()

    'loop 2000 times

    For x = 1 To 2000

    'pick a random number from one to three

    car = CInt(Int((3 * Rnd()) + 1))

    'this sets the door the car is behind

    'pick another random number from one to three

    guess1 = CInt(Int((3 * Rnd()) + 1))

    'this is the player's first guess

    'let's make the player chose to switch half the time

    'this will give 1000 trials for each option

    If (x Mod 2) = 0 Then

    choice = 1

    Else

    choice = 2

    End If

    'now see who wins and collect results

    If choice = 1 Then 'choice is to stay

    If car = guess1 Then

    'wins the cadillac

    WinStay = WinStay + 1

    Else

    'loses and wins a goat - maybe

    LoseStay = LoseStay + 1

    End If

    Else 'choice 2 to switch

    'Hey, you know what? The door opening business

    'doesn't make a damn bit of difference.

    'It's a non-event that can't even be coded!

    'The fact is, Switchers get to look in TWO doors!

    'That's why switching should win two out of three times.

    'So:

    If car = guess1 Then

    'shouldn't have switched

    LoseSwitch = LoseSwitch + 1

    Else

    'the car was in one of the two other doors

    WinSwitch = WinSwitch + 1

    End If

    End If

    Next x

    'stop looping and display results

    Console.WriteLine(("Staying wins ") + CStr(WinStay) + (" times out of 1000 and loses ") + CStr(LoseStay) + (" times."))

    Console.WriteLine(("Staying wins ") + CStr(WinSwitch) + (" times out of 1000 and loses ") + CStr(LoseSwitch) + (" times."))

    'halt console so you can read results

    strInput = UCase(Console.ReadLine())

    End Sub

    Note: there's nothing here about computers as such, nothing about 'popping the stack' or anything else. This is just an example of using coding to think through a problem. IMV, EVERYONE should be able to code like this. That's what Basic is good for, not to delve into computer basics, but to be a readily understandable and univeral programming language.

    Programming, let us note, is something that is completely distinct from controlling computers. In fact, most people really don't want to know what is going on inside their computers and really don't need to know. But they should know how to program.

Most Active Letters Threads

509

The crazy, irrational beliefs of Muslims

Tom Friedman explains the real problem: stupid Muslims think the U.S. is about war and aggression.
426

A key British official reminds us of the forgotten anthrax attack

A vast array of establishment and expert sources do not believe this episode was really resolved.
311

The face of rotted Washington

Evan Bayh demands more debt-financed war - fought by others - while boasting that he's a stern "deficit hawk."
210

Is Obama's civil liberties record understandable?

Was it unreasonable to expect him to adhere to his commitments regarding the Constitution?
151

Bigotry wins in Switzerland

By voting to ban the construction of minarets, Switzerland apes the most extreme intolerance in the Muslim world

View all »

Letters Help

Currently in Salon