views:

396

answers:

17

When you are learning a new language, what is your favorite first (or close to first) exercise that you do to get the hang of it? And why?

EDIT: Preferably looking for things that are more complicated that 'Hello World'.

+4  A: 

'hello world!'

I really do think this a good place to start. Its basic and only takes a few seconds but you make sure your compiler is running and you have everything in place. Once you have that done you can keep going. Add a variable, print to database, print to file. Make sure you know how to leave comments. This could all take a mater of 5 minutes. But its important stuff.

Patcouch22
+1  A: 

Personally I like to make a simple echo server and client to get the hang of network programming with that language.

The.Anti.9
+2  A: 

Connect to data somehow, whether it be a database, file or other...

Galwegian
+2  A: 

Red-Black tree.

Ben Hoffstein
What is a Red-Black tree?
The.Anti.9
http://en.wikipedia.org/wiki/Red-black_tree
Ben Hoffstein
Rolling On The Floor Laughing. %)
rafek
A: 

Ray tracer.

TraumaPony
A ray tracer? Really?
Galwegian
Yeah. They're pretty :P
TraumaPony
+6  A: 

other than hello world, I try to port one of the existing programs to the new languange. this will challenge me to learn some good old techniques in the new language and help me build a new library of classes or helpers..

Gulzar
Absolutely. I do the same and find it the best way to learn. It also indirectly teaches me more about the language i originally wrote it in, depending on the new language (better technique, etc)
mattlant
+1  A: 

I like to learn a new language by doing a "real" task (for "personal" use)

My first java program was a client for an online multiplayer game (that I then released into public domain)

My first vb.net program was a front-end for my digital video recorder

My first VHDL "program" was a 64x32 led array controller

Axeman
+2  A: 

I usually don't do very well with it unless I have a "real" project to apply it to. Even made up ones get boring fast. In fact, I find it helpful to throw yourself in the middle of a bigger project and make small changes to something that already works.

YMMV

Jeff MacDonald
A: 

Often I'll implement the k-means clustering algorithm.

Corey
+2  A: 

My equivalent of a hello world is to do the following:

  1. Retrieve multiple inputs (ie, parms from command line, text boxes on a gui)
  2. Manipulate that input (ie, do math on numbers and manipulate text)
  3. On a gui use a list box.
  4. read and write files.

I feel after doing the above I get a good feel for the language and a good introduction to the IDE and how easy (or really how difficult) it is to work with the language and the environment it runs in.

After that if I want to go further I will use the language in a real project that I need to do (probably a utility of some kind).

bruceatk
A: 

Drag-and-drop image gallery.

When I was cutting my teeth on Win32 and MFC, this was one of my first projects. Pretty quickly I ported all my code into ActiveX controls. Then I rewrote the thing in Java. For kicks, I rewrote it again in pure Javascript. When I broke into .Net, I rewrote the thing again in C#. Last but not least, I used it as an exercise for learning Objective-C and UIKit.

Why? It's a visually appealing toy, for one thing. It's nice to get instant gratification from your code, I think, and working with images is one of the most gratifying things I can think of.

David Hill
+5  A: 

Larry O'Brien had a great series of blogs titled '15 Exercises to know A programming Language' Part 1 Part 2 Part 3

See Larry's Blog for the details.

Part 1. Calculations

  1. Write a program that takes as its first argument one of the words 'sum,' 'product,' 'mean,' or 'sqrt' and for further arguments a series of numbers. The program applies the appropriate function to the series.

  2. Write a program that calculates a Haar wavelet on an array of numbers. .

  3. Write a program that takes as its arguments a the name of a bitmapped image. Apply the Haar wavelet to the pixel values. Save the results to a file.

  4. Using the outputs of the previous exercise file, write a GUI program that reconstitutes the original bitmap (N.B.: The Haar wavelet is lossless).

  5. Write a GUI program that deals with bitmaps images

Part 2. Data Structures

  1. Write a class (or module or what-have-you: please map OOP terminology into whatever paradigm appropriate) that only stores objects of the same type as the first object placed in it and raises an exception if a non-compatible type is added.

  2. Using the language's idioms, implement a tree-based datastructure (splay, AVL, or red-black).

  3. Create a new type that uses a custom comparator (i.e., overrides "Equals"). Place more of these objects than can fit in memory into the datastructure created above as well as into standard libraries, put more objects into it than can fit in memory. Compare performance of the standard libraries with your own implementation.

  4. Implement an iterator for your datastructure. Consider multithreading issues.

  5. Write a multithreaded application that uses your data structure, comparable types, and iterators to implement the type-specific storage functionality as described in Exercise 6. How do you deal with concurrent inserts and traversals?

Part 3. Libraries

  1. Write a program that outputs the current date and time to a Web page as a reversed ISO 8601-formatted value (i.e.: "2006-06-16T13:15:30Z" becomes "Z03:51:31T61-60-6002"). Create an XML interface (either POX or WS-*) to the same.

  2. Write a client-side program that can both scrape the above Web page and the XML return and redisplays the date in a different format.

  3. Write a daemon program that monitors an email account. When a strongly-encoded email arrives that decrypts to a valid ISO 8601 time, the program sets the system time to that value.

  4. Write a program that connects to your mail client, performs a statistical analysis of its contents (see A Plan for Spam ) and stores the results in a database.

  5. Using previous Exercise, write a spam filter, including moving messages within your mail client

If you can do all these things in 2 languages, I'm sure google has a job for you

Benoit
Seems a little extreme and probably a waste of time for most people.
bruceatk
I don't disagree, but at the end, you will **know** then language...
Benoit
+5  A: 

I usually do the following (in the order presented):

  1. Print a pyramid with height provided by the user (checks basic I/O, conditionals and loops)
  2. Write a class hierarchy with polymorphism etc... (checks OO concepts)
  3. Convert decimals to roman numerals (checks enums and basic data structures)
  4. Write a linkedlist implementation (checks memory allocation/deallocation)
  5. Write clones of JUnit and JMock (checks refelction/metaprogramming)
  6. Write a console based chat system (checks basic networking)
  7. Modify (6) to support group chat via multicasting (checks advanced networking)
  8. Write a GUI for (7) (checks GUI library)

After that its on to a real project...

Garth Gilmour
A: 

Console based Tetris

rapto
A: 

I like games for learning programming because the business rules are carefully delineated. The first three programs I write in a new language are Ro-Sham-Bo, Blackjack, and Video Poker.

Jekke
A: 

Pick a task(s) that you already understand. That way you limit the amount of "new stuff" you need to assimilate.

A: 

I think, for me, learning by porting existing code (for example, from another platform) is always a challenge and fun. just simple demos, boardgames, etc.

bmosley