Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: header guard + drop some dead end references #1224

Closed
wants to merge 5 commits into from

Conversation

jnpkrn
Copy link
Contributor

@jnpkrn jnpkrn commented Feb 10, 2017

My eyes need rest now.

Originating in discussion around commit ef711f9, there's a Ken's
concern about not enough uniqueness in artificial header inclusion
guard names (in that particular case) on the table.

Together with varying styles used for these names across the project
and the guards sometimes missing altogether, this is to be addressed
in two subsequent commits (adjust existing + fix missing ones).

With this first step, we further introduce following naming scheme:

1. all guards start with PCMK ands end with __H

2. there are 5 purposeful patterns so that the guard name also encodes
   some not-so-obvious pieces of information:

   PCMKDEF_<HEADER>__H:
     shared headers being a mere dictionary assigning symbolic
     names to constants/literals, no type/function/object business here

   PCMKLIB_<LIBRARY-or-MIX>_<HEADER>__H:
     public headers for a library (or a mix of libraries designated
     with "MIX")

   PCMKPRIV_<LIBRARY-or-MIX>_<HEADER>__H:
     private headers for a library (or a mix of libraries designated
     with "MIX") created more-or-less in an organic way, function
     promises via "extern" and not via proper declarations, etc.

   PCMKINT_<LIBRARY-or-MIX>_<HEADER>__H:
     private headers for a library (or a mix of libraries designated
     with "MIX") created in more decent way, declaring functions
     properly (with hidden visibility, cf. G_GNUC_INTERNAL from glib)
     hence usable in all the contexts of standard library-internal use

   PCMK_<DIR-or-BINARY>_<HEADER>__H:
     private headers exclusively for compiling particular binary

Some kinds of normalization is also applied on lines around respective
preprocessor conditionals and comments.

(As an aside, there used to be unintendedly mixed "ElECTION" in a guard
name prior to this change.)
Appeared in 83919a1, slighty modified on serveral occassions, but
still pretty blind.
This is a remnant from experimental support for failover domains
(as in rgmanager cluster world order) introduced in a773335, but
did not got purged during 800a12f.
This got added with 9273e61, but then gradually replaced with
glib-based hashtables (08c4060) until replaced completely,
but dd1e806 forgot to drop this reference as well.
@kgaillot
Copy link
Contributor

The naming scheme is way too formalized and complex; it's neither intuitive to someone reading the code, nor easily maintainable in a large, distributed project.

We need a much more free-form approach with as few rules as possible. A good choice would be prefixing all symbols with "PCMK_" and ending with "__H", and otherwise a free-form similarity to the filename. The only goal should be to prevent re-inclusion of the same file, not encode any information.

@jnpkrn
Copy link
Contributor Author

jnpkrn commented Feb 13, 2017 via email

@jnpkrn
Copy link
Contributor Author

jnpkrn commented Feb 13, 2017 via email

@kgaillot
Copy link
Contributor

The naming scheme is way too formalized and complex; it's neither
intuitive to someone reading the code,
...who usually has no business in understanding what the particular
pattern was meant to encode, it's just an inclusion guard in this view

It's very important in a distributed, community-driven project that code be as readable as possible to a newcomer, without mysterious coded parts that need a separate guide to decipher. Pacemaker code is already very difficult to follow in many cases due to its asynchronous, event-driven nature and multiple daemons -- we need to lower the barrier to understanding, as much as possible.

Applied guard names already conform to that, so there's not conflict.

The names picked here will be fine if you get rid of the extra part between PCMK and underbar, so that your #1 is the only hard rule.

In other words, I don't understand what complexity you are arguing against if it is so easy to ignore the actual patterns behind the now-unique-enough names.

Most developers won't (and shouldn't) simply ignore parts of the code they don't understand in the area they're working on. If something's meaning is obvious, they can move on to the part they're interested in, but if it's mysterious, they need to waste time figuring out why it's the way it is before they can feel confident enough to change anything near it.

@jnpkrn
Copy link
Contributor Author

jnpkrn commented Feb 13, 2017 via email

@kgaillot
Copy link
Contributor

Someone should be able to add a new header file by copying and editing an existing one without needing a decoding guide.

Additionally, without any enforcing mechanism, this is guaranteed to become wrong over time, at which point it becomes unreliable and can cause more trouble than it helps.

If we want to describe the purpose of a file, that's best done in a doxygen file block.

@jnpkrn
Copy link
Contributor Author

jnpkrn commented Feb 13, 2017 via email

@kgaillot
Copy link
Contributor

At worst it ends up as PCMK_foo__H. No issue here.

Right, if you redo this as PCMK_foo_H, I'll merge it.

Header guards should simply be unique; they should not encode any information. Readability and maintainability are more important here.

@jnpkrn
Copy link
Contributor Author

jnpkrn commented Feb 14, 2017 via email

@kgaillot
Copy link
Contributor

find -name '.h' -print0 \ | xargs -0 sed -i 's|( PCMK)(DEF|[^_ ]+[^_ ]+)([^_ ]__H)|\1\3|'

If you do that and update the first commit message, I'll merge this.

I am not merging a complex encoding of information into header guards. That is not the appropriate place for such information.

A large, distributed, community-driven project such as pacemaker must favor readability and maintainability across a wide range of developer mindsets and styles. Trust me, encoding information into header guards does not have wide appeal among developers. It hinders readability and maintainability. Our goal here is to help solve users' problems, not create a crystalline structure of pristine purity.

@jnpkrn
Copy link
Contributor Author

jnpkrn commented Feb 15, 2017

Ah, but the maintainability for the time being is the exact goal for that scheme...

@kgaillot
Copy link
Contributor

Let's not let this request gather dust. Please make the requested change, and I'll merge it.

@jnpkrn
Copy link
Contributor Author

jnpkrn commented Feb 16, 2017

Please make sure you understand the situation.

One more thing you should realize: if that command is applied (well,
use something other than | as a sed substitution delimiter, I used @),
you'll get some clashes (e.g. 2x PCMKUTIL__H), i.e., there's no
effective enhancement at all(!).

Last one time: I don't agree with your proposed (bikeshed-level in my
view) simplification and will not endorse it.

That being said, I am checking "allow edits from maintainers" box;
I cannot prevent you from remixing my change anyway, so if you want to
add an extra commit to the effect of running the suggested command on top,
so be it (at least GPG signatures will be retained).

(And I will be free to undo that change again for me locally via local
git attributes setting.)

@jnpkrn
Copy link
Contributor Author

jnpkrn commented Feb 16, 2017

(not endorse ... at this time)

@kgaillot
Copy link
Contributor

Cherry-picked the "Cleanup" commits, and merged with #1229

If you are able to make the requested change, feel free to re-submit the others.

@kgaillot kgaillot closed this Feb 16, 2017
@beekhof
Copy link
Member

beekhof commented Feb 16, 2017

Ken's first comment is spot on as demonstrated by the first "new" guard (PCMK_ATTRD_INTERNAL__H) which ironically doesn't conform to the proposed naming scheme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants