Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Any idea's on how long it takes to learn C++, then create a chessmon

Author: Tord Romstad

Date: 06:43:14 12/12/01

Go up one level in this thread


On December 11, 2001 at 03:07:36, David Rasmussen wrote:

>On December 10, 2001 at 15:40:09, David Hanley wrote:
>
>>
>>Robert.
>>
>>Everyone had their chess program written in C/C++.
>>
>>I'd say use something else.  C/C++ is really a high-level assembler.  It
>
>No it isn't. Especially not C++.
>
>>sacrifices a lot of programmer time to make your code run faster.  But even
>>running twice as fast won't make your prgoram a LOT stronger.  But it will make
>>your programming take a LOT longer.
>
>Not necesarily.

For a person with wizard-like abilities in C++, maybe not.  For the rest
of us, this is definitely the case.  I guesstimate that I would spend at
least 5 times more time writing a C++ chess engine from scratch than a
similar Common Lisp engine.  And I have spent much more time learning C++
than learning Lisp.

>Smalltalk, CommonLisp and SML are all nice languages in their own respect, but
>there is no reason to choose any of those instead of C++.

There are a lot of reasons.  On the top of my head (I am not very familiar
with Smalltalk and SML, so I will limit my discussion to Lisp):

1. The edit-compile-link-run cycle when developing a C/C++ program is painful,
frustrating and time-consuming in the extreme.  A Lisp-like interactive
environment with a top-level in which you can evaluate expressions, quickly
define and execute functions to test your code, and the ability to compile an
individual function or method (I find the ability to modify the program while
it is running especially useful) is a huge help in developing complex programs.

2. Optional type declarations make your life a lot easier.  When programming
in C/C++, you are forced to decide the type of your variables very early in
the development, at a time when it is often difficult to guess what choice is
right.  It is much more convenient to be able to avoid cluttering your
code with type declarations at first, and add them later when you have a
working program.

3. The C/C++ syntax is painful to work with, compared to the much simpler
syntax of Lisp.  One of the main advantages of the simple syntax is that
editing source code is much faster and easier.  When editing Lisp code, I
can navigate, copy, cut and paste by expressions rather than using a more
primitive line- and character-based editing style.  Another fundamental
advantage is that the simple syntax enables the powerful Lisp macro system.
In C++, there is no easy way to manipulate code as data, or to write code
which writes code.

4. C++ has (AFAIK) no analogue of the special variables in Common Lisp,
which I find a serious handicap when developing large programs (particularly
multi-threaded ones).

5. First-class functions are sorely missed in C++.  This makes useful
programming techniques like memoization difficult to implement.  Also,
the lack of anonymous functions make the use of functions like qsort()
much more inconvenient.

6. C++ functions do not support keyword arguments.  As a consequence, it is
often difficult to extend the functionality of a function without rewriting
several other parts of your program.

7. C++ has a rather underpowered object system.  For instance, last time I
checked, there was still no multiple dispatch, no before-, after-, or
around-methods, and no ability to change the class of an object at runtime.

8. The READ function in Lisp (mentioned elsewhere in this thread).

9. GC (also mentioned elsewhere).

I do not doubt that C++ can be a very powerful tool in the hands of a
sufficiently good programmer, but is a phenomenally difficult language to
learn.  Mastering C++ is certainly far beyond my capabilities (and I have
tried really hard).

On the other hand, I do find C to be a useful programming tool.  I would
never consider using C in the early phases of development of a complex
program, but I often use it to micro-optimize performance bottlenecks in
my code (only when I am 100% sure I am satisfied with the algorithms and
the data structures, of course).

>The nice thing about this is that you will have learned C++ instead of SML,
>which is always a good thing :),

Why?  I certainly wish I had learned SML rather than trying to wrap my mind
around C++.

>and also you will be geared for performance
>from the beginning, without focusing on it. Also, C++ has a much larger
>community and a broad support in tools and compilers, moreso than for any of the
>other languages.

Concerning compilers, you definitely have a point.  The quality of
contemporary optimizing C/C++ compilers is superior to almost all compilers
of other languages.  Regarding other tools, I don't agree.  I have never
seen a C/C++ programming environment which comes even remotely close to
Macintosh Common Lisp in terms of elegance, ease of use and ease of learning.
Xanalys Lispworks (which I use at work), although visually ugly, is also
a pleasure to use.

> And you will not have been forced to use only one style
>(Object-Oriented or Functional) that may not fit the problem at hand.

This statement puzzles me.  One of the most central design principles of
Common Lisp is to provide a multi-paradigm language.  The user is free to
program in imperative, functional, object-oriented or logical style,
depending on taste and the problem at hand.  C++, on the other hand, seems
much less flexible in this regard.  You can do imperative and object-oriented
programming, but other programming styles are IMHO not at all well supported.

Tord




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.