   Language Impact in System / App / Game Programming: Evaluating (and Critiquing) C
  I've been programming in most languages for a long time, and recently i've found surprisingly that most well known games / operating systems / frameworks are still written in C. By example: most of GTK+/GNOME, Linux (Torvalds is one of the most fervent defenders of the goodnesses of C for the projects of Linux and Git), and when a new hardware platform arrives, the first that is done in software is usually a C compiler.I'm not unaware of the disadvantages of C, by example, the micromanagement of memory, the lack of garbage collection, the lack of builtin complex data structures, and many others. But i'm too aware of its strong points: its syntax became almost a standard, it doesn't forces any programming paradigm on you, its very few keywords and relying in code libraries for all tasks (revolutionary at its age of creation among languages with dozens of keywords to memorize like BASIC and LOGO), its ease of optimization.I want to get an informed, educated critique of the C language and its place today, including but not limiting to:- Best practices- Uses and places where it performs the best in a world overtaken by C#, C++ and Java- Comparisons with other languages- Possible successorsThanks in advance,Sam   
  Exactly which well known games are written in C and not C++?They are not the same language.   ;Quote:Original post by xhyldazhk... when a new hardware platform arrives, the first that is done in software is usually a C compiler.There's an obvious resaon for this:  what language are you going to use to write your Java or C# interpreter in?  What language do you write the C++ runtime in?  The answer is C.  So, first bootstrap a C compiler using a cross compiler, then port your Java interpreter or RTL assemblies or C++ runtime, then use your native C compiler to build native versions of the other languages.That's also why all the fancy new "high level" languages have a trap door that allows you to "drop down" to C to write native code (well, C++ doesn't, but it's neither particularly new nor high level).When it comes to comparing C and C++, there's nothing C can do that C++ can't, so it's hard to imagine a world where C performs better.  Remember that except for some additional keywords and a few minor semantic differences, any C program is a C++ program.  The two languages have different idioms, and an expert in C is unlikely to write good C++ code and vice-versa.--smw   ;Quote:Uses and places where it performs the best in a world overtaken by C#, C++ and JavaEmbedded market. Everywhere else, it's used only to support legacy applications. Starting a new project in C today is very suboptimal solution.Quote:- Comparisons with other languagesobsolete. With lack of even basic modern (developed in last 20-30 years) paradigms, it offers nothing that could be used in modern application development. Everything that can be done in C can be done faster, cheaper and more reliable in and of the modern development platforms. Note: Nobody writes an OS. And GTK/GNOME have been desktop ready for last 10 years. They just need a bit more polish, and have for the last 10 years.Quote:Possible successorsC++ has replaced C. Businesses have adopted C# and Java, along with Ruby and other similar solutions. Scientific domain likes Python.Otherwise - any memory managed, concurrency-enable language.Quote:- Best practicesDon't use C.Quote:its syntax became almost a standard, I wouldn't bet on this. Visual Basic, Flash and other non-C languages probably have more programmers than C/C++/C# crowd.   ;  Interesting answers.legalize:Doom, Quake and Quake2 are the most known of them IMHO. Almost any new system gets a Doom engine for it. And I'm aware they're not the same, C++ is way bulkier, and making a compiler for C++ ys much harder.Bregma:I would be interested in knowing about that 'trap doors' in higher level languages  to C. I know about Chicken Scheme that compiles itself to C, and SWIG that generates interfaces from C/C++ to some scripting languages. Which other usable, suppoerted languages compile to C code, beyond Chicken Scheme and Eiffel?Antheus:Still hardware is far easier to acces by C. SDL, OpenGL are examples of that. I am aware that coding directly in C is suboptimal, coding in functional style ala Lisp/Scheme in C is simply impossible because the stack would be blown before the end of most tail recursions, but what about coding on high level languages that compile themselves to C? That is a compromise between portability and ease of use. Concurrency is another big problem because AFAIK pthreads, the most standard threading library in C, is not optimized in all platforms. And it uses system threads that are expensive. I don't know yet of a library of quick, cheap threads that doesn't share anything (like in Erlang) for C. The real reason for this thread is that i want to do onboard development on my Gamepark Holdings GP2X while commuting. I haven't been able to port GCC to it, but it has TCC C Compiler, GNU Make, Chicken Scheme, and Simple ECMAScript Engine as programming languages that run onboard, and the terminal emulator sterm. Its possible to code with that environment, given that the GP2X comes with a small linux distro and it includes a vi clone.   ;Quote:Original post by xhyldazhkAntheus:Still hardware is far easier to acces by C. SDL, OpenGL are examples of that.No, they're examples that libraries written using a C ABI are far easier to access from multiple languages.  SDL and OpenGL have bindings in just about everything, whereas C++ has no standardized ABI whatsoever.  There's poor OS support for kernel-mode C++, but SDL has no kernel-mode components, and OpenGL stuff probably depends on the same kernel-mode stuff as Direct3D.Speaking of Direct3D, Direct3D is a clear counterexample that C++ works just fine for said "hardware access".  It uses COM to get around the lack of a C++ ABI.Quote:But what about coding on high level languages that compile themselves to C?One of the few things even I will admit is an acceptable use of C.  Because you aren't (directly) using it -- your computer is.   ;Quote:Doom, Quake and Quake2 are the most known of them IMHO. Yea... and Adventure was written in BASIC. Those are oooollddd games. Everything they did to make things run is considered part of ancient history, since the core of their rendering relied on specific mode X behaviour, and various hardware specific tricks which have long been deprecated and obsoleted.Quote:Still hardware is far easier to acces by C. SDL, OpenGL are examples of that. No - those are APIs. OpenGL is written in C as lowest common denominator. SDL is built on top of OpenGL, as such it makes sense to share same accessibility.Hardware is still accessed as it always was. But since that is so cumbersome, layers and abstractions were put on it (aka drivers). OpenGL is just that, part of the OS, with common API defined in C. But OpenGL are no more connected than Linux is part of C.Quote:I am aware that coding directly in C is suboptimal, coding in functional style ala Lisp/Scheme in C is simply impossible because the stack would be blown before the end of most tail recursions, but what about coding on high level languages that compile themselves to C? Then you either execute interpreted code, or compile straight to assembly. Why compile into another language?Quote:I don't know yet of a library of quick, cheap threads that doesn't share anything (like in Erlang) for C.Neither do I. That's why I wrote my own in C++. That aside - Erlang is a complete platform. No matter what, you cannot achieve the same in C-like languages natively, you can only emulate it.Boost::ASIO is another implementation of the core system, but it doesn't have higher level structure, so you need to implement share-nothing yourself, Active Object approach is most suitable.Quote:The real reason for this thread is that i want to do onboard development on my Gamepark Holdings GP2X while commuting. I haven't been able to port GCC to it, but it has TCC C Compiler, GNU Make, Chicken Scheme, and Simple ECMAScript Engine as programming languages that run onboard, and the terminal emulator sterm. Its possible to code with that environment, given that the GP2X comes with a small linux distro and it includes a vi clone.Heh, embedded development. The probably last area where C is actively used for a good reason.You have no choice, if C is only thing you have, its merits or pitfalls are irrelevant.   ;Quote:Original post by xhyldazhkI've been programming in most languages for a long time, and recently i've found surprisingly that most well known games / operating systems / frameworks are still written in C. With games this isn't the case much nowadays, in the industry C++ is king at the moment (unforuntately).OS & frameworks - You mean APIs for things like graphics hardware? if so this is just a case of "lowest common denominator syndrome" and this is partly the OSs which are at fault since they where originally written (or still are) in C as opposed to a more secure, more strongly typed languages which are much more viable to use nowadays (and research projects have done like with Haskell's Home and Sing#'s singularity project). Another reason could be the lack of developers willing to learn new langauges or be open minded enough to look into other paradigms.Quote:Original post by xhyldazhkits syntax became almost a standardWhat is that suppose to mean, C is ISO standardized, i think you just mean it's popular. Well popularity wise C this is only the case in very niche problem domains, not in general.Quote:Original post by xhyldazhkit doesn't forces any programming paradigm on youIt doesn't give you a choice either and it only supports one pardigm natively which is procedural.Quote:Original post by xhyldazhkits ease of optimization.This is only half truths, it's more complicated than that and in actual fact more declartive/high-level languages (usually statically typed ones) are much more amenable to aggresive optimizations mostly because of the lack of side-effects (or explicit, controlled and localized side-effects) and strong typing (be it static or dynamically typed).Quote:Original post by xhyldazhk- Best practicesChoose the right tool for the job.Quote:Original post by xhyldazhk- Comparisons with other languagesWell what can i say, it's the lowest common denominator of programming languages, just above assembly.Quote:Original post by xhyldazhk- Possible successorsC++ is already it's successor, possible successors of which i know include Cyclone, Vault, Xanadu, and Felix.Quote:Original post by xhyldazhkDoom, Quake and Quake2 are the most known of them IMHO. Almost any new system gets a Doom engine for it.Yeah if you live about 15 years ago that would be true, if you mean't Doom 3 it's not written in C it's in C++ (but not the best example C++) and even that engine is dated by todays standards. Virtually all quality commercial game engines are written in C++ nowadays (unforuntately).Quote:Original post by xhyldazhkI would be interested in knowing about that 'trap doors' in higher level languages  to C.He's talking about bindings and foreign function interfaces (FFI) for higher-level languages to use C APIs and i've mentioned the reason why this is the case, lowest common denominator syndrome and where stuck with it until a new OS written in something else becomes very popular (and thus make that language more popular).[Edited by - snk_kid on September 8, 2007 4:45:45 AM];Quote:Original by MaulingMonkeyNo, they're examples that libraries written using a C ABI are far easier to access from multiple languages. SDL and OpenGL have bindings in just about everything, whereas C++ has no standardized ABI whatsoever. There's poor OS support for kernel-mode C++, but SDL has no kernel-mode components, and OpenGL stuff probably depends on the same kernel-mode stuff as Direct3D.Speaking of Direct3D, Direct3D is a clear counterexample that C++ works just fine for said "hardware access". It uses COM to get around the lack of a C++ ABI.Which other languages compile to C ABI? Maybe the answer is to find an high level language that does so. The dirty way is finding a language that compiles to C.Quote:Original by AntheusThen you either execute interpreted code, or compile straight to assembly. Why compile into another language?Because there are lots of useful existing C functions, that i want to use linking with the generated C code isntead of rewriting them.Quote:Original by snk_kidThis is only half truths, it's more complicated than that and in actual fact more declartive/high-level languages (usually statically typed ones) are much more ammenable to aggresive optimizations mostly because of the lack of side-effects (or explicit, controlled and localized side-effects) and strong typing (be it static or dynamically typed).Please elaborate more on this. Its interesting... Which would be your option to generate C ABI compatible files?;  Halo 1's engine was done with C. However its toolkit was made with C++   