[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: My First Computer (was Computing Editorial)





Lee Hart wrote:

Glen wrote:

I would recommend python as a language that is very well suited to
beginners.  Perl (which is very similar) is the runner up.


Good heavens! You think they are *easy* to learn? Both are very large
and sophisticated languages, that require substantial computer resources
to run. There are so many choices of how to do things that I think a
beginner would be totally lost.

Might I suggest that you try sitting down with someone who has never
programmed any computer, and watch what happens when they try to learn
one of these languages? For example, ask them to figure out how to get
two numbers from the user and print their sum.

We all suffer from the Professor's paradox; we know so much that it's
hard to remember what it was like when we *didn't* know it. "It's so
obvious to me... how can these students be so stupid that they don't get
it?"


Well I think one big thing is that you want to avoid compilers because
you will have 90% of the "questions" be the same: "why doesn't this
compile". Programs that don't compile frustrate adults and children
alike.


Absolutely!


Basically you need a language that has distance from the hardware.


Quite the contrary! When you're on the bottom rung of the ladder, you
are very close to the hardware. It is essential that you understand it.


I don't know a lot about kids. I'll be the first to admit.  So I don't
know the right age to start programming.


Learning programming is all about learning to think. To learn to think,
you have to think about something. Even the very youngest children are
learning to think, every day and in everything they do. So, they are
learning to "program" their siblings, their parents, their world. "How
do I get people and things to do what I want?"

Teaching them programming skills is giving them a systematic basis for
rational, logical thought. Cause and effect, doing things in order,
counting, repeating until you get it right, making good decisions, etc.
These are essential concepts needed in programming AND in real life.

The world of the computer is more predictable and repeatable than the
real world. Thus, it is the perfect "playground" to learn and practice
logical thinking. The computer is absolutely predictable, endlessly
patient, it never criticises or scolds, and there are no real penalties
for errors. Thus it (ought to) be the perfect tool to teach thinking.
To your point on computers in education; it is of course also possible
to program computers to teach BAD thinking. Rote memorization instead of
problem solving. Entertainment instead of intelligence. Violence instead
of cooperation. In fact, it's probably easier (which is why it is so
common)!
--
Lee A. Hart                Ring the bells that still can ring
814 8th Ave. N.            Forget your perfect offering
Sartell, MN 56377 USA      There is a crack in everything
leeahart_at_earthlink.net  That's how the light gets in - Leonard Cohen




I don't *need* a lot of background in education to recommend perl! I can recommend it because I know that perl makes simple things easy and hard things possible. Isn't this what you want?! Simple things easy.

Take a look at below: from perl.com This is part of an intro that is probably on the level a high school kid could easily get.

In fact it is much longer and you can learn all without buying anything at all-- no software no books.

See how the design is meant to be simple but powerful. In fact the basic syntax is extremely similar to BASIC. My example.

------------
$x= 4;
$y= "cat";
$z= "dog";

Print "The $y saw $x $zs."

-------------
Output:
The cats saw 4 dogs.
------------

And so that could be easier how?!

Glen.
















*********************************************************************


Variables

If functions are Perl's verbs, then variables are its nouns. Perl has three types of variables: scalars, arrays and hashes. Think of them as ``things,'' ``lists,'' and ``dictionaries.'' In Perl, all variable names are a punctuation character, a letter or underscore, and one or more alphanumeric characters or underscores.

Scalars are single things. This might be a number or a string. The name of a scalar begins with a dollar sign, such as $i or $abacus. You assign a value to a scalar by telling Perl what it equals, like so:

$i = 5;
    $pie_flavor = 'apple';
    $constitution1776 = "We the People, etc.";

You don't need to specify whether a scalar is a number or a string. It doesn't matter, because when Perl needs to treat a scalar as a string, it does; when it needs to treat it as a number, it does. The conversion happens automatically. (This is different from many other languages, where strings and numbers are two separate data types.)

If you use a double-quoted string, Perl will insert the value of any scalar variables you name in the string. This is often used to fill in strings on the fly:

