Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I start learning a new language, I have a couple of simple implementations that I like to complete to familiarise myself with the language. Currently, I write:

  1. Fibonacci and/or factorial to get the hang of writing and calling methods, and basic recursion
  2. Djikstras shortest path (with a node type) to get to grips with making classes (or whatever the language equivalent is) with methods and properties, and also using them in slightly more complex code.

I was wondering: does anybody else have any techniques or tools they like to use when getting off the ground in a new language? I'm always looking for new things to add to my "start-up routine".

share|improve this question

closed as too broad by gnat, Kilian Foth, MichaelT, Dan Pichelman, GlenH7 Mar 28 '15 at 14:31

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

Learning a new language at work or at home? There can be a big difference. – Job Apr 9 '12 at 1:23
These are things I do when learning in my own time. I hadn't given much thought to learning at work: there's not much call for it. – AndyBursh Apr 9 '12 at 1:31
I lately make a brick-breaker game (methods, objects, arrays, timers, loops, I/O) or you can try a tetris or snake – e-MEE Apr 12 '12 at 10:14
John Carmack rewrote Wolfenstein 3D in Haskell to learn Haskell. – user16764 Oct 2 '13 at 16:35

12 Answers 12

up vote 12 down vote accepted

I have constructed a small "hello, world" task I have used to make sure I learn some important parts of languages. The program needs to read and parse a CSV file (I make sure to use regex if available), and then - based on command line arguments - it needs to output the data in either json, yaml or XML format to a new file. For constructing the output I usually try not to use to many loops, but instead find the language equivalents of map and reduce.

I've found that modelling this problem is complex enough to be quite valuable. For instance I try not to use a switch/case, but somehow apply the open/close principle and thereby making it extendable (object-based polymorphism, dynamic dispatch table etc.)

share|improve this answer
I really like the idea of having a suitably complex program that most every language would be capable of implementing. – AndyBursh Apr 8 '12 at 21:52
+1, I agree with AndyBursh. Sounds like a really good task that tests control logic, map/reduce-functionality, string handling and IO. The only thing missing would be some kind of graphics, but that might not always be possible in all languages or systems. – Leo Apr 9 '12 at 8:09

I tend to try and find a suitable real-world project - something that the language in question is supposed to be especially suitable for.

Then I play around with the language, see how the most crucial problems for that particular project can be solved on their own, and once I feel somewhat comfortable, I just dive into the real project. More often than not, I end up rewriting the thing from scratch at least once, but I consider that part of the learning experience.

share|improve this answer
+1 for this...solving a Fibonacci program in SQL is a bad way to learn the language. Writing a GUI app in Erlang is not a good way to learn that language. Likewise writing anything in Clojure is also a...wait...nvm...writing anything in Clojure is just awesomeness! – Timothy Baldridge Apr 9 '12 at 14:19
@TimothyBaldridge: doing I/O in Haskell is also... – tdammers Apr 9 '12 at 14:22

Solving problems in Project Euler or similar projects specific for the language helps a lot in understanding the language functions and libraries, and it's powers and weaknesses in different areas. (like finding why a sorting loop you use to solve the problem in the new language is working a lot slower than the one in some other language)


Also, comparing the language you want to learn with the languages you already knows helps a lot to understand what is different and what you should look for in the new language. Relating new concepts with the old ones eases the learning curve. Googling old language vs new language generally gives you a lot to read in that aspect.

share|improve this answer
I've been through a few problems on Project Euler before. Funnily enough, I found it more useful for learning bits of maths than a new language, since I had to actually learn some of the maths first! – AndyBursh Apr 8 '12 at 20:09

I'm quite partial to Conway's Game of Life and the good old Mandelbrot Set as first projects in any new language (preferably as GUI apps). By the time you're done you'll have gained some insight into their compute performance, dabbled in the language's (or its standard library's) multithreading support and implemented a minimal viable GUI app (an image which responds to mouse clicks).

A few years ago I wanted to learn Scala and decided to use Project Euler to do so. 200+ solved problems later and I don't really feel I know the language that well at all beyond the basics (I use Scala almost exclusively for PE); sure learned a lot of mathematics though (more on this here).

Update 2012-11-30: Just watching the video (20min) on the "Global Day of Code Retreat" site, and pleased to see that their focus for the day is Conway's.

share|improve this answer
That's pretty in-depth just for getting off the ground in a language. How long does it take you to implement Conway's game of life + gui in a language you've never used before? – naught101 Apr 9 '12 at 1:55
Not really: getting game of life printing '*' patterns to the console might take a few hours while you learn the basic control structures / datastructures. The GUI you just need enough to display a canvas and respond to mouse clicks, figure out animation/timers and maybe some buttons for stop/start/clear... maybe a similar amount of time unless it's a really weird API. I'd probably actually invest more total time in researching the resources I'm going to use (identifying what are considered the best tutorials, online documentation, example code) before I actually start coding. – timday Apr 9 '12 at 20:27

