Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
The way to the good side of the Source: How to Learn to code
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
pytigger
Tux's lil' helper
Tux's lil' helper


Joined: 27 Aug 2003
Posts: 134
Location: Hanover, Germany

PostPosted: Tue Sep 02, 2003 12:11 pm    Post subject: The way to the good side of the Source: How to Learn to code Reply with quote

Many Linux-uses are actually programmers, and many have been for years beforee they even knew what Linux is. Others use Windows or Linux without the least programming experience.
Most people at least once in their computer life think: Now wouldn't it be cool if I could create my own programs, my own games, or modify existing software?
A basic motivation for people to enter the Open Source movement. Programming can be a fascinating hobby, and a very useful one. But it is considered to be hard work to learn to program. Many people think, programming languages are cryptic, unreadable to the average human being, something only for the initiated gurus. These myths prevent people from learning this art, an art next to singing, painting and writing. Of course, some people have more talent then others, but still, the most important requirement is motivation.
I have learnt a lot of natural and programming languages, and one thing I have learnt over time is, that with every language you learn, the easier it gets, and if you begin with a very complicated language, it quickly gets into your way. This is the reason most (non-English) schools start with English, not Latin, French, German or Spanish. Esperanto has also proven to be a powerful way of teaching people to learn languages.

Is there an Esperanto in programming? Yes: Python!

My opion is: If you begin your career with anything but Python, you waste your time, frustration, maybe even money.
Python is almost as easy to read as pseudo-code, it uses very few unusual characters, and has a very good and easy to use standard libraries. On top of that there are a lot of third-party extensions.
There are excellent tutorials that to Python both for programmers and non-programmers.
Even if you, after using python for some time, decide to learn another language for some reason (what you will certainly regret) you can use the abilities that quickly built during your Python career. Many experienced programmers use Python to prototype algorithms and programs, or use it to test C/C++ code.
I recommend these steps of learning Python:

  1. (highly optional) Get Guido van Robot for Linux (Windows version is broken), or any other Karel-workalike and try to solve a few basic or advanced problems. (gvr.sf.net)
  2. Read one or more of the Python for non-programmers tutorials at www.python.org.
  3. Write a few small Python text-mode programs (using things like print and input) for your personal need, get inspired by browsing Python's library documentation, or even get extensions from the internet (there are extensions for ID3 taggers, audio extensions, SQL queries etc).
  4. (optional) Write CGI programs or mod_python modules
  5. (again, optional) Try writing simple games or graphic demos with pygame (www.pygame.org).

After that you will probably want to learn how to create graphical user interfaces. I recommend wxPython (www.wxpython.org) or PyGTK (www.gtk.org) for the beginner. Both are excellent, but pygtk doesn't run on windows and Mac that easy.
Once you have gained some experience, it is time to evolve further. Here are a few tips what to do if you want to stay with Python:

  • analyze foreign code, a good place for searching is sourceforge.net
  • join an existing project
  • create your own project


If you don't want to stay forever with Python, you can go on to other languages. Probably the most widely used language with Linux is C/C++, so there is not much of an option what to learn. Still there are PHP, Perl, Java, Haskell, Pascal and others, each with their own strengths and weaknesses. Once you gained a little knowledge in C/C++ you can learn how to extend Python with C, or you can do almost the same things I pointed out for Python.

I hope that my little over-lengthy introduction gives some non-programmers a point to start and a directory to head.
_________________
And by the way - Gentoo needs an official WIKI!!
Back to top
View user's profile Send private message
JT Mac
n00b
n00b


Joined: 02 Sep 2003
Posts: 7

PostPosted: Tue Sep 02, 2003 2:44 pm    Post subject: Reply with quote

For a long time I have been describing Python as "the Esperanto of programming languages".

Unfortunately, despite my own enthusiasm for both, such a description has not helped inspire others :)
_________________
"Ford, you're turning into a penguin. Stop it."
Email/Jabber: joshua -at-symbol- stalo.com
Back to top
View user's profile Send private message
pytigger
Tux's lil' helper
Tux's lil' helper


Joined: 27 Aug 2003
Posts: 134
Location: Hanover, Germany

PostPosted: Tue Sep 02, 2003 7:41 pm    Post subject: Reply with quote

