Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Any reason to use C?

Author: Hristo

Date: 22:38:22 07/29/03

Go up one level in this thread


On July 29, 2003 at 16:53:05, Vincent Diepeveen wrote:

>On July 29, 2003 at 03:15:54, Hristo wrote:
>
>>On July 28, 2003 at 19:12:56, Vincent Diepeveen wrote:
>>
>>>On July 28, 2003 at 17:34:46, Russell Reagan wrote:
>>>
>>>>Is there any reason to start new projects with C anymore? It seems like most (if
>>>>not all) of the drawbacks of C++ have faded away with modern compilers.
>>>>
>>>>Note that I am talking about new projects, and maintaining old projects is
>>>>obviously a good reason to still use C.
>>>
>>>If i would learn coding today i would prefer C++.
>>>
>>>However let's be clear, for good programmers there is not much diff between C
>>>and C++. Every complex problem which you can solve in 10000 lines of C++ you can
>>>solve in 10000 lines C too.
>>>
>>
>>Vincent,
>>with all due respect I must disagree. In 10K lines of C++ code one can solve a
>>much more general or larger set of problem(s) or cram in more features. :)
>>(think templates, exceptions, and often inheritance ... all of which can shorten
>>your code)
>
>I do not know about you, but i program both in C and C++.
>
>Do you?
>
>Not a single program where you can use all the nice toys you can also make a few
>functions for in C.
>
>In general the average programmed C++ program you program more compact in C.
>

dido!

>That's not what i'm talking about.
>

The way I understood you is that anything you can do in 10000 lines of C++ code
you can do in 10000 lines of C. This is what I disagree with.

>If you do not know how to program in C, then just say it loud instead of writing
>it down like this.
>

I do know a thing or two about C. :-)
Consider this to be a free jab on your side. Enjoy.

>the advantages of what you mention here (assuming 1 man products) you can show
>great in 50 line examples or even 200 line examples.
>
>But as soon as you write a 10000 line product then it doesn't matter what you do
>in C++. I can do the same in C too. No problem!

You will do less! The overall difference might not be as large as in a 50 lines
of code, but there will be difference.

The issue, at least to me, is that some times it is easier to write 500 lines of
C code than to write 200 lines of C++. The last time this happened was years
ago, but it still happens.

>
>>In your post, latter, you indicate that C++ offers some advantages over C,
>>especially for large projects. In my experience this is %100 true, so we are in
>
>I see no other advantages to C++ than for big projects in fact.

True. The bigger the project the more advantages C++ has and therefore when you
reach the 10000 lines mark you are better off with C++.

>
>The advantage is *really* huge there for companies.
>
>Given the importance of those companies for the world, the choice to teach
>students C++ instead of C is a logical choice.
>
>teaching them Java, delphi i find a bad idea.

Java is "funky" but not that bad. The transition from Java to C++ is possible.
The Delphi thing, if it is still with Pascal back-end is questionable.

>
>sometimes fortran is needed though because all libraries are in fortran.
>
>>agreement, but C++ offers extra features at all levels and C++ often imposes
>>performance penalties because of it. Sometimes C is better because you don't
>
>You should realize that if i understood well, some early C++ compiler generated
>C code out of it which then was optimized further.
>
>There is really *nothing* which C++ offers that you can't get to work in C
>either. If a product becomes bigger (10000+ lines) then you can create in C a
>lot of functions which you can reuse everywhere.
>

You have to build the infrastructure to handle function pointer tables,
Constructor/Destructor semantics, virtual functions and inheritance, function
overloading, operator overloading, exceptions, etc. Perhaps you can write all of
this from scratch, using plain C and then on top of it write your application
specific code and yet still make it all fit in the same amount of lines. While
you are it you might as well add templates (???) ... even if you manage to do
this, the only thing you'll achieve is recreate C++ and hence you'll be
programming in C++. If you use C only then you'll probably end up writing more
lines of code than if you were using C++.

You can reuse C code! I'm not arguing that.

>So where you focus upon 1 feature that C doesn't have, the savings that C books
>is in the functionality below it, because the product is designed in a different
>way.

I'm not bashing C. In fact I enjoy writing some functions or small parts in C.
It works well, especially when building "glue" code.
Products are never valued because of the language used in their creation. So a
good product would sell even you it was created with Visual B.

>
>>have to deal with the _nice_features of C++. If speed and size are important
>>then C, even assembler, might be the right choice. However, beginners in the
>>field (programming) believe they can d a better job at implementing already
>>available features/functions...
>
>In general i find assembler a bad idea to use.

For a whole project, yes. But assembler has its place.

>
>It is a public secret that most C++ projects tend to use too much code to get a
>simple thing to work. Way more than they could need. This is true. But usually
>commercial projects are programmed by employees who must write each hour.
>
>>BTW,
>>there is another paradigm "Objective-C" which is, in some cases, absolutely
>>amazing way of doing things, but it could get slow and cumbersome.
>>More features always cost something and the cost is usually speed. ;-)
>
>In general the average programmer has no idea bout speed. They do not even know
>how to loop through an array usually taking advantage of features like fall
>through of the processor. It isn't easy indeed.
>
>So taking that into account such high level languages like C++ and objective C
>and smalltalk and java are very slow indeed.

C++ and objective-C have no limitation when optimizing a particular function or
aspect of the application. In both cases one can drop all the way down to
assembler. Those languages provide a different approach(es) to solving the
"same" problem.

>
>>Regards,
>>Hristo
>>
>>>No big deal.
>>>
>>>Only some 50 line examples C++ looks more powerful.
>>>
>>>However for large projects there C++ is really a major advantage. If one
>>>programmer messes up his object then for large projects the type checking and
>>>array checking is way easier.
>>>
>>>Of course the extra features in c++ means theoretical that there is more chances
>>>to mess up and to create hidden bugs which are real hard to find, more than in
>>>C.
>>>
>>>In that sense C and C++ are the same.
>>>
>>>I wrote a big athletics time tracking program in C++ when i was 17 years old. it
>>>was finished when i was 18 and they didn't need it by then as they had already
>>>some better commercial solution then (the athletics club).
>>>
>>>However when i was 15,16,17 i had written a big chess interface, which when i
>>>was 20 would be using for DIEP. For those days the interface was great.
>>>
>>>VGA support even.
>>>
>>>By modulair setting up the engine i ensured that at university i could run the
>>>engine without graphical interface.
>>>
>>>Note that under dos i had no option but to INTEGRATE the interface and the
>>>engine. So i have a diepasci.c, my dos text interface i/o which is even till
>>>todate existing, which is just:
>>>  19-07-2003  19:56               21.884 diepasci.c
>>>
>>>And i had a 140KB diepmenu.c which was the graphical DOS interface which i could
>>>exchange for diepasci.c
>>>
>>>Both having the 100% same functionality.
>>>
>>>Great work at the time when DOS didn't know the word multithreading or
>>>multiprocessing yet.
>>>
>>>So there really isn't a difference for a one mans product at all if you are good
>>>in dividing and conquering.
>>>
>>>However for large projects i really see the advantages of C++.
>>>
>>>Reality will be however that even the best set up c++ projects will suffer from
>>>the same bugs a C project would. Yet it is at least a bit more clear now who to
>>>blame for bugs B.
>>>
>>>In a one mans product that is not the case.
>>>
>>>So as most of us won't be writing one mans products only, C++ is trivially
>>>better to use.



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.