Live data from Hacker News

Modern C++ gamedev: thoughts and misconceptions

vittorioromeo.info

151–160 of 221 posts

Re: Modern C++ gamedev: thoughts and misconceptions

#151
I don't understand why does he show loop-based version using 2 for loops instead of using just one. I usually work in higher-level programming languages, but can't believe that cache hits or something else makes it faster than finding sum and maximum both while going through all images only once.

And having just one loop makes it simpler too.

Re: Modern C++ gamedev: thoughts and misconceptions

#152
post #151

I don't understand why does he show loop-based version using 2 for loops instead of using just one. I usually work in higher-level programming languages, but can't believe that cache hits or something else makes it faster than finding sum and maximum both while going through all images only once. And having just one loop makes it simpler too.

Choosing C++ over C means his programming abilities aren't very good.

Re: Modern C++ gamedev: thoughts and misconceptions

#153
post #18

Earlier quoted context omitted.

>I find that the dumbest code is the best code Not always, though. See every bug and exploit with C arrays or pointers that exists because C devs think even minimal attempts at safety are too complicated or slow, or old-style PHP code that builds SQL queries out of printf strings directly from POST values, or probably countless other examples in other languages. C++ code that uses raw pointers instead of references o…

> Not always, though. See every bug and exploit with C arrays ... That can also be perceived as a a flaw of the language design in that it does not allow one to write dumb, safe and fast code. Which are such languages in existence today? edit: fixed typos

Golang is a pretty good example.

> The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt.

~ Rob Pike

Re: Modern C++ gamedev: thoughts and misconceptions

#154
post #150

Earlier quoted context omitted.

I'm a C++ developer who occasionally writes Rust. The experience of writing new code in one is very, very similar to the experience of writing new code in the other, right down to the compile times. The lifetime analysis in Rust is nice and pretty far ahead of what static analyzers can do in C++, but Rust Generics are a pretty weak approximation to Templates. Rust has better Browser integration, C++ has Qt. One imagi…

I agree with most of what you're saying here except for the point on generics versus templates. I wouldn't say generics are an approximation of templates at all, templates are something in between generic programming and macros and that leads to them being hazardous, slow, and generally speaking unergonomic. Rust's generics allow for some seriously powerful abstractions to be built in a very clean and readable way, a…

> I wouldn't say generics are an approximation of templates

Template (at their origins) are nothing more than generics, and a pretty clean, powerful and zero cost way of doing generics.

What you name "hazardous, unergonomic" macros style is not the template system itself. It is mainly due to all the 2005-styles SFINAE hacks that have been invented by abusing templates properties.

SFINAE in C++ is nothing natural, it's at best a dangerous trick to have compile time resolution/execution.

Fortunately all of that should die progressively with C++-17 constexpr for the good of humankind.

Re: Modern C++ gamedev: thoughts and misconceptions

#155
post #115
post #90

I’m often disappointed by how disrespectful people can be in programming discussions. It’s one thing to discuss tradeoffs but ridiculing peoples’ choices or speaking in absolutes is not helpful. There’s no One True Way to program.

I always wondered whether it's programming in particular that attracts a lot of people that think in only black and white, or whether it's the same in other industries as well.

I know this kind of turns things up to 11, but about 5 years ago there was a book published called, "Engineers of Jihad." A bunch of news articles were written when it was published. I have zero idea how reputable it is, or if its been later debunked (I never read the book itself or heard any followup). My recollection is that one assertion offered was that many engineers are predisposed because engineering has logical, straightforward order and hierarchy while most of life is a lot more messy.

Separately, I think programming itself is solitary and predisposed to people who don't focus on building social skills (myself included). I think online (pseudonymous) communication can introduce all sorts of problems.

Re: Modern C++ gamedev: thoughts and misconceptions

#156
post #52

Earlier quoted context omitted.

Traditionally C++ code is often considered harder to read than code in these other languages, and the "excessive" use of 'auto' does not make understanding code easier. Still, according to my observations the split in opinions on this is about 50/50; mine is that the use of 'auto' improves the "genericity" of code (on par with the use of templates) and its amenability to refactoring with less chance to make a mistake…

I'd also say that using auto makes your code easier to read, especially when you are the user of generic code. Looping through a vector where you need to keep track of the iterator, for example. for(auto iter = vec.begin(); iter!=vec.end(); iter++) for(std::vector ::iterator iter = vec.begin(); iter!=vec.end(); iter++)

I think pretty much every one agree with auto for iterators and duplicated types (casts, initialisation).

The debate is about all the other cases.

