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'.
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'.
'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.
Personally I like to make a simple echo server and client to get the hang of network programming with that language.
Connect to data somehow, whether it be a database, file or other...
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..
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
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
My equivalent of a hello world is to do the following:
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).
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.
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
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.
Write a program that calculates a Haar wavelet on an array of numbers. .
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.
Using the outputs of the previous exercise file, write a GUI program that reconstitutes the original bitmap (N.B.: The Haar wavelet is lossless).
Write a GUI program that deals with bitmaps images
Part 2. Data Structures
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.
Using the language's idioms, implement a tree-based datastructure (splay, AVL, or red-black).
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.
Implement an iterator for your datastructure. Consider multithreading issues.
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
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.
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.
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.
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.
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
I usually do the following (in the order presented):
After that its on to a real project...
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.
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.