$apple_count = 5;
    $count_report = "There are $apple_count apples.";
    print "The report is: $count_report\n";

The final output from this code is The report is: There are 5 apples..

Numbers in Perl can be manipulated with the usual mathematical operations: addition, multiplication, division and subtraction. (Multiplication and division are indicated in Perl with the * and / symbols, by the way.)

$a = 5;
    $b = $a + 10;       # $b is now equal to 15.
    $c = $b * 10;       # $c is now equal to 150.
    $a = $a - 1;        # $a is now 4, and algebra teachers are cringing.

You can also use special operators like ++, --, +=, -=, /= and *=. These manipulate a scalar's value without needing two elements in an equation. Some people like them, some don't. I like the fact that they can make code clearer.

$a = 5;
   $a++;        # $a is now 6; we added 1 to it.
   $a += 10;    # Now it's 16; we added 10.
   $a /= 2;     # And divided it by 2, so it's 8.

Strings in Perl don't have quite as much flexibility. About the only basic operator that you can use on strings is concatenation, which is a $10 way of saying ``put together.'' The concatenation operator is the period. Concatenation and addition are two different things:

$a = "8";    # Note the quotes.  $a is a string.
   $b = $a + "1";   # "1" is a string too.
   $c = $a . "1";   # But $b and $c have different values!

Remember that Perl converts strings to numbers transparently whenever it's needed, so to get the value of $b, the Perl interpreter converted the two strings "8" and "1" to numbers, then added them. The value of $b is the number 9. However, $c used concatenation, so its value is the string "81".

Just remember, the plus sign adds numbers and the period puts strings together.

Arrays are lists of scalars. Array names begin with @. You define arrays by listing their contents in parentheses, separated by commas:

@lotto_numbers = (1, 2, 3, 4, 5, 6);  # Hey, it could happen.
    @months = ("July", "August", "September");

The contents of an array are indexed beginning with 0. (Why not 1? Because. It's a computer thing.) To retrieve the elements of an array, you replace the @ sign with a $ sign, and follow that with the index position of the element you want. (It begins with a dollar sign because you're getting a scalar value.) You can also modify it in place, just like any other scalar.

@months = ("July", "August", "September");
    print $months[0];   # This prints "July".
    $months[2] = "Smarch";  # We just renamed September!

If an array doesn't exist, by the way, you'll create it when you try to assign a value to one of its elements.

$winter_months[0] = "December";  # This implicitly creates @winter_months.

Arrays always return their contents in the same order; if you go through @months from beginning to end, no matter how many times you do it, you'll get back July, August and September in that order. If you want to find the length of an array, use the value $#array_name. This is one less than the number of elements in the array. If the array just doesn't exist or is empty, $#array_name is -1. If you want to resize an array, just change the value of $#array_name.

@months = ("July", "August", "September");
    print $#months;         # This prints 2.
$a1 = $#autumn_months; # We don't have an @autumn_months, so this is -1.
    $#months = 0;           # Now @months only contains "July".

Hashes are called ``dictionaries'' in some programming languages, and that's what they are: a term and a definition, or in more correct language a key and a value. Each key in a hash has one and only one corresponding value. The name of a hash begins with a percentage sign, like %parents. You define hashes by comma-separated pairs of key and value, like so:

�ys_in_month = ( "July" => 31, "August" => 31, "September" => 30 );

You can fetch any value from a hash by referring to $hashname{key}, or modify it in place just like any other scalar.

print $days_in_month{"September"}; # 30, of course.
    $days_in_month{"February"} = 29;   # It's a leap year.

If you want to see what keys are in a hash, you can use the keys function with the name of the hash. This returns a list containing all of the keys in the hash. The list isn't always in the same order, though; while we could count on @months to always return July, August, September in that order, keys �ys_in_summer might return them in any order whatsoever.

@month_list = keys �ys_in_summer;
    # @month_list is now ('July', 'September', 'August') !

The three types of variables have three separate namespaces. That means that $abacus and @abacus are two different variables, and $abacus[0] (the first element of @abacus) is not the same as $abacus{0} (the value in �acus that has the key 0).