Re: Modern C++ gamedev: thoughts and misconceptions

#157
post #128
post #6

After years of experience writing code for games, I find that the dumbest code is the best code. It doesn't matter if it's C# or C++, whenever I've used something like reactive extensions or template metaprogramming, it has been a terrible mistake every single time. Make your code simple, dumb and verbose all the time. Avoid using any complex abstractions or any overcomplicated syntactic sugar and you'll have a codeb…

I wish this kind of thinking would die. 9 times out of 10 when I'm working on a large code base at (any company I've worked at so far), the main problem I have is with disorganized, messy code with poor abstractions, state everywhere, functions that are too long, functions that are too short, references to objects everywhere with no regard for lifetime and the list goes on and on. The times I have been stumped with c…

You made me realise that term "dumb code" isn't exactly what I mean. I want to advocate writing code that is very easy to statically understand. You should be able to look a piece of code without needing to read too much around it to understand what it is doing. One of the best ways of doing this in my experience is keeping things simple (or "dumb" as I put it earlier). Using simple abstractions, keeping code organised and avoiding global state also help in this regard.

Re: Modern C++ gamedev: thoughts and misconceptions

#158
post #131

Earlier quoted context omitted.

No, I did not make the point that Twitter arguments are counterproductive at all o the contrary this one looks very productive EXCEPT for the author. So now you're straw manning me as well, then say I'm gatekeeping and no true-scotsmanning. I don't appreciate that all and am therefore out.

- winterismute questioned qualifications to have a position on writing C++ for game dev. That is gatekeeping and No True Scotsman. - At least someone on Twitter called some tweets "retarded", etc., so OP thought to continue the conversation by ignoring nonsense and restating concerns in a healthier tone. This post is his attempt to be productive, apparently. - Any perceived slight against you, you have inferred. No o…

> winterismute questioned qualifications to have a position on writing C++ for game dev. That is gatekeeping and No True Scotsman

Well, not really. Some of the people on twitter (and the author himself) basically pointed out that "one of the main reason we do not use that coding style is that, despite the advantages, when you need to work on a codebase that requires both performant simulation of the planet and rapid experimentation of mechanics at the same time by hundreds of de-localized devs, you end up seeing many of its limitations". If you want to handle this argument, you need to have a clear idea of what are the priorities in such a scenario, which I doubt the author has. Even more interestingly, the article does not raise the point "this is how I write modern C++, I think it will benefit all the industries" but specifically seems to want to argue that this style helps gamedev particularly despite showing basically no domain-specific observations, nor anything that convinces me he knows what are the critical problems in the "triple A game" scenario... I don't think I can call this gatekeeping if I am not convinced - even by reading only the article - that the author has a good grasp of the fundamental problems involved in the development of big games, or not?

Re: Modern C++ gamedev: thoughts and misconceptions

#159
post #150

Earlier quoted context omitted.

I'm a C++ developer who occasionally writes Rust. The experience of writing new code in one is very, very similar to the experience of writing new code in the other, right down to the compile times. The lifetime analysis in Rust is nice and pretty far ahead of what static analyzers can do in C++, but Rust Generics are a pretty weak approximation to Templates. Rust has better Browser integration, C++ has Qt. One imagi…

I agree with most of what you're saying here except for the point on generics versus templates. I wouldn't say generics are an approximation of templates at all, templates are something in between generic programming and macros and that leads to them being hazardous, slow, and generally speaking unergonomic. Rust's generics allow for some seriously powerful abstractions to be built in a very clean and readable way, a…

Non-type Template Parameters ("const Generics") are on the short-term road-map for Rust. Small step from there to recursion and compile-time factorial.

Re: Modern C++ gamedev: thoughts and misconceptions

#160
post #128
post #6

After years of experience writing code for games, I find that the dumbest code is the best code. It doesn't matter if it's C# or C++, whenever I've used something like reactive extensions or template metaprogramming, it has been a terrible mistake every single time. Make your code simple, dumb and verbose all the time. Avoid using any complex abstractions or any overcomplicated syntactic sugar and you'll have a codeb…

I wish this kind of thinking would die. 9 times out of 10 when I'm working on a large code base at (any company I've worked at so far), the main problem I have is with disorganized, messy code with poor abstractions, state everywhere, functions that are too long, functions that are too short, references to objects everywhere with no regard for lifetime and the list goes on and on. The times I have been stumped with c…

It's the endless copying-and-pasting that gets you.

Fix a bug somewhere ... pray to the Nasal Demons you got there before more than two developers duplicated it elsewhere.

Post reply on HN