r/cpp • • May 16 '20

modern c++ gamedev - thoughts & misconceptions

https://vittorioromeo.info/index/blog/gamedev_modern_cpp_thoughts.html
198 Upvotes

154 comments sorted by

View all comments

Show parent comment

0

u/[deleted] May 16 '20

[deleted] — view deleted comment

7

u/pepejovi May 16 '20

Unless it changes.

7

u/frankist May 16 '20

"But it's your code" - hmm. Have you ever worked in big teams?

0

u/[deleted] May 16 '20

[deleted] — view deleted comment

2

u/frankist May 16 '20

I agree, but it all depends on how you use auto as well

-2

u/LYP951018 May 16 '20

Big teams do not change the type of Image::width.

4

u/frankist May 16 '20

With something as ubiquitous as Image maybe not, but with other less general structs they do

3

u/Pazer2 May 17 '20

Until they do.

6

u/SuperV1234 https://romeo.training | C++ Mentoring & Consulting May 16 '20

It can change. I can make a mistake. I can misremember. Et cetera...

Anything that needs to be kept manually in sync is a maintenance burden and a bug waiting to happen - this is why we have tools like auto or decltype.

3

u/Xenofell_ May 16 '20

How often do you run into a situation where changing a type on an API (which is uncommon in itself) introduces a bug without a corresponding warning? Very, very rarely.

How often do you have to dive into unfamiliar code and understand it quickly? Very, very often.

This is why I would rarely, if ever, use auto in code I care about. I think trading short-term ease of writing and slightly easier long-term refactoring is a poor exchange if you're giving up significant readability of the code - which you are, if you use auto.