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

Re: learning programming

Glen Mehn <glen@squaretrade.com> writes:
GM> personal preference, I think. 
GM> And perl/python is apples and oranges: python is object oriented
GM> (like java, C++), while perl is more like C.
GM> A lot of people take issues with perl's lack of standards-- where
GM> {}, (), etc, may or may not be required.
GM> As to having {} and ;, it's a matter of the language structure,
GM> and that's all. Whether or not you use them is simply a matter of
GM> how you structure the language.

For someone who's just starting out, doing anything non-trivial in
Perl can be extremely confusing; there's a fundamental difference
between $foo{'bar'} and $foo->{'bar'}, and it's not obvious how they
relate to the variables $foo, @foo, and %foo (which are all

For someone who's just beginning, good language picks are probably:

-- Python: very simple language structure, little punctuation,
   reasonably high level of intuitiveness.  Free tools, good OO
   semantics, reasonable documentation.  http://www.python.org/

-- Java: C-like syntax (good if you eventually want to learn C),
   object-oriented with relatively sane semantics (good if you
   eventually want to learn C++).  Downsides are a lack of free tools
   and a fairly slow compile-execute cycle.  http://java.sun.com/

-- C: most Linux programs are actually written in C, so if you want to
   "hack on Linux stuff" you'll probably eventually want to learn C.
   Plusses: standardization, good books, ubiquity; minuses: pointers,
   explicit memory management.  No one Web site, but _The C
   Programming Language_ (Kernighan and Ritchie) is the canonical
   reference book, and isn't bad to learn from.

[1] In particular, if you don't know Perl already: $foo is a scalar
(number or string); @foo is an array of scalars; %foo is a
string-to-scalar hash table.  $foo[0] is the first element in the
array @foo, and $foo{'bar'} is the element referenced by the string
'bar' in the hash %foo.  A scalar can also be a reference to some
other variable, though (this is the only way to build nested data
structures); this is a similar concept to pointers in C, only more
hackish.  So if $foo is a reference to a hash, $foo->{'bar'} gets the
'bar' element from that hash, but not necessarily (though possibly)
the 'bar' element from %foo.

For contrast, in Python, you similarly have numbers, strings, arrays,
and "dictionaries".  The variable foo can be exactly one of these
types (or some other object type); foo[0] gets the first element of
foo, if foo is an array; foo['bar'] gets the element referenced by the
string 'bar' if foo is a dictionary.  There's none of the "well,
depending on the bit of punctuation afterwards, $foo could actually
reference pretty much anything" nature that Perl has.

Not, mind you, that it isn't useful to learn Perl; a fair number of
scripts, including many important things on a Debian system, are
written in Perl, and if what you're doing is vast amounts of
text-processing then it's even the right tool.  But IMHO the
documentation is hard to get around unless you know what you're
looking for; it's probably a poor first language, and a good third or
fourth one.

David Maze         dmaze@debian.org      http://people.debian.org/~dmaze/
"Theoretical politics is interesting.  Politicking should be illegal."
	-- Abra Mitchell

Reply to: