I'm not sure this comment actually means that we should prefer a programming language over an other. As Steve McConnell says in Code Complete 2:
"Program into your language. Not in it!"
By this he mean abstraction to data types. What the GNU Backgammon code is missing is real abstraction of backgammon types. There should be a type for a position/board, there should be a type for a move, there should be a type for outcome probabilities, there should be a type the dice, there should be a type for a roll, there should be a type for the doubling cube, there should be a type for an action, there should be a type for a board point, there should be a type for a player there should be a type for a game, there should be a type a match, there should be a type for.....( you get the point -- fill any _backgammon_ related term. )
There should also be some interfaces. One I can think of on the top of my head is "evaluate". Evaluate should be an interface and all functions that can evaluate a position should implement this.
In the above paragraphs "type" does not necessarily mean "class" in C++. Nor does it mean typdefed struct in C. "Interface" in the above paragraphs does not necessarily mean an abstract class with only virtual not-implements methods in C++. Nor does it mean a function pointer to function in C (or any similar trick to mimic abstract behavior). The point is that it should be abstracted out of the mind of the coder, such that the coder can think about the backgammon logic when coding.
A ok code of backgammon in _my_ language will then be like this:
board_t *board = board_new( INITIAL_BOARD );
evaluator_t *eval = gnubg_evaluator_new( STANDARD_CONFIGURATION );
dice_t roll = dice_new( 3, 1 );
move_t best = find_best_move( eval, board, roll );
printf("Best move is: %s\n", move_to_string( best ));
/* I just made up this code based on the abstractions I listed in the paragraph above. Note the syntax is C. */
/* The code is not tested or compiled or anything since I don't have the types.... */
Hopefully the above code will output:
Best move is: 31: 8/5 6/5
Let me make up the same program snippet with C++ syntax:
Board board = Board();
Evaluator* eval = new gnubg();
Dice roll = Dice( 3, 1);
Move best = eval->find_best_move( &board, &roll );
std::cout << "Best move is: " << best;
// I just made up this code based on the abstractions I listed in the paragraph above. Note the syntax is C++.
// The code is not tested or compiled ... And my C++ is a bit rusty, so there probably bad errors.
As you see. There is really not much difference. The code is in _my_ language, defined by the data types, not the programming language I'm using. Maybe I can even swig (is swig a verb? www.swig.org
) this and have a Python interface. If I did, the code would be nearly exactly the same, just another syntax.