I just want to spread the word that Python is ideal for new coders.
If people disagree, they can, but the ways I've seen people recommend look totally weird.
In computer science classes students of my school are introduced to programming traditionally using Niki Robot, a Karel Work-a-like, using Pascal like language. Then they are taken to Turbo Pascal (yes, STILL), and after that to Delphi, which actually needs a few changes in coding.
The point here is: I can't see the reason why a school is willing to pay so much of license fees again and again, when they could use a simpler language? This fact being even more scaring when you begin feeling that even the teacher's don't really master the language, the platform and the paradigms (let aside the code itself).
The choice of Pascal at all is very contraproductive, as Pascal is not widely used, neither comercially nor in the Open Source world, where Perl and Python definitely have their share.
_________________
And by the way - Gentoo needs an official WIKI!!
Back to top
View user's profile Send private message
telex4
l33t
l33t


Joined: 21 Sep 2002
Posts: 704
Location: Reading, UK

PostPosted: Tue Sep 02, 2003 10:36 pm    Post subject: Reply with quote

I absolutely agree. Being a philosophy student, I'm not exactly "trained" in programming, yet I've managed to write QuickRip without much trouble thanks to Python :)

I'm amazed that my friends doing CS learn such bizarre languages as CamL, L, Pascal and Delphi, when they could be learning Python!

I'd recommend checking out PyQt and PyKDE too... I've really enjoyed working with them.

I'd also suggest writing documentation as an aid to learning. Nothing sorts your knowldge out better than trying to document something; I really found that when helping write Pygame docs!
Back to top
View user's profile Send private message
bassvandijk
Guru
Guru


Joined: 13 Sep 2002
Posts: 306
Location: Haps, Netherlands

PostPosted: Tue Sep 02, 2003 10:42 pm    Post subject: Reply with quote

Quote:
Python is almost as easy to read as pseudo-code, it uses very few unusual characters


If that's the criteria for the ideal beginners programming language, maybe beginners should look into functional language such as Haskell.

These languages have very few "reserver words" like: for, while, switch, class, define...

Functional languages are very good at expressing algorithms. This means that you don't need to learn many language concepts such as "for" or "switch" to figure out an algorithm. The "only" concept you need to learn is that a function is something that takes some imput and produces some output and that a functions consits of other functions. (There are a few other concepts dough like patterns and types :oops: )

Example:
Code:

Quicksort in Haskell

 
qsort []     = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
                 where
                   elts_lt_x   = [y | y <- xs, y < x]
                   elts_greq_x = [y | y <- xs, y >= x]

 

Quicksort in C

qsort( a, lo, hi ) int a[], hi, lo;
{
  int h, l, p, t;

  if (lo < hi) {
    l = lo;
    h = hi;
    p = a[hi];

    do {
      while ((l < h) && (a[l] <= p))
          l = l+1;
      while ((h > l) && (a[h] >= p))
          h = h-1;
      if (l < h) {
          t = a[l];
          a[l] = a[h];
          a[h] = t;
      }
    } while (l < h);

    t = a[l];
    a[l] = a[hi];
    a[hi] = t;

    qsort( a, lo, l-1 );
    qsort( a, l+1, hi );
  }
}


BTW I don't want to start a religious programming war :-)

I only want to say that people starting with programming should start with a language that hasn't many language concepts.

BTW I think that Python is a beatifull language.
Back to top
View user's profile Send private message
telex4
l33t
l33t


Joined: 21 Sep 2002
Posts: 704
Location: Reading, UK

PostPosted: Tue Sep 02, 2003 10:56 pm    Post subject: Reply with quote

I think that if you're serious about really learning programming from a computer science point of view, languages like Haskell may be worthwhile.

On the other hand, if like me you're just interested in doing some practical coding, and aren't really a computer science type, you're better off sticking to languages that you can learn from, and then do useful things with, and distribute without adding odd language dependencies..... i.e. Python/Perl/PHP/etc.
Back to top
View user's profile Send private message
pytigger
Tux's lil' helper
Tux's lil' helper


Joined: 27 Aug 2003
Posts: 134
Location: Hanover, Germany

PostPosted: Wed Sep 03, 2003 10:33 am    Post subject: Reply with quote

I think "practical" is the way someone should go, except if he wishes to study computer science one day. Maybe he should go practical at first anyway, since other paths might scare him away before learning significant abilities.
Anyway, here's a quicksort in Python:

Code:

l = [1,6,2,60,12,55,53,34]
l.sort()


No, just kidding.



8O here is a serious one from http://c2.com/cgi/wiki?PythonSample :

Code:

