Skip to content

Conversation

@skyline75489
Copy link
Collaborator

@skyline75489 skyline75489 commented Oct 29, 2019

Summary of the Pull Request

Replace some macros with modern constexpr.

References

#2941

PR Checklist

  • Closes #xxx
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

Macros are just very 1980s and should be used less.

I'm not sure which one is preferred, auto or concrete type.

Validation Steps Performed

Not needed.

_Inout_opt_ PSHORT psScrollY);

#define LOCAL_BUFFER_SIZE 100
constexpr auto LOCAL_BUFFER_SIZE = 100;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is used only in _stream.cpp. I have no idea why it's in the header file.

Copy link
Contributor

Choose a reason for hiding this comment

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

great question. I'd be fine moving it.

Copy link
Member

Choose a reason for hiding this comment

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

I just checked the history. The reason is historical artifact behind _stream.h (there wasn't a _stream.cpp in the past and it was a weird double-compiled thing for Western v. Eastern languages). I'm OK with this.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

This overall looks reasonable to me. I think there's been some push to change all constants to PascalCase, (@adiviness can cite the standard I'm thinking of) but this is goodness even without doing that.

#define BOTTOM_LEFT_CORNER 4
#define BOTTOM_RIGHT_CORNER 5

static constexpr auto UPPER_LEFT_CORNER = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should file a follow-up work item to turn this into a proper enum, instead of whatever this is.

Copy link
Member

Choose a reason for hiding this comment

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

(moved to #3366)

Copy link
Contributor

Choose a reason for hiding this comment

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

The standard I was trying to apply was that macros would be SCARY_CAPS and constexprs would be PascalCase.

Copy link
Contributor

Choose a reason for hiding this comment

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

@j4james has a PR that just gets rid of this layer of indirection, which seems fine to me. #3371

_Inout_opt_ PSHORT psScrollY);

#define LOCAL_BUFFER_SIZE 100
constexpr auto LOCAL_BUFFER_SIZE = 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

great question. I'd be fine moving it.

#define BOTTOM_LEFT_CORNER 4
#define BOTTOM_RIGHT_CORNER 5

static constexpr auto UPPER_LEFT_CORNER = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

@j4james has a PR that just gets rid of this layer of indirection, which seems fine to me. #3371

@skyline75489 skyline75489 force-pushed the fix/replaceMacroWithConstexpr1 branch from 52a563d to c8c35ca Compare October 31, 2019 01:19
@skyline75489
Copy link
Collaborator Author

Updated the PR in favor of #3371.

#include "terminalOutput.hpp"
#include <math.h>

#define XTERM_COLOR_TABLE_SIZE (256)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is duplicate of

constexpr WORD XTERM_COLOR_TABLE_SIZE = 256;


// To prevent invisible windows, set a lower threshold on window alpha channel.
#define MIN_WINDOW_OPACITY 0x4D // 0x4D is approximately 30% visible/opaque (70% transparent). Valid range is 0x00-0xff.
constexpr unsigned int MIN_WINDOW_OPACITY = 0x4D; // 0x4D is approximately 30% visible/opaque (70% transparent). Valid range is 0x00-0xff.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should this be WORD? See that's how much confusion #define caused us.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And by the way do we prefer WORD over unsigned short?

Copy link
Member

Choose a reason for hiding this comment

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

WORD is just a Windows-ism for unsigned short. I don't know strictly why other than Windows invented a lot of Windows-isms over the years. We've slowly been moving things to the more standard naming instead of the Windows-isms, so feel free to use unsigned short instead.

@skyline75489 skyline75489 force-pushed the fix/replaceMacroWithConstexpr1 branch from c8c35ca to d1312b5 Compare November 1, 2019 00:17
@skyline75489
Copy link
Collaborator Author

Updated the PR. For the naming part, there are too many rule-breaking constexpr like in

constexpr COLORREF INVALID_COLOR = 0xffffffff;

I think it's fair save the naming thing for future tasks.

@miniksa
Copy link
Member

miniksa commented Nov 1, 2019

Updated the PR. For the naming part, there are too many rule-breaking constexpr like in

constexpr COLORREF INVALID_COLOR = 0xffffffff;

I think it's fair save the naming thing for future tasks.

Agreed, feel free to file a follow-on issue for it.

@miniksa miniksa merged commit 86e0ea7 into microsoft:master Nov 1, 2019
@skyline75489 skyline75489 deleted the fix/replaceMacroWithConstexpr1 branch November 2, 2019 08:54
ghost pushed a commit that referenced this pull request Mar 29, 2021
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.

5 participants