Do you have any programming "exercises" that you do in order to hone your programming skills? Anything from FizzBuzz [1] to more complicated problems to get you thinking about real-life scenarios that you may encounter?
A lot of great suggestions are archived in this question [1] about teaching beginners. Particularly the bits about what projects you should try for beginners.
Here is a summary of some resources out there for programmer practice.
Another great technique for practice is to repeat problems using a different language or technology, or a different approach.
[1] http://stackoverflow.com/questions/3088/best-ways-to-teach-a-beginner-to-programPushups: Gets the heart pumpin', the mind workin', and wears out those wrists encouraging you to keep the code concise and avoid redundant comments.
Darts: Strengthens your wrists, so you don't become crippled after too many push-ups / redundant comments. Plus, you can (and should) drink while playing, allowing you to hit that elusive Ballmer Peak [1].
Mavis Beacon Teaches Typing: Oh... Mavis...
[1] http://xkcd.com/323/Jeff Bay, in the Thoughtworks Anthology [1] has a nice set of 'rules' (object calisthenics) to follow to get your code back to a more object oriented state. It's an exercise to help change the way you think about structuring your code, and give you better OO habits when writing real-world code. The ideas is to right 1,000 lines of code while imposing the following constraints:
Use only one level of indentation per method. If you need more than one level, you need to create a second method and call it from the first. This is one of the most important constraints in the exercise.
Don’t use the ‘else’ keyword. Test for a condition with an if-statement and exit the routine if it’s not met. This prevents if-else chaining; and every routine does just one thing. You’re getting the idea.
Wrap all primitives and strings. This directly addresses “primitive obsession.” If you want to use an integer, you first have to create a class (even an inner class) to identify it’s true role. So zip codes are an object not an integer, for example. This makes for far clearer and more testable code.
Use only one dot per line. This step prevents you from reaching deeply into other objects to get at fields or methods, and thereby conceptually breaking encapsulation.
Don’t abbreviate names. This constraint avoids the procedural verbosity that is created by certain forms of redundancy—if you have to type the full name of a method or variable, you’re likely to spend more time thinking about its name. And you’ll avoid having objects called Order with methods entitled shipOrder(). Instead, your code will have more calls such as Order.ship().
Keep entities small. This means no more than 50 lines per class and no more than 10 classes per package. The 50 lines per class constraint is crucial. Not only does it force concision and keep classes focused, but it means most classes can fit on a single screen in any editor/IDE.
Don’t use any classes with more than two instance variables. This is perhaps the hardest constraint. Bay’s point is that with more than two instance variables, there is almost certainly a reason to subgroup some variables into a separate class.
Use first-class collections. In other words, any class that contains a collection should contain no other member variables. The idea is an extension of primitive obsession. If you need a class that’s a subsumes the collection, then write it that way.
Don’t use setters, getters, or properties. This is a radical approach to enforcing encapsulation. It also requires implementation of dependency injection approaches and adherence to the maxim “tell, don’t ask.”
SPOJ [1] - has much of the same ACM problems, but has code submission in a large number of programming languages.
[1] http://www.spoj.pl/A series of 20+ code katas are available from the Pragmatic Programmer folks here [1]. I particular like the Supermarket Pricing challenge ($3.00 each or 2 for $5.00) kind of stuff. As Dave says:
[1] http://codekata.pragprog.com/How do you get to be a great musician? It helps to know the theory, and to understand the mechanics of your instrument. It helps to have talent. But ultimately, greatness comes practicing; applying the theory over and over again, using feedback to get better every time.
some general questions that I found fun:
1) Reversing a string in place -- using no swap (this is prb a C question)
2) reverse a linked list (iteratively)
3) reverse a linked list (recursively)
4) converting strings of numbers to ints (character by character, don't cheat and use a class library)
5) splitting a string of strings into an array of strings
6) converting milliseconds into hours, minutes,seconds, and remaining milliseconds
7) join a 2D array of strings into one string
8) given a function:
float getAngle(int hours, int minutes) - return the angle between them if the hours and minutes were represented on a regular clock. Example getAngle(12, 15) would return 90.0
I'm a programmer and I have several web projects. I don't need external excercises to keep me busy. If I feel that I should do something I just take one of my projects and improve it:
Really, I don't need to write another sort algorithm when there are so many interesting "real world" problems to solve.
You should try that and be creative yourselves. Maybe you are the first to develop the 100% spam protection mechanism?
I like Programmer Puzzles [1] on forums, this way you can see other people's clever(or not) answers
[1] http://forum.lessthandot.com/viewforum.php?f=102I hear that CipherSaber [1] is a good programming exercise. Try implementing that in a variety of languages! (My picks, for the sake of choosing extremes in the abstraction continuum, would include Scheme and assembly language.)
I've recently taken to implementing MD5 [2] and its related MD4 [3] functions. The skill is not in coding it as such (although it's always nice to see that the test vectors pass):
Once you run out of languages to try, you can then try to implement SHA-1 [5], again refactoring commonalities (SHA-1 is very similar to MD5).
After that, perhaps SHA-2 [6]? Refactoring your hash system to accommodate the SHA-2 family would be interesting…I'll say no more. :-)
[1] http://ciphersaber.gurus.org/I once participated in an ACM programming contest.
To practice we went through questions from UVA online-judge [1]. It provides a huge list of problems and allows you to submit your answers to see if they are correct. I do believe it supports C, C++ and Java submissions. The questions deal with graphing problems, number crunching, simulations, etc. Half the battle is trying to figure out what type of question it is.
Here are a few [2] sample [3] questions [4].
For some puzzles that arent necessarily programming but you may run into at interviews check out http://techinterview.org/
There are some good puzzles at ITA Software [1]. If you do well, they might offer you a job.
[1] http://itasoftware.com/careers/SolveThisWorkHerePuzzles.htmlHaven't seen this mentioned: http://www.challenge-you.com/
It's built on the Google App Engine. I like the part where it gives a breakdown of the submissions by language.
How about these challenges?
The book Programming Interviews Exposed [1] contains a number of good exercises to brush up your programming skills.
[1] http://rads.stackoverflow.com/amzn/click/047012167XI found www.hackthissite.org/ [1] to be pretty fun.
They have various challenges including:
You also learn a lot of useful security related stuff, so it's both fun and useful.
This should keep you busy for a couple of months at least! :)
[1] http://www.hackthissite.org/Here are the lists of programming exercises [1] for beginners and problem with algorithm [2]
Hope this helpful.
[1] http://www.tesear.com/2011/11/list-of-programming-exercises.htmlMy standard exercise when learning a new language has been to write a Mandelbrot set app. Done it in BBC Basic, Turbo Pascal and, recently, C# among others. The TP version was the most optimised with all sorts of approximations going on, but then it was running on a 12MHz 286 or something.
I worked through some of the Python Challenge a few years back. That was fun.
It depends on what kind of skills you want to work on...
Project Euler is good for building math and problem solving skills. If you are a web developer, building your own webserver will teach you a LOT about lowlevel HTTP, which can't be a bad thing. Choosing a language and implementing it is a great way to learn all about the deeper aspects of programming. A subset of scheme is fairly easy to implement, or, you could even implement one of the wierder languages like brainfuck for befunge. Implementing tools for programming is another excellent exercise. Editor plugins are pretty easy to do, and a good start.
Topcoder and ProjectEuler.
Topcoder is a challenging environment where you can be prized and eventually hired... but the competitors are incredibly strong!
The Scripting Games [1] by Microsoft are held every year. You can also look at past years' problems and solutions and exercise your Perl, VBScript and Windows Powershell skills.
[1] http://www.microsoft.com/technet/scriptcenter/funzone/games/default.mspxI wrote all my favorite exercises down in my Building Skills [1] books.
[1] http://homepage.mac.com/s_lott/books/index.htmlFind some old software you've written, and expand it so it can send and receive email.
One thing I like to do with my college friends when we want to practise optimisation, or more commonly when we want to learn a new language, is we write programs to generate primes (usually using eratosthenes sieve or some variant thereof). Whoever has generated the largest prime by the end of the night wins! While it seems a fairly simple algorithm, there are a lot of small optimisations you can make (especially in languages a bit closer to the machine, like C). If it's a scripting language we play prime number golf (writing the smallest program we can that outputs primes).