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

Avoid colliding with macro names B1 and PI #247

Merged
merged 1 commit into from
Jun 22, 2024
Merged

Conversation

chiphogg
Copy link
Contributor

@chiphogg chiphogg commented Jun 20, 2024

This helps Arduino compatibility.

Of course, this whole situation is an excellent case in point to
illustrate why, if you must use macros, never to give them such
easily collidable names. But that is not the users' fault, so since we
can work around the problem, we do so.

The B1 template parameter can be renamed to B without loss of
readability.

PI is a little more challenging. We do use it in one place in our
code, in defining Degrees, so we must replace that with its definition
of Magnitude<Pi>{}. We provide workaround instructions in the
comments. We leave alone the many instances of PI in test files,
since that shouldn't affect these users.

Helps #246.

This helps Arduino compatibility.

Of course, this whole situation is an excellent case in point to
illustrate why, if you _must_ use macros, _never_ to give them such
easily collidable names.  But that is not the users' fault, so since we
can work around the problem, we do so.

The `B1` template parameter can be renamed to `B` without loss of
readability.

`PI` is a little more challenging.  We do use it in one place in our
code, in defining `Degrees`, so we must replace that with its definition
of `Magnitude<Pi>{}`.  We provide workaround instructions in the
comments.  We leave alone the many instances of `PI` in test files,
since that shouldn't affect these users.
@chiphogg chiphogg added the release notes: 🐛 lib (bugfix) PR fixing a defect in the library code label Jun 20, 2024
@chiphogg chiphogg requested a review from geoffviola June 20, 2024 14:00
// accommodate those frameworks by omitting the definition of `PI` in this case.
//
// If you are stuck with such a framework, you can choose a different name that does not collide,
// and reproduce the following line in your own system.
static constexpr auto PI = Magnitude<Pi>{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is a perfect solution. It would depend on the order of includes. The order of headers is not great to reason about.

I don't have great ideas for alternative solutions 😓

  1. Use Google style guide for naming constants kBlah. It generally won't collide with macros, but it is ugly.
  2. Rename PI to something like AUPI. It would be unique, but it's more verbose and farther from the simple Greek letter. Also, that is what namespaces are for 😄
  3. Define PI in another header. This would require more fine grained header management.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having slept on this, I'm leaning towards Option 4: just don't define PI. Using really short all-caps names is a recipe for collision with poorly designed frameworks. That's not to say we'll never do it, but it seems wise to minimize how much we do it. And in this case, we have a clear collision with the Arduino framework, which we'd really like to support, so I think our PI has to go.

I'll deprecate it in a follow on PR for ease of review. I think we'll still want to retain the #ifndef guards until we remove it entirely (probably in 0.4.0).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards 1. It adds one ugly character, but it is consistent and reduces conflicts.

Deleting it for now buys us time. It's a good idea to minimize Au's public API. At some point, we should design a path forward for constants that works for most users.

@chiphogg chiphogg merged commit bd36cc5 into main Jun 22, 2024
10 checks passed
@chiphogg chiphogg deleted the chiphogg/dodge-macros#246 branch June 22, 2024 00:05
chiphogg added a commit that referenced this pull request Aug 12, 2024
It conflicts with the `pascal` macro in `<Windows.h>`.  Yes, they really
did define a lowercase-named macro in `<Windows.h>`.

As with `PI` (#247), the `#ifndef` should immediately unblock most
users, but it's not a long-term solution, because it depends on
order-of-includes.  Therefore, we also deprecate `pascal` (as with `PI`
in #250).  I think a good rule of thumb is that deprecated constructs
should be deprecated for at least one full minor release cycle, so we'll
plan to delete it (along with `PI`) as part of 0.5.0.

Fixes #284.
@chiphogg chiphogg mentioned this pull request Aug 12, 2024
chiphogg added a commit that referenced this pull request Aug 12, 2024
It conflicts with the `pascal` macro in `<Windows.h>`.  Yes, they really
did define a lowercase-named macro in `<Windows.h>`.

As with `PI` (#247), the `#ifndef` should immediately unblock most
users, but it's not a long-term solution, because it depends on
order-of-includes.  Therefore, we also deprecate `pascal` (as with `PI`
in #250).  I think a good rule of thumb is that deprecated constructs
should be deprecated for at least one full minor release cycle, so we'll
plan to delete it (along with `PI`) as part of 0.5.0.

Fixes #284.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: 🐛 lib (bugfix) PR fixing a defect in the library code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants