views:

485

answers:

9

I'm wondering if there's any good exercise to test and improve one's ability to code? I'm think specifically about program logic and being able to write good OOP code.

I thought about writing a simple HTML parser, but it seems that's more of a challenge then it sounds.

Anyone got any idea's of something that would test & improve my ability to code effective code?

I know there's Open Source projects, but is there some kind of exercise that exists?

+10  A: 

My personal favorite is project Euler

Lots of small thought provoking puzzles to solve in code.

JaredPar
Definitely true.
Dario
Project Euler is more about math and code optimization problems than writing clean OOP code (which is what the OP is asking for).
SnOrfus
+4  A: 

The Code Kata is a generally accepted method for practicing coding. There is also Project Euler.

As for good OOP practices, there are great books out there. Combine that with gigabytes of professionally-designed open source projects (found on Codeplex, GitHub, SourceFourge) and there is plenty of food for thought.

Dave Swersky
You beat me to suggesting Code Kata. +1 for you =]
James Hollingshead
A: 

Try searching for code katas -- these are short exercises that should be repeated, improving each time you have another go. I personally like this checkout example. The idea is that you implement a checkout for a supermarket, dealing with things like special offers.

Michael Williamson
+1  A: 

Anything you code helps. The trick is finding something interesting enough to keep at it.

Lately a good option I've found is XNA. You can download the SDK, and it integrates nicely with Visual Studio. You can use it for Windows games as well as XBox games. And you end up with a game you can play (instead of a boring database application or something). I use it to write small games for my kid, who currently has reasonably simple tastes.

Kyralessa
Although XNA is nice, it will not help you to learn how to design in OOP very well, since xna is not 'that' object oriented.
Frederik Gheysels
It is if you make it so. I made a little cat-chases-the-mice game for my kid, and while I started out with just Texture2D and stuff, I soon ended up with Cat and Mouse classes because they had distinct behavior. You can get experience creating specific classes and in refactoring to pull up common behavior into base classes.
Kyralessa
Also, I'd repeat the advice I gave here: http://stackoverflow.com/questions/1772791/solitaire-game-design/1772855#1772855 Making OO code isn't a matter of identifying a bunch of objects and then figuring out what they do. The best design will grow organically out of the behaviors the software needs. As a beginner, it's easy to think you should start by creating a bunch of classes that correspond to real-world objects. But the result of that is writing a lot of code that doesn't actually *do* anything.
Kyralessa
A: 

You could try doing the Code Golf problems on here, but instead of obfuscating, try to write the best structured program possible.

Jon Seigel
+7  A: 

Why "exercise" when you can just do the real thing? Anyone can code simple parsers, simple math problems, whatever. If you want to practice your OOP then I suggest building a useful (to you at least) multi-tier application or tool - but do it in steps.

Start with a simple game that you like to play with your friends. Chess? Cards? Doesn't matter. Build an engine for it; write some tests. Try to apply the best OOP practices you can (if that's your goal).

Once you have an engine you can then add a neat GUI to it. WPF or Silverlight would be a great start to this. You could even decide to do it with HTML/JavaScript if you want.

Now that you can play the game locally, add the ability to play over a network or online. You'll notice you need to save game state at some point, this would be a great time to add in a database or whatever storage method you feel is appropriate.

This process of expanding will eventually teach you more and more about fundamental OOP practices when you realize you have to go back and refactor some code that may eventually become difficult to work with as the application scales.

John Rasch
+1 Get something complex enough done instead of playing with brain teasers and narrow-use algorithms ^^
Oskar Duveborn
I think this is an excellent idea, it is better to take it seriously by doing something that is going to help you. I was thinking in something not only useful but give a better understanding of thing and improve my skills.
nmiranda
+1  A: 

If you're looking for code quality/style, readability, maintainability and OO design then there is no better exercise than just making something and getting the code into someone else's hands (they'll help be the judge of the aforementioned criteria).

If you have any projects that you've always wanted to work on, or software that you like that seems like you could duplicate it, or something that you've even made before but you could have made it better then you've got a good exercise already. The key to know if your 'exercising' is producing positive results is to get it into someone else's hands and talk to them about it.

Additionally, working through books on OOP topics might be a good idea - especially the types of books that produce a piece of software throughout it (Here is an example of one such book)

SnOrfus
+1  A: 

One method is to show them a poorly written project and ask them how they would do it differently. This will test their ability to read code, analyze the problem, and work a solution.

Here's a Java example. http://code.google.com/p/ugly-and-clean-tictactoe/

Gabe
+1  A: 

I'm wondering if there's any good exercise to test and improve one's ability to code? I'm think specifically about program logic and being able to write good OOP code.

One of my favorite exercises to prove to myself that I've learned a new language is to write a ray tracer (if you've never written one before, check out the pseudo-code in Andrew Glassner's book from quite some years ago).

Ray tracers are nearly ideal for demonstrating OOP prowess but they also open the door to all sorts of other interesting problems:

  1. Concurrency: each ray can be treated independently so, depending on your implementation, you can scale your rendering to fill your available compute resources.
  2. Image processing: given that the problem is to generate synthetic images, you have to learn how your new language handles pixels and images.
  3. Numerical or bit-wise accuracy: if you aren't using some sort of random sampling, an image generated for the same virtual scene using implementations in different languages should be pixel-indentical.

Finally, the ray tracer has nearly infinite opportunities for self-challenge. Do you want to demonstrate optimization prowess? Show how you can make your own code 10 times faster. Physical modeling? Demonstrate how you would render moving and colliding images using your new renderer.

In short, it's a great OOP application space and has the additional visual benefit of being visually fun to work on.

Bob Cross