• 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
Kyall

Is C++ too complex?

122 posts in this topic

I always want to improve my C++ knowledge and this time around this means finding out what parts of C++ aren't any good, so I thought I'd field a question to the experts: what parts of the c++ language are too complex to the point they interfere with writing good code and should be avoided as much as possible. Should I always use the stdio and not iostream for example, dynamically allocated memory in classes vs putting it in structs. What's the debate on what parts of c++ improve code, and the other parts that are over complicated and are damaging to code standards.
2

Share this post


Link to post
Share on other sites
[quote name='Kyall' timestamp='1354261356' post='5005610']
dynamically allocated memory in classes vs putting it in structs.
[/quote]

I'm not sure what you mean by that. Maybe stack vs heap ?
2

Share this post


Link to post
Share on other sites
[quote name='solenoidz' timestamp='1354264118' post='5005621']
[quote name='Kyall' timestamp='1354261356' post='5005610']
dynamically allocated memory in classes vs putting it in structs.
[/quote]

I'm not sure what you mean by that. Maybe stack vs heap ?
[/quote]

I believe he means that member data of a class is either dynamically allocated and referenced with a pointer or else it isn't (in which case it may be global, stack or still dynamically allocated, depending on how the instance of the class was defined).
2

Share this post


Link to post
Share on other sites
While I personally hope that I never have to deal with goto myself, I have encountered enough "damned if I do, damned if I don't" scenarios to understand that I might be at some point in a situation where goto might be the least evil way to solve something. I hope I won't have to ever use it though - no amount of showers would be enough to ever feel clean again after that.
0

Share this post


Link to post
Share on other sites
All good answers guys, it was nice to read every single post confirming my biases that there's nothing unnecessary in the language, next time I read an article that has me challenge my assumptions about c++ I'll ignore it. Also using a subset for clarity seems like a good idea.
0

Share this post


Link to post
Share on other sites
The parts of C++ that should generally be avoided (unless necessary) is misusing C stuff rather than the C++ alternative.
For example fopen, malloc and goto could be replaced with ifstream, new (with smart pointer) and exception respectively.

