Possible Duplicate:
“Projects” for learning a new language [1]
Hello! I'm about to begin learning C# and ASP.Net and I was wondering if anyone had any suggestions for ten really good, short programs (i.e. Hello World, Towers of Hanoi, etc.) to write to help become fluent with a new language .
I actually made a list for myself of about sixty software exercises I try to do in new languages/frameworks. Here's a few I think would be useful:
[Phonebook.] Generate a list of 5,000 random names of people and generate 0 to 3 random phone numbers for each person.
[Primes.] Compute the 5,000th prime number.
[Syntax: Collections.] Write a method M
which takes an array of type T and some sort of reference to another method m
which operates on Ts. Call M
on various arrays with different m
s (e.g., print this item; add 5 to this item; put this item in another collection if it matches a condition; etc.) to see if you can produce useful results.
[Syntax: Big numbers.] 3^3 is 27; 3^3^3^2 is over 9,000 digits long. Compute the exact value of 3^3^3^2.
[Blackjack.] Play a simple interactive game of blackjack. Use a "real" deck, such that you don't shuffle until needed (instead of after every hand). Keep track of and report win/loss rate on demand. Allow user to stand, hit, double down, split (if two cards are the same, start two new hands that each use one of those cards), and surrender (recover half your bet if you don't want to continue the hand and you haven't made a move yet).
[Choose Your Own Adventure.] Make an interactive state machine which is essentially a choose-your-own-adventure game. Allow the user to save their state and restore it from a file.
[Integration.] Get the 10 most recent StackOverflow questions, the author of each one, and the number of votes that this question has.
[Sudoku Solver.] Given a 9x9 input consisting of the characters 1-9 or ".", determine what values must go in the "." to make a valid Sudoku solution, or return "error" if no solution is possible.
[Blogging I.] Write a small blogging platform consisting of Posts
and Comments
. If you authenticate, you can edit posts. Anybody, authenticated or not, can leave Comments
on a Post
. Initially, users just have a user-id and plaintext password stored manually (there is no interface to add/remove users). There are five different views:
[Blogging II.] Enhance the Blogging I
exercise. Add a few more features:
[Blogging III.] Enhance the Blogging II
exercise. Integrate with external APIs:
Rosetta Code
Rosetta Code [1] might be a good fit. It has all kinds of tasks and little games. It can show you completed versions of the problems in multiple languages, providing an extremely useful point of reference!
Here's a link to a solution for "print out all the words from the 99 bottles of beer on the wall song", in the key of F#: Solution [2]
Project Euler
You could also work through some of the problems on Project Euler [3].
Of course, Euler is pretty challenging, and as some commentors pointed out, it is perhaps overly focused on math.
[1] http://rosettacode.org8-10: I'll have to owe you.
I'd go to Rosetta Code [1] and pick ten tasks that looks to play into that language's strength.
But there are two problems with the question, as stated. First, some languages play to some strengths and some to others, so no set of ten problems will ever be a good exercise for a language.
But there's a even more serious problem with this, even assuming that problem is overcome. Once you did a problem in one language -- in fact, once you did a problem in three or four languages that share a similar style, you'll tend to approach that problem the same way with every new language, which is exceedingly counter-productive when trying to learn a new language.
In my opinion, doing familiar problems is a good way to learn the new syntax of things you already know in a new language. In a sense, it is a good fast forward, even if it often leaves holes in one's knowledge that one won't even notice are there.
But to truly know what makes a language different, what pushed someone to create a new language, you have to approach it with a problem you don't know how to solve.
[1] http://rosettacode.org/wiki/Main_PageI've lost count of the number of programming languages I've learned over the years, so if you haven't learned many languages, my advice might not be right for you. For me the key is that if I'm learning a new language, I must be doing it for a reason. I find it motivating to get to a new problem as soon as possible that will justify learning the new language. Examples:
Somebody I admire had been bugging me for years to learn Icon, but I waited until I had a problem that would really stretch Icon's backtracking.
I learned Tcl because I really wanted to learn the Tk toolkit.
I learned Modula-3 because of the prospect of writing systems code (a debugger) in a language that was mostly safe but would still allow me to do unsafe things.
Although I taught Haskell several times, I didn't really become solid in it until a problem captured my imagination that would have been nearly impossible without Haskell's type classes.
I will learn Scheme on the day that I really, really want to do something that absolutely has to have macros.
So my advice is this:
Find a problem that is better suited to your chosen language than to any other language, and build a solution to that problem.
If there is no such problem, why are you learning the language in the first place? If other people are forcing you to learn it, find out what problems they think are so important that the language is worth learning...
Not exactly 10 problem but try S-99: Ninety-Nine Scala Problems [1]. It's applicable to other languages as well, although the answers are only given in Scala.
[1] http://aperiodic.net/phil/scala/s-99/I dont have 10, but one I always use is, I generally write a program to calculate the date of easter for any given year as a first program when starting a new language.
The reason I do this is, it not only helps you understand the language syntax, it also helps understand the way mathematical operations occur within the given language.
Check out http://www.assa.org.au/edm.html for more information regarding calculating the date of easter.
Simple card games. e.g. Blackjack, War... And once you have the basics you can build up from there - try Poker, add networking, etc.
Also, check out this SO thread [1] for some interesting suggestions...
[1] http://stackoverflow.com/questions/2192808/simple-but-interesting-task-for-c-newbie/2193081#2193081Look up questions tagged code-golf
on stackoverflow and do them (not worrying about character count though).
Questions like this have been asked many times before. Even I have had a go at asking this question [1], and you may find the answers there helpful (and there are plenty of links to other similar questions too, which also probably contain useful information).
As other people have pointed out, this practice does have some issues that you need to be aware of:
Still, this is not to say that this is a bad idea. I do actually think that having these standard problems is a good idea, as it means that there will be a few programs that you understand how to solve, so the challenge is in coding the solution and working out the correct language constructs to use.
I think the important thing for the problems is that you must find them interesting. One idea that I once heard was to write a simple Twitter client for each new programming language you attempt to learn. Or, you could write a program to solve Boggle [2] or any number of simple games like this.
[1] http://stackoverflow.com/questions/1031926/standard-programming-problems-for-learning-a-new-languageI generally try to implement a Cribbage hand evaluator, and then determine what an average Cribbage hand value is (for, say, 10000 hands). AS stated, this exposes you to the math functions, lists, arrays, output, and input. If I am feeling ambitious I will do some sort of statistics on the spread of hand values, standard deviations, means, etc.
By far the best application to write to become fluid in a language is.....Hello World, of course!
Just kidding :)
System.out.println
? Even in Ruby where everything is an object there is a simple puts
- Earlz
I'm a big fan of math functions. An easy one to start with is the Sieve of Eratosthenes.
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Doing some easy math functions not only helps in learning syntax but also helps in learning some of the basics of the language like how to print output to the console, gather user input, etc.
Maybe Minesweeper. Or something which explores the data structures and specific logic for the language (like a ticking system with lists, stacks, etc)
While this isn't perhaps a direct answer, I might start with a program or programs to answer your own question. What i mean is, that I learn the most from trying to solve problems that I'm actually interested in solving, not simply going though a list of arbitrary problems. You might start by figuring out some basics, like:
There are endless possibilities, and you would no doubt encounter many features of a language by going down this route. By the time you got through just a bit of it, you'd probably feel like you had a good grasp of the language.
The down side here is that there isn't a clear right/wrong solution, but that's often the case in real world programs. :)
I read somewhere about someone who implements Tetris in every new language he learns.
If you are interested in Microsoft Languages then probably you should start from their learning site. http://msdn.microsoft.com/en-us/beginner/default.aspx
hope this helps.
I try to write a very simple lisp interpreter for every language I learn. It gives you a nice range of skills. It can be broken down into 10 stages if you want :)
I like the idea of having the same set of things to learn. They become like a kata practised in different ways. I gained a new understanding of lisp with each new implementation.