• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Mercury Filter

How Languages Compare?

37 posts in this topic

First off, great job either starting a holy war or getting your thread locked. I'm pretty sure that's what happens when this question gets asked, because it gets asked a lot. ;)

 

But since neither of those things has happened yet, here's my cent and a half (adjusted for inflation):

 

 

 

In writing some C++ code today, I saw that there were member functions of classes that could, due to the nature of classes, be written in a way that no arguments were needed to the function. 

 

This is true, and classes are pretty great. I'm developing almost exclusively in C nowadays, and while the arguments needed are sometimes lengthy, it isn't a dealbreaker for me. The biggie in C++ is encapsulation - that an object's methods and properties have restricted access from outside - which, in theory, means that the language reinforces correct design. This strikes me as weird, because having the discipline to manage memory but not to make sensible modularity and good separation of concerns seems a lot like trusting someone to do brain surgery but not to own an electric kettle.

 

In my C codebase, I have logic split up into eight separate domain-specific (that's problem domain, not web!) files, with prefixed function names. For the most part it's all coordinated by the central logic in game.c, and there are only three functions that call functions between domains (specifically, it's for the entities system to ask the sprite system for sprites and the script system for scripts.) It's very much like the OO version of the code would be, because I'm disciplined and I want to be able to maintain my code.

 

 

 

lol. ["lol" is included in my typing language as a provisional inclusion, and I am not sure if it will make the cut for the standard]

 

I see your "lol" and raise you a "trololol." ;)

2

Share this post


Link to post
Share on other sites

C and C++ are really very similar to each other but with one big difference, classes. Classes are like a big new introduction to C and C++ is by miles better just because of this. I really don't know if there are any more big projects written in C since it seams pretty hard to do it without classes.

Classes just make it easier for bigger project because you just get lost in all that functions and you start to write things that you already have. With classes its much more organized and you know where each member belongs.

 

C allows functions without arguments. This is possible in C and C++, and I think all languages support that.

-1

Share this post


Link to post
Share on other sites

I apologize if I have asked something that can be the cause of a legendary holy war. That was certainly not my intent.

Perhaps I was not clear. I was not asking for whether one or the other is better. I wanted to know (if such a response is even possible with reasonable effort) if anyone had any high-level explanations regarding benefits in writing code in one or the other. Not really a better thing, but more specifically if there are certain things that are a bit easier in one language versus the other.

My question was meant to try and obtain objective responses, but I did use the dirty word "opinions" in my original post. Probably bad form when seeking an objective response. Perhaps the nature of my question can not easily be answered objectively. I mainly just want to try and determine if there are things here and there that may be easier in one language versus the other.

I play with both of them (which occasionally leads to me trying to do riduculous things in one because I forget I am not using the other), and just wanted to know a bit more about usage of the languages in general.

1

Share this post


Link to post
Share on other sites


C allows functions without arguments. This is possible in C and C++, and I think all languages support that.

I am sorry if I did not make it more clear what I was saying. I am aware that C allows functions without arguments, I was trying to say that I was doing something with C++ where I would have needed arguments in C, or (if I understand correctly) I would have needed to be using global variables in C.

1

Share this post


Link to post
Share on other sites

Yea, you are right. In C there wound have been needed more arguments since a class manages all that.

1

Share this post


Link to post
Share on other sites


I'm developing almost exclusively in C nowadays

This is interesting for me to see. I am sure that there are people developing in all kinds of languages that I would not expect, but I usually see people insisting that you cannot use C, and you need to use C++. I would assume that it is a "toolbox" issue, and nothing is actually quantifiably superior in all ways, with the selection being a matter of choosing which benefits are most important. I am currently kind of a fan of C, but that is probably due to familiarity, since I have spent the most time using it at this point.

Thank you, by the way, for warning me about asking this kind of question. I will either be a lot more careful with how I approach such matters, or I will avoid asking potentially inflamatory questions in the future.

1

Share this post


Link to post
Share on other sites

 

This is interesting for me to see. I am sure that there are people developing in all kinds of languages that I would not expect, but I usually see people insisting that you cannot use C, and you need to use C++. I would assume that it is a "toolbox" issue, and nothing is actually quantifiably superior in all ways, with the selection being a matter of choosing which benefits are most important. I am currently kind of a fan of C, but that is probably due to familiarity, since I have spent the most time using it at this point.

Thank you, by the way, for warning me about asking this kind of question. I will either be a lot more careful with how I approach such matters, or I will avoid asking potentially inflamatory questions in the future.

 

 

I don't want to tell you to stop using C, but when your code starts to have 1 000 000 lines I think you will have a hard time to manage around.

-2

Share this post


Link to post
Share on other sites

I don't want to tell you to stop using C, but when your code starts to have 1 000 000 lines I think you will have a hard time to manage around.

I understand what you are saying there (not really, as I lack the experience of writing large programs to claim understanding). I imagine managing any large programming project is not trivial, but I am curious about what it is that makes managing the larger programs in C++ easier? I have heard the quick answer of "classes", and perhaps this is another question that I need to experience as opposed to hear an answer to, as the quick answer does not really feel like it enhances my understanding (I often take this as a sign that I am missing some fundamental understanding that would make the quick answer more complete, if I had the knowledge). I assume that what Winfield said above is a  Edit::workable good::Edit option, so I guess I am wondering if there is something else that I am not familiar with in C++ that makes it easier to manage code for bigger projects, or if perhaps I need to write more C++ before I will really see the benefits?

Sorry if some of these questions are kind of silly (perhaps). I presume the wonderous shield of 'newb', which should be obvious from said questions, should afford me some pity, assuming that I manage to improve....eventually.

 

Edit::I felt like "workable" may have been communicating a negative or perhaps diminished appraisal of the option that I did not intend.

Edited by Mercury Filter
1

Share this post


Link to post
Share on other sites


I usually see people insisting that you cannot use C

 

People are weird and say crazy, hyperbolic things. 

 


I don't want to tell you to stop using C, but when your code starts to have 1 000 000 lines I think you will have a hard time to manage around.

 

Yeah. 

 

C's existed forever, and if you want a library that does something it's probably been completely stable since the 1980s. C is perfectly expressive, has tight and easily memorized syntax, and has extensive library support. Programming a game engine in C is made simpler by the plethora of libraries available: allegro, SDL, SFML, GLFW, the list goes on. 

 

There's a very good discussion here - see the second answer to the question in particular.

1

Share this post


Link to post
Share on other sites

I think worrying about function parameters isn't really something to be worrying about. Good design use function parameters in both C/C++. You don't want to access your member variables directly as that defeats one of the points of C++'s encapsulation.

 

I used C for about 2 months on my way to C++. I'm not an expert but I've been working with it for many years now. I just don't like the idea of manually matching up stand alone functions to data. It just seems strange to not have a physical tie like what a class provides. It just seems a little hokey to me to rely on naming or docs to make that link between function and data.

0

Share this post


Link to post
Share on other sites

 

I understand what you are saying there (not really, as I lack the experience of writing large programs to claim understanding). I imagine managing any large programming project is not trivial, but I am curious about what it is that makes managing the larger programs in C++ easier? I have heard the quick answer of "classes", and perhaps this is another question that I need to experience as opposed to hear an answer to, as the quick answer does not really feel like it enhances my understanding (I often take this as a sign that I am missing some fundamental understanding that would make the quick answer more complete, if I had the knowledge). I assume that what Winfield said above is a  Edit::workable good::Edit option, so I guess I am wondering if there is something else that I am not familiar with in C++ that makes it easier to manage code for bigger projects, or if perhaps I need to write more C++ before I will really see the benefits?

Sorry if some of these questions are kind of silly (perhaps). I presume the wonderous shield of 'newb', which should be obvious from said questions, should afford me some pity, assuming that I manage to improve....eventually.

 

Edit::I felt like "workable" may have been communicating a negative or perhaps diminished appraisal of the option that I did not intend.

 

 

Without classes you will end up with a function like GetPositionOfWalkableForOutherSystem(). Where with classes this could be broken into something like this:

 

pWalkable = OutherSystem.GetWalkable();

position = pWalkable->GetPosition();

 

I think that this example is much easier and more readable. Lets say that you have 150 functions as in first example, you will start very soon to struggle to find something you want.

As Agony sad C++ saves a huge time. If you use a lot of functions as in  first example they will start to be dependant of each other and you will not be able to find this dependency very quickly. With classes you just know where the things are as classes provide that for you.

Also Agony sad that learning C might make you better at C++. Its true, and if you know assem things will be a lot more clear to you.

Edited by ryt
1

Share this post


Link to post
Share on other sites

 

 

I understand what you are saying there (not really, as I lack the experience of writing large programs to claim understanding). I imagine managing any large programming project is not trivial, but I am curious about what it is that makes managing the larger programs in C++ easier? I have heard the quick answer of "classes", and perhaps this is another question that I need to experience as opposed to hear an answer to, as the quick answer does not really feel like it enhances my understanding (I often take this as a sign that I am missing some fundamental understanding that would make the quick answer more complete, if I had the knowledge). I assume that what Winfield said above is a  Edit::workable good::Edit option, so I guess I am wondering if there is something else that I am not familiar with in C++ that makes it easier to manage code for bigger projects, or if perhaps I need to write more C++ before I will really see the benefits?

Sorry if some of these questions are kind of silly (perhaps). I presume the wonderous shield of 'newb', which should be obvious from said questions, should afford me some pity, assuming that I manage to improve....eventually.

 

Edit::I felt like "workable" may have been communicating a negative or perhaps diminished appraisal of the option that I did not intend.

 

 

Without classes you will end up with a function like GetPositionOfWalkableForOutherSystem(). Where with classes this could be broken into something like this:

 

pWalkable = OutherSystem.GetWalkable();

position = pWalkable->GetPosition();

 

I think that this example is much easier and more readable. Lets say that you have 150 functions as in first example, you will start very soon to struggle to find something you want.

As Agony sad C++ saves a huge time. If you use a lot of functions as in  first example they will start to be dependant of each other and you will not be able to find this dependency very quickly. With classes you just know where the things are as classes provide that for you.

Also Agony sad that learning C might make you better at C++. Its true, and if you know assem things will be a lot more clear to you.

 

This is false. Why would you do it that way, and not like this?

othersystem_getposition(pWalkable, &position);

When you start talking about systems that have 1000000+ lines of code, it doesn't really matter much whether you use classes or "not". Encapsulation is still very much possible in C. You could ask Linus Torvalds what he thinks on the subject.

Edited by patrrr
2

Share this post


Link to post
Share on other sites

Ok, but for me its a lot easier to have othersystem.GetWalkable(). It works trough IntelliSense and other plugins where with a single function you have to know exactly what you want.

Also if you want to write a variable this way you have to write it like othersystem_somevariable;. Now if you have a lot of things like othersystem it takes ages to write that.

Edited by ryt
0

Share this post


Link to post
Share on other sites

Ok, but for me its a lot easier to have othersystem.GetWalkable(). It works trough IntelliSense and other plugins where with a single function you have to know exactly what you want.

You can have the "othersystem" prefix in C as well. Works well with IntelliSense-like systems.

Edited by patrrr
0

Share this post


Link to post
Share on other sites

What about inheritance and polymorphism. With polymorphism you have to write a lot less code.

Edited by ryt
0

Share this post


Link to post
Share on other sites

Yeah, polymorphism is useful. But thing is, you can implement that in C as well, which is what the large projects I've worked at have done. Structs might contain function pointers for example, implementing a service.

2

Share this post


Link to post
Share on other sites
Nowadays the trend in game development is to use the component entity system which works really nicely with languages like C which don't actively enforce rigid object orientation.

At work we tend to write fairly typical C code using similar patterns to Gtk+ for our small amount of object orientation but then we attach components to a single type akin to Unity's GameObject.
We do however use the GNU C++ compiler so we can access some of the really useful C++ functionality like std::string, std::vector, smart pointers etc. We also use external C++ and C libraries so using a C++ compiler was the most compatible choice.

Also, it seems easier to interface with C code from a Java or Objective-C shim layer (for mobile devices), than C++.

My personal favorite feature of C over C++ is that if you define the struct in the .c file and just have a forward declaration of the struct and corresponding functions in the .h file, it is much more encapsulated than even a class with everything private in C++ since other developers can't even see the data and you have complete control over any aspect of the data being exposed. This can't seem to be done so well in C++ without rewrapping all the functions because the class contains the functions so has to be exposed. Thus the pimpl idiom which I find a tad messy and convoluted. Edited by Karsten_
1

Share this post


Link to post
Share on other sites

struct DeadPlayer {
     Player player;
     Point deathLocation;
}

Now, you write methods that take a DeadPlayer* as their first argument (and observe, you can pass DeadPlayer pointers to all methods that expect a Player).


Nice example.
Usually a fairly junior C# or Java developer will jeer at C because they don't realize or understand how this works. This is how Gtk+ (and many object-orientated C libraries) does it and demonstrates that C is pretty darn flexible. Edited by Karsten_
1

Share this post


Link to post
Share on other sites

Automatic enforcement of initialising stuff is good in C++ though (in C, you don't want to forget to call an init/deconstruct method).

 

But most things you can do in C++ you can do in C, although C's version of templates via macros is not good ;)

 

C makes you write a lot of boilerplate code and get it right which C++ shields you from.

2

Share this post


Link to post
Share on other sites
Almost any piece of high level C code can be improved by applying C++ techniques. References, generic algorithms, lambdas, constexpr, smart pointers, move semantics etc. are all really nice. You don't need to write object oriented code to benefit from C++.

Just the fact that C++ has a good assortment of standard containers is a huge leg up on C. If you are working in C, you'll be using containers from some 3rd party library, or have rolled your own from scratch with great time expenditure and possible quality issues, or you are effectively hamstrung by lack of appropriate tools.
0

Share this post


Link to post
Share on other sites


Almost any piece of high level C code can be improved by applying C++ techniques. References, generic algorithms, lambdas, constexpr, smart pointers, move semantics etc. are all really nice. You don't need to write object oriented code to benefit from C++.

I hate to nit-pick (ok, I actually love to, it seems very effective in terms of learning), but isn't it a bit misleading to refer to genetic algorithms and lambdas as being C++ techniques? Correct me if I misunderstood what you were saying but the statement seems to associate those techniques with C++, while I am pretty sure the two I mentioned existed before it did. I could not say about the others, as I am less familiar with them, and I am not very familiar with those two in the first place.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0