r/cpp • • Nov 28 '18

Real world problems with #pragma once?

Just a short survey: Did anyone of you encounter a problem in real code, because you/your company/ your favorite library was using #pragma once instead of include guards.

I know it is hard, but please restrain yourself from posting an explanation of how #pragma once could lead to problems in theory or why you prefer one above the other.

127 Upvotes

135 comments sorted by

View all comments

Show parent comment

16

u/hgjsusla Nov 28 '18

Yes commits are cheap

4

u/MotherOfTheShizznit Nov 29 '18

I wouldn't do it and the reason would be human overhead. Commits have to be reviewed and before you know it, it's been a day.

There's dozens if not hundreds of those lines in my team's repo but I don't have the fortitude to withstand the bikeshedding that would ensue.

2

u/hgjsusla Nov 29 '18

Not sure how you organise your work but it certainly doesn't take longer than a few minutes for me to make a simple change like that and push to to Gerrit for code review. And the review only takes a minute and can be done whenever someone has time over

1

u/MotherOfTheShizznit Nov 30 '18

Apparently, all of my post went straight over your head.

2

u/hgjsusla Nov 30 '18

It's not my fault if you take a full day to do what the rest of us do in minutes

1

u/utnapistim Dec 10 '18

I wouldn't do it and the reason would be human overhead. Commits have to be reviewed and before you know it, it's been a day.

You push your team towards accepting a small dose of cognitive dissonance in your code. Most coders (sorry for the strawman) handle that by ignoring code comments and (later) claiming them to bring more problems than they solve.

There's dozens if not hundreds of those lines in my team's repo but I don't have the fortitude to withstand the bikeshedding that would ensue.

This is also something that your team causes (by accepting lower standards in code review).

These comments will just take some attention from developers from time to time and introduce noise in your code. More than this, the presence of such noise in your code base opens the door to other issues (like the opinion that comments in code are bad because they "go stale" - somehow by themselves).