Complex Programs with Simple code?

Chessboard

After my last post, i was wondering if really complex programs/systems/applications could be written using simple, easy-to-understand code. Code that does not span more than 10 lines a method.

The most complex program that i could think of to experiment with was a Chess server – an app that would evaluate a position and suggest the “next best” move. This app would have a set of rules which would determine how good a position is. All possible “next moves” will be stored in a tree and evaluated on the position they end up with after ‘n’ moves. For more information->http://en.wikipedia.org/wiki/Computer_chess

I have created an open-source project on sourceforge.net for this activity->http://sourceforge.net/projects/javachessserver. What i have in there so far are the Chess domain objects, Rule interface, several skeleton rules and one concrete rule->CheckmateRule

I would be interested in knowing what you think about this project. If you are interested in joining this project and wish to explore this idea, i would be happy to include you.

Tags: , ,

2 Responses to “Complex Programs with Simple code?”

  1. I think you’re right on the money thinking you can follow this 10 lines per method rule. Reading your code it’s fairly easy to understand and I like how you’ve named your sub-methods with very descriptive names (i.e. inside “isCheckMate” you call “isKingUnderCheck” “isAttackingSquareTakeoverPossible” and “isKingMovable”.

    I have found when writing my own code that not only is it possible to write code this way but when you follow TDD its actually easier. Each test I write usually forces me to write only a few lines and at most one IF statement. The only code I’ve writting in the past 6 months that does not look like this is when I’ve “forgotten” to follow TDD. I’ve found that when I nest logic (if statements or loops) and then try to write tests I realize the number of possible scenarios to test has exploded. So I go back and refactor it to look more like what you have and give myself a slap on the write to do TDD the next time.

  2. amar647 says:

    Thanks for the insight Alex. Fully agree with your thoughts on TDD. I am hoping to use TDD for the remaining rules that i write.

Leave a Reply