cppit / jucipp

A lightweight & cross-platform IDE supporting the most recent C++ standards. This project has moved to https://gitlab.com/cppit/jucipp.
https://gitlab.com/cppit/jucipp
MIT License
882 stars 98 forks source link

Header guards #377

Closed szymonk211 closed 6 years ago

szymonk211 commented 6 years ago

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: https://github.com/szymonk211/jucipp/commit/cecd283c1259974ec33a6dd325ae548a62abc0f1 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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Good thinking. Thank you.

eidheim commented 6 years ago

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