Whilst the ability to use classic C stuff seems to make the language complex, I actually prefer the way C++ extends rather than reinventing the whole language again from scratch (such as C#).

Kindof like OpenGL is seemingly quite hard to learn for new developers because it still has all the old stuff rather than dropping it all and starting with a brand new graphics API.
1

Share this post


Link to post
Share on other sites
[quote name='Karsten_' timestamp='1354273814' post='5005651']
The parts of C++ that should generally be avoided (unless necessary) is misusing C stuff rather than the C++ alternative.
For example fopen, malloc and goto could be replaced with ifstream, new (with smart pointer) and exception respectively.

Whilst the ability to use classic C stuff seems to make the language complex, I actually prefer the way C++ extends rather than reinventing the whole language again from scratch (such as C#).

Kindof like OpenGL is seemingly quite hard to learn for new developers because it still has all the old stuff rather than dropping it all and starting with a brand new graphics API.
[/quote]
how would you replace the goto in this bit with an exception
[code]
for (int bar =0; bar < 100; ++bar)
{
for(int foo = 0; foo < 100; ++foo)
{
if (foo * bar == 100)
{
goto loopBreak;
}
}
}

loopBreak:
printf("%d", 100);
[/code]

The code I am presenting is not doing something usefull at all to be honest but imagine a difficult calculation going on over a grid in which if a certain condition is met you need to break out of both loops and continue the rest of the algorithm with the results already calucalted?
1

Share this post


Link to post
Share on other sites
[quote name='NightCreature83' timestamp='1354278416' post='5005667']
how would you replace the goto in this bit with an exception
[/quote]
[source lang="cpp"]int doWork()
{
for (int bar =0; bar < 100; ++bar)
{
for(int foo = 0; foo < 100; ++foo)
{
if (foo * bar == 100)
{
return 1;
}
}
}

return 0;
}

// ...

if (doWork()) printf("%d", 100);[/source]

Or, use a boolean flag for each loop... works too but it's ugly.

EDIT: I guess foo wasn't the best function name, lol. Edited by Bacterius
2

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1354279576' post='5005671']
I'm of the opinion that exceptions as implemented in C++ are too costly to be used in the same fashion as they are in C#/Java. I use exceptions in C#, but never ever use them in C++.
[/quote]
It's funny, because ,y gut feel puts me in the same position with many constructs. Using dictionaries or regular expressions in Python, for example, is normal but in C++ I tend to avoid them because they're expensive.

Funny thing is, much of the time such constructs in higher-level languages are implemented using the underlying C++ construct. For instance, Java exceptions in the GCC Java runtime are implemented using exactly the same mechanism as C++ exceptions (it's the same libgcc_s.so file on my system). Any performance barrier is psychological: Java forces you to pay the cost always by design, C++ allows you to pay only for what you use, and you can avoid using exceptions, so you feel guilty about waste.

I am still of the opinion that exceptions are too costly to use for anything but exceptional situations. I limit (but not avoid) their use in C++, avoid Java completely, and use Python mostly for prototyping.
2

Share this post


Link to post
Share on other sites
[quote name='NightCreature83' timestamp='1354278416' post='5005667']
The code I am presenting is not doing something usefull at all to be honest but imagine a difficult calculation going on over a grid in which if a certain condition is met you need to break out of both loops and continue the rest of the algorithm with the results already calucalted?
[/quote]
I would say wrong semantic. Since you loop as long as a condition is met, you should need a while loop. Breaking out of a for loop is a strong indicator for that.

It is a bit nitpicky, but from a theoretical computer science stand point, for loop with a break statement is wrong. A for loop is intended to repeat the internal statement for a known amount. Therefore a for loop can be expanded by repeating the line of code by x amount of time.

A while loop is very different, each while loop has a variance and invariance which you can use to proof your loop aborts, and with the invariance you can proof that your loop calculates what it should.
</detail>

I am sure there is a freak case where a goto statement makes more sense and is more readable than any other solution, But I have yet to see a good example for it.
You can live a happy and productive life writing clean code without ever using a goto statement. Edited by Bluefirehawk
-2

Share this post


Link to post
Share on other sites
[quote name='Bluefirehawk' timestamp='1354284849' post='5005693']
I am sure there is a freak case where a goto statement makes more sense and is more readable than any other solution, But I have yet to see a good example for it.
You can live a happy and productive life writing clean code without ever using a goto statement.
[/quote]
In C++. The assertion is not transitive to C.
0

Share this post


Link to post
Share on other sites
[quote name='Bregma' timestamp='1354284410' post='5005688']It's funny, because ,y gut feel puts me in the same position with many constructs. Using dictionaries or regular expressions in Python, for example, is normal but in C++ I tend to avoid them because they're expensive.[/quote]Yeah I get the same feelings, in C# a dictionary is common for me, but I never use [font=courier new,courier,monospace]std::map[/font] in C++, and a hash-table is almost always implemented on top of a flat array... but this is because I'm writing real-time systems in C++ and bloated tools in C#.
[quote]Any performance barrier is psychological: Java forces you to pay the cost always by design, C++ allows you to pay only for what you use, and you can avoid using exceptions, so you feel guilty about waste.[/quote]No, exceptions in C++ are a fundamentally different construct than exceptions in Java, they just happen to share terminology. Plus most C++ compilers suck at implementing their flavour of them, while the JVM is good at it's flavour. If you port my benchmarks to Java, there's no way the throw version of the double-break idiom will be 2000x slower than the other implementations. Edited by Hodgman
1

Share this post


Link to post
Share on other sites
[quote name='Kyall' timestamp='1354271289' post='5005648']
All good answers guys, it was nice to read every single post confirming my biases that there's nothing unnecessary in the language, next time I read an article that has me challenge my assumptions about c++ I'll ignore it. Also using a subset for clarity seems like a good idea.
[/quote]

The question presented was whether there were any components to C++ that were so complex as to be unecessary. There are definitely unecessary parts to C++ -- Valarrays immediately come to mind -- but I'm not learned enough in the language to identify any language features that are unecessary out of overcomplexity (except the ultimate low-hanging fruit goto).
0

Share this post


Link to post
Share on other sites
My own experience of C++ is that, for every good pattern to solve a problem, there are 10 bad ways of doing it. I needed a lot of time to learn that, and there are surely ways I don't know yet (and I don't know that I don't know).
2

Share this post


Link to post
Share on other sites
[quote name='Mike.Popoloski' timestamp='1354299991' post='5005766']
C++ most assuredly has features that are too complex and/or arcane for their own good. Sure, they're "valid" features, but if you use one in your code you're going to get slapped upside the head during the code review. For example, overriding the comma operator [img]http://public.gamedev.net//public/style_emoticons/default/sleep.png[/img]
[/quote]
It can be funny also, making practical jokes (not possible with proper configuration management).

#define struct union // Save memory

#define while if // Speed optimizer
1

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