[Tutor] Which programming language is better to start with

dman dman@dman.ddts.net
Tue, 26 Mar 2002 21:59:21 -0600


On Tue, Mar 26, 2002 at 09:50:35PM -0500, Erik Price wrote:
| On Tuesday, March 26, 2002, at 05:46  PM, Sean 'Shaleh' Perry wrote:
| 
| >In my experience people who start on the high level languages and
| >then try to go low level often find it hard to fit in.  They are
| >too used to the language doing everything for them.  Of course the
| >opposite is sometimes true and we find C coders trying to implement
| >hashes themselves or who never check if a python module exists
| >before reinventing the wheel.
| >
| >I started in C, worked up to C++ and then learned perl, lisp and python.
| >Having started in C where I had nothing I learned to be good at managing
| >resources and careful planning.  It was hard though.  No doubt.
| 
| I'm afraid of this very same thing.

Keep working at it, little by little.  As you go, though, do things
that are interesting to you.  If you aren't interested in the task it
will be boring and tedious.  If you are interested in it, then you
will be driven to work it out.

| I never received any formal instruction in programming.  A few months 
| ago, I started learning PHP, and feel very comfortable doing basic tasks 
| with that language (data processing, database access, typical web app 
| stuff).

That's good.  You know how to think in concrete abstract terms.  (if
that makes any sense)  You think concrete enough to explicitly list
all the steps needed to be done, but abstractly enough that your steps
work for more than one particular input.  This is the core of
programming.

| I have always wanted to learn Python, though, for even longer 
| than I've known of PHP, so I am tackling that too.  But often -- REALLY 
| often -- I see a lot of references to things that I know are C-related.  
| It can be anything from "this language is based on C's construct..." to 
| "similar to the C function 'printf' ..." or even simple references like 
| "garbage collection", which I now know that a Python programmer can 
| pretty much get by without ever hearing in their life but it is an issue 
| that is of concern to C programmers.

C is historically very important, and is still very important today.
For one thing, python is implemented in C.  Some of the C libraries
are good enough that redesigning them is not very beneficial.  Thus
the python interface closely matches the C interface.  For older
programmers (not me, btw) their C background helps here.

| Yet, if C is the language that Unix and operating systems and games are 
| written in, then it must truly be a complex thing, right?  Like assembly 
| language, only a little higher?

C is like a portable assembly, but it isn't all that complex.  The
beauty of C and UNIX is their elegance and simplicity.  Performing
regex searches on strings without any nasty memory corruption or leaks
is much harder than in python, but that's not what C is designed for
doing.  C was designed for system-level programming.  Creating kernels
and the like.  It gives you direct unprotected access to system
resources (namely memory).  This is like handing you a .357 magnum
fully loaded.  If you don't know how to handle it (which way points
away from you) then you're liable to shoot yourself.  One you graps
the basics, however, it isn't terrible, it just isn't high-level.

| A few weeks ago I was in a library and saw a book on C programming, so I 
| started reading it.  It was "a C Primer" or something (there's probably 
| fifty of those).  I was pleased to find that it wasn't really that 
| intimidating at all, and in fact the syntax strongly resembled that of 
| PHP.  It was a strange feeling, to understand what was going on in the 
| simple examples of the first few chapters that I read.

Yeah, perl and php borrowed a lot of their syntactic structure from C
(as did Java).  I expect that is largely because C (C++, Java) is
familiar to many programmers.

The main difficulties with C, compared to python or php, are :
    o   no OO support built-in,  an OO style can be used, but it is
        more awkward (though the standard FILE operations are rather
        OO)

    o   memory management,  when do I free this pointer to prevent a
        memory leak, but not create a dangling reference?

    o   string and other high-level operations;  in C a string is a
        "char*".  That is, it's a pointer to the beginning of an array
        of characters.  The last character in the string has the value
        NULL.  If you forget to NULL-terminate a string, you can have
        functions that do nasty things to memory.  Same goes for
        trying to copy a string into an array that is too small.  It's
        the memory management that all the effort goes into.

| I would really like to learn more about it, if only to get a more 
| foundational education in the way programming is done, but when I 
| consider how little time I have for hobbyist programming, I am convinced 
| that I am best off learning something like Python, which will hopefully 
| let me get off the ground more quickly in terms of writing useful 
| scripts and programs.

As Sean said, knowing data structures and algorithms is more useful
than knowing a plethora of languages.  Definitely go get "The Practice
of Programming" by Kernighan and Pike.  It will help you in both areas
at once!  It is a highly recommended book, kind of a classic.  I have
it, but haven't gotten very far with it yet.  The book discusses how
to program; how to develop software.  It doesn't focus on any given
technology or library, but rather the process.  It will teach how to
go about developing software in an effective way.  For their examples,
they use C with some C++ and Java sprinkled in.  You can begin to pick
up C while you learn how to program effectively!  With your
syntactical familiarity with a C-ish languge you should have little
difficulty in picking it up (especially if you have a decent C
reference handy).
 
| One of these days I shall surely have to take a class in
| programming.

Some classes are more helpful than others.  In one of my classes the
prof. spent a lot of time covering the details of C semantics.
Everyone in the class had already learned C++.  It was a waste of
time.  The remainder of the class was spent discussing mathmatical
algorithms like Netwon's Method and matrix mutliplication.  The
homework assignments were to implement the math in C.  They were
extremely easy.

Other classes are very helpful.  For example I learned about hash
tables, AVL trees, and other data structures in some of my early CS
courses.  Also, since I'm a Software Engineering major (not CS), many
of my courses have focused on the process of software development and
things like Design Patterns and Architecture.  These are the classes
that I'm glad I've taken so I don't need to rediscover these concepts
the hard way.  ("Design Patterns" by the GoF is a must for anyone who
intends to do any serious programming)

Are there any programmer-type groups in your area?  Any LUGs or PIGs,
etc?  You will probably get just as much out of personal interaction
with a "guru" as you would from a class.  The realtime responses and
the ability to diagram concepts and react to your expressions of
confusion or enlightenment can be very helpful.

Good luck to you!

-D

-- 

A)bort, R)etry, B)ang it with a large hammer