def qsort(aList):
        if not aList:
                return []
        ltList=[y for y in aList[1:] if y<aList[0]]
        gtList=[y for y in aList[1:] if y>=aList[0]]
        return qsort(ltList)+[aList[0]]+qsort(gtList)



I would have created my own if I knew the algorithm well enough, I once knew it exactly by heart... I never used it for 2 years now. It can be done a lot simpler (though with a few more lines!).
_________________
And by the way - Gentoo needs an official WIKI!!
Back to top
View user's profile Send private message
itkovian
n00b
n00b


Joined: 04 Feb 2003
Posts: 17
Location: Belgium - Oostende

PostPosted: Wed Sep 03, 2003 12:18 pm    Post subject: Reply with quote

Afaik, quicksort is an excellent thingie to demonstrate the expressive power of languages such as Haskell, Python etc., but to have a robust implementation of the algorithm requires far more than that. IIRC, it is actually quite easy to degrade quicksort into some shell-sort like algortihm, performance-wise.
_________________
I am the Shield-Anvil. And I am not yet done.
Back to top
View user's profile Send private message
bassvandijk
Guru
Guru


Joined: 13 Sep 2002
Posts: 306
Location: Haps, Netherlands

PostPosted: Wed Sep 03, 2003 1:06 pm    Post subject: Reply with quote

itkovian wrote:
... it is actually quite easy to degrade quicksort into some shell-sort like algortihm, performance-wise.


Well you're right about that:
http://www.haskell.org/aboutHaskell.html wrote:

When C is better
It isn't all roses, of course. The C quicksort uses an extremely ingenious technique, invented by Hoare, whereby it sorts the array in place; that is, without using any extra storage. As a result, it runs quickly, and in a small amount of memory. In contrast, the Haskell program allocates quite a lot of extra memory behind the scenes, and runs rather slower than the C program.

In effect, the C quicksort does some very ingenious storage management, trading this algorithmic complexity for a reduction in run-time storage management costs.


In applications where performance is required at any cost, or when the goal is detailed tuning of a low-level algorithm, an imperative language like C would probably be a better choice than Haskell, exactly because it provides more intimate control over the exact way in which the computation is carried out.


But I think for beginners expresiveness is better than performance.

BTW the python quicksort looks pretty much like the Haskell one :-)
Back to top
View user's profile Send private message
gentooalex
Tux's lil' helper
Tux's lil' helper


Joined: 02 May 2003
Posts: 123
Location: Charlottesville, Virginia

PostPosted: Wed Sep 03, 2003 2:09 pm    Post subject: C++ Reply with quote

I am starting to learn C++ because that is the language offered for first year compsci students at my school. Java is taught in the second year of computer science. Im in high school btw.
Back to top
View user's profile Send private message
pytigger
Tux's lil' helper
Tux's lil' helper


Joined: 27 Aug 2003
Posts: 134
Location: Hanover, Germany

PostPosted: Sat Sep 06, 2003 4:26 am    Post subject: Reply with quote

I think neither of us wanted to replace the C quicksort by a Haskell or Python version, nor would any of us use it this way!
Python's sort function for arrays is C anyway!
Yet, the C Version is not well suited for dynamic data structures, whereas there are STL sort algorithms for C++, where you can use arbitrary data structures.
In C, this gives a lot of frustration. Python does not even ask what datatype you assign to the list. The only important thing is that there is a way to compare them (for sorting, I mean).
C++ does you no harm. It only slows down your progress, I think. C++ has a lot of rules and limitations that will hinder you learn the basic mindset for programmers. Still it is a great language and has great software associated with it, thus it's worth learning it.
_________________
And by the way - Gentoo needs an official WIKI!!
Back to top
View user's profile Send private message
sadrok
n00b
n00b


Joined: 21 Feb 2003
Posts: 21
Location: Infront of this stupid PC

PostPosted: Sat Sep 06, 2003 6:03 am    Post subject: maybe there's opportunity here.... Reply with quote

At my old highschool, 1 year after finishing, they started learning the kids Java instead of Python. Personally I don't like Java, even less than I like Pascal (used before going to Java). I can't believe they're using Java to teach programming. And then the teacher (sweet as she is) is basically learning it herself, and still managed to mix up the Java and Pascal code.

I'm wondering if there's the possibility to actually giving Python classes in the area :D after-hours since the programming languages is decided by a commitee for all the schools in the province.

I would agree that Python would be a wonderful language to use for newcomers, just like QBasic was in my time :P
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum