Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Header guards #377

Closed
szymonk211 opened this issue May 5, 2018 · 5 comments
Closed

Header guards #377

szymonk211 opened this issue May 5, 2018 · 5 comments

Comments

@szymonk211
Copy link
Contributor

In general, there is small chance anyone would want to create header file without header guards or pragma once, so why not generate it anytime new .h or .hpp file is created?
I did something like that on my fork:
szymonk211@cecd283
because I needed it for some project that uses header guards.

My solution might be a bit incomplete though. In this solution header stubs are generated according to the global policy. Header policy from current project is not taken into account. There is a risk that user can by accident mix header guards with pragmas because of that. If user had two projects: one with pragmas and one with guards, he would have to change the global settings any time he starts working on another project.

This is partially related to #294.

@eidheim
Copy link
Member

eidheim commented May 5, 2018

Thank you for looking into this as well. I'm thinking we could just force #pragma once into new header files? It's 2018 anyway, and the important compilers have supported it for quite a while?

@szymonk211
Copy link
Contributor Author

I created header guards because I have some project with stupid guidelines that I didn't want to break. In case of my project you are right. Good habits and simplicity should be promoted, and nothing bad gonna happen if some unrelevant guidelines will be broken.
I just wonder if there are some projects, where (from legacy or some different reasons) it is really not possible to use #pragma once. Maybe for that reason it is good to left small window for code with header guards and just left the code in the way I wrote it (without some complex logic for discovering what kind of guards given project use).
What do you think?

@eidheim
Copy link
Member

eidheim commented May 6, 2018

The only cases I can think of is when using really old compilers, or if one header file is split into several in a weird build setup. But I think it's safe to just add #pragma once if an empty header file is opened (for instance in Source::ClangViewParse::ClangViewParse(). It definitely will help a lot of new C++ programmers that tend to forget this (and get strange errors because of it). And in cases where it is not wanted, one can simply push undo or remove it manually.

@szymonk211
Copy link
Contributor Author

Good thinking. Thank you.

eidheim added a commit to eidheim/jucipp that referenced this issue May 7, 2018
@eidheim
Copy link
Member

eidheim commented May 7, 2018

I implemented my proposal in the commit above. I'm thinking it is better to have it than not:)

@eidheim eidheim closed this as completed in 86adaba May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants