When I start learning a new programming language
One does not simply start to learn a programming language.
And this is the same for me. When I start learning a new programming language I read a brief tutorial about the language (or not, depends on my mood) and then I make some sample projects with that language.
This article is about which pet-applications are ideal learning a new programming language.
With ideal I mean my own programming experience. So here I will list my pet projects I implement when I want to get seriously involved with a programming language.
Reverse plolish notation calculator
This is a simple sounding pet-project but it requires some data structures as stacks and lists. I ranked it on the first place because it only needs simple user input and nothing else which is not included in the core of the language. Or with unit-testing you can even forget the user input.
The application is a calculator based on the polish notation. The input is a less or more complex mathematical formula (with postfix notation) which is solved using the reverse polish notation algorithm and the result is printed to the console (or in a unit test where it can be validated with an assertion).
And this application is expandable with Dijkstra’s Shunting-yard algorithm, which takes a formula with infix notation and converts it to the postfix notation used by the reverse Polish notation calculator as input.
Guess the number
A simple game. Here I use basic concepts of the language such as random number generation, variables, integers, loops, if-else constructs, and console based user input.
Naturally, you cannot create a game without input of the user, so this is a crucial point of development: how to read the data and how to parse / convert it.
So I suggest you to create a simple “Guess the number” application if you try to learn a new programming language.
Some hints for the development:
- for numbers between 1 and 100 choose a maximum guess-count of 7
- for numbers between 1 and 1000 choose a maximum guess-count of 10
- general: for a range of n choose a maximum guess-count of int(log(n,2))+1
Similar to “Guess the number” is “Hangman” which is a guess the word game. The concepts used here are almost the same than in “Guess the number”: random, variables, loops, if-else. And it is extended with strings and characters.
To represent the hangman is not a must for this application — you only have to limit the guesses. You can improve the application later with displaying a hangman after each guess. This can be done on the console with ASCII-art or if the programming language has a GUI you can add a drawing (simple shapes) or a changing image.
A luck-game — as it is for rock-paper-scissors. Here the user can input something and the computer makes a random decision too.
You can improve the game in various ways:
- extend the normal rock-paper-scissors game with lizard and Spock
- make your computer always winning (this can be annoying for the user so make your application cheat sometimes)
- create a graphical user interface where you display the possible hands and the user can choose and you display the opponents hand as an image too
- make it a multiplayer game — eventually over the internet
The simplest card game I know is Blackjack. Here you use the same techniques as previously extended with a list or a queue (stack if you like). You can vary the implementation to reshuffle the deck after each game or when the number of remaining cards is under a given limit. If you want to go further you can shuffle on demand, when the deck is empty — and do not include the visible cards.
There are many variations of Blackjack. For further gameplay or just for fun you can introduce several of them and make them default or let the player choose which variation he/she would like to play.
And again, you can make this game to have a GUI and/or make it multiplayer.
Conway’s Game of Life
OK, this game is a bit out of the normal game-scope and it is a bit more complex than the previous ones and it is not really a game. But I like to have something complex at the end to see if I understand the programming concepts and can work with threads for example.
I have written a GUI for a Game of Life backend but the backend is interesting too. Here you work with multidimensional arrays or multiple lists, you can make it object-oriented or plain functional.
There are many pet-projects you can implement with a new programming language. There are many features you would not cover with such a simple game — but with a working experience (or need). But for the start these are good — and feel free to rethink and improve the simple games.
And there are much other simple applications and games you can think of and implement (mastermind, poker, battleship, etc.). If you find something funny tell me, I’ll take a look and try to implement it too.
And I do not think that a text based adventure game should take its place in the list. This is because if you want a good game you have to invest much of you time because there are so many ideas for rooms, enemies, tools and so on that you can get overwhelmed. And an unfinished project can be bad if you are trying to learn a programming language.
Note: this only works if you write the code yourself. There are many sources available on the Internet but you will not learn anything if you do not write the applications yourself.