views:

544

answers:

7

Possible Duplicate:
What would you write if you wanted to learn a new language?

I once read that having a standard set of programming problems that you solve every time you learn a new programming language is a very good thing. It is good because you know in theory how to solve the problem and the only difficulty is in implementing the solution in the language you are trying to learn, which is exactly what you want. My question is for those who do follow this practice. My question is this: What standard programming problems do you solve when you learn a new language?

To get the ball rolling, here's a problem I have implemented a couple of times: Given nine letters, find all the words that are three letters or longer that can be formed using only those nine letters. Furthermore, every word must contain one particular letter. (This problem is one that is given in some of the Australian newspapers.) I like it because it's fairly simple, but still involves file IO, playing with data structures and generating prime numbers (I have a pretty cool method of solving this problem). Here is a Python + AJAX implementation of it.

Note: I thought I read about this practice in Peter Norvig's Teach Yourself Programming in Ten Years, but I think I actually first read about it in this comment here on SO.

Also, if this should be community wiki, please let me know. I haven't quite worked out what should and shouldn't be community wiki, and I haven't seen any official looking guidelines on it.

+7  A: 

These related questions might help:

Colin Pickard
Thanks. I had actually read most of those already. I'm curious to see how many people have their own non-trivial programming problems they always solve and what those problems are.
David Johnstone
+2  A: 

Project Euler is a good source of problems.

duffymo
I agree, but I find it more language agnostic and maths-focused - so not always best for getting up to speed in a new language.
Colin Pickard
"language agnostic" is exactly the point, in my opinion. Some of the math is rather advanced, but a lot of the problems shouldn't be beyond anyone with a high school education (e.g., prime numbers).
duffymo
+6  A: 

Because I tend to do a lot of graphics programming, one problem I like to solve in any new language I learn is color quantization.

http://en.wikipedia.org/wiki/Color_quantization

Each time I either search out a new algorithm I haven't implemented before or try to remember (without my notes!) one that I have done in the past.

The nice thing about this sort of problem is that it makes me familiar with a wide array of language features - loops, data structures, graphics libraries, etc.

In general I like to learn new languages by solving what I would call "fun" problems. Sometimes these are real world problems, sometimes not. The big thing is that I enjoy solving them - this makes me pay more attention to what I'm doing and helps me restart after I have to take a break (inertia is a powerful thing!).

Branden Hall
+2  A: 
  • Try small fun problems like shown in Ruby Quiz. They are funny and solutions are given and discussed. The problems there are a scripting centric (Ruby of course), but I used some puzzles to play around with Scala. The name puzzle or quiz is misleading, as there are just reasonable sized tasks to complete, that are challanging and funny as well.

  • Try to implement a simple xUnit implementation test driven in the new lanaguge (like proposed in http://www.amazon.com/Test-Driven-Development-Addison-Wesley-Signature/dp/0321146530 I think). It's quite difficult in the beginning, but when you are finished with the testrunner, you likely used all major features of the language. I did this with Ruby and it worked well for me (although there was a good implementation available already so it's just for fun.)

  • Write all your homegrown utilities and scripts in the new language then. That is really hard as I want things to be done and do not like searching for some solution for hours, but it helps you getting around quickly.

Peter Kofler
+1  A: 

I must confess I don't have any such set. What I'm doing is I usually leave it up to language to introduce itself in short tutorial. Each language is unique and each language can express/describe/solve a slightly different set of problems than the other one. I think the best way is to think of/plan what are you going to solve/implement and then pick up the language the most people would chose to solve similar problem. In example:

  • considering a simple game, then think of a ActionScript/LUA/...

  • is it a web project for unix* server? consider perl/php/python

  • are you going to implement compiler or something like that - lisp/haskell/...

  • is rather an expert system, then why not to try to learn prolog?

  • ...

I think you can see the point now. I think it does not make much sense to try to come up with common/universal set of problems, which would introduce/compare all these languages.

What makes probably sense is to have a two sets of examples, one set will be just for comparison of languages in one set. These examples will just demonstrate the syntactic sugar: how arrays are defined in python/perl/pascal/C/PHP, how to create a dictionary in python/perl/...

The second set will allow you to see how to implement data structures in particular languages: record in C, in LISP, in Perl, in Python, tree in C, tree in LISP, ...

SashaN
+1  A: 

I usually start with the simple "Hello World!" problem in the new language. Getting output displayed is useful for future debugging as most programs have some form of output. In some cases this can involve taking a few differenet approaches as for example in ASP.Net there are a few ways to create a web page that says, "Hello world," and each has its benefits and drawbacks in a way.

JB King
+1  A: 

Tetris or other small games (samegame, chain reaction) . Partially because its fun enough to remain interesting when doing it repeatedly.

Marco van de Voort