There is a website called Project Euler that contains a large number of mathematical/algorithmic problems. The cool thing is that it has algorithms that will require to handle different data structure and different techniques (iteration, recursion).

I did that for F# and it really helped.

share|improve this answer

I have been using Project Euler for this kind of stuff, but right now i think that you should think about some simple app and use the language in a practical solution.

You can write something like Todo list.

Check out this site.

share|improve this answer

Other than Project Euler, I like to do some of this problems

Many of this problems were used in programming competitions like and others.

For me, the main advantages os SPOJ over Project Euler is that spoj evaluate's your code and have a ranking of all users submissions. Just as a note, today it accepts languages from ADA, Brainfuck and bash, to TCL and Haskell

And of course, a blog engine.

share|improve this answer

I use Project Euler, and sometimes make simple text based games, as well as the fibonacci thing you said. I also go and look at other beginner's code and try to write their code…except better. Also, try doing some simple I/O Routines.

share|improve this answer

When trying a new language, like trying out a new PHP framework for example, I like to create a Guestbook.

Guestbooks were all the rage when i was starting off, creating a basic blog would probable be a modern equivalent.

Either way, I think creating something like this teaches the basics, including creating a form, validation, saving its contents to a database table and then loading records from that table to show previous entries.

These are the fundamentals you'll need if you keep developing in that language.

share|improve this answer
-1 "When trying a new language, like trying out a new PHP framework for example"...wat? A language is not a framework.... – Timothy Baldridge Apr 9 '12 at 13:59
You're right, I should have worded that a little better, I should have said when trying out a new language or a new framework. – Gortron Apr 9 '12 at 14:17

I, too, have a small set of programs I write when learning a new language. Mine are:

  1. Pentominoes - output solutions for the basic 12 unique 5-orthogonal-squares shapes placed in the rectangular areas of 3x20, 4x15, 5x12, 6x10. And then with a single tile removed from each corner, 8x8. For a bonus, I treat each pentomino as having one color (blue) on the top and another on the bottom (white). And then I mark each solutions as to whether it is a single color. For an extra bonus, I input the 12 pieces such that one of the 3x20 solutions is a single color.
  2. Checkers - generate a checker (or draughts) board, a checker player which randomly generates a move from the set of all currently legal moves given a board state and then a manager which then plays and outputs each game for some number of iterations. BTW, this appears deceptively simple. {smirk} For a bonus, I then implement a simple board-value-sum alpha-beta move selector and then play it against random and against itself at various depths.
  3. Boggle/Scramble - given a 4x4 or 5x5 board of randomly generated letters, use a dictionary to find all possible valid words. For a bonus, use Scramble/Scrabble letter points and/or word multipliers to generate scores and order the returned list of valid words in descending point value.
  4. Conway's Life - initial version, self-evident. For a bonus, enhance to play in a triangular and hexagonal environment (slight adjustment to the rules necessary). For an extra bonus, alter the Boolean on/off to a real/float and then use an expanded area for determining thresholds for moving towards cellular life and death. I ended up doing lots of playing around once I got here. {smirk}

Each of these requires a different "slice" of basic logic and search. I have found each of these to be great in pushing my mind to figure out the nuances of each language from a core "getting things done effectively" standard of measure. Each can be done from a command prompt (no crazy UI dependencies). Each offers pretty immediate and accurate feedback of where one might have made bad assumptions and/or coding mistakes. Each offers a nice platform from which to perform some benchmarks to feel out performance issues. And most importantly, I've found each is fun in nature and inspire me to explore and play with the language, its libraries as well as the problem domain itself.

share|improve this answer

Speaking for myself, I'm almost always learning a new language in order to work on an existing codebase. So I much prefer tasks that simultaneously teach me the language and the code (rather than an artificial task like Fibonacci).

So, usually it goes something like this:

  1. Make a tiny change that produces a visible effect (usually a bad one)
  2. Make a small change that produces an improvement
  3. Identify a tiny bug and fix that
  4. Move on to bigger bugs...
  5. Eventually add new features...

I usually learn the language by osmosis, by cutting/pasting bits from elsewhere in the code and modifying them. When I want to add new features, I start googling. That leads me to functions and library features that are useful, and usually to language features I wasn't aware of, which I'll start to drop in as I see the need.

I'm curious why so many people have answered with this similar preference for developing small "learning" projects that are not valuable in their own right.

share|improve this answer

I don't have a standard approach. It depends on why I learn the language.

For example:

This year I learnt C# and C++/CLI for my job in order to work on a big commercial application, so I needed to get really familiar with those languages. For each language I simply fetched a book, read it cover to cover and did (almost) all exercises from the book in about a week.

Last year I learnt Python, just to know some Python and to create some small scripts for building and maintaining a hobby project of mine. I read a few tutorials and then jumped right into writing the scripts I needed and learning Python on the fly.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.