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

Fix readability warnings #1722

Merged
merged 3 commits into from
Nov 24, 2023
Merged

Fix readability warnings #1722

merged 3 commits into from
Nov 24, 2023

Conversation

jfsimoneau
Copy link
Contributor

Did not fix readbility-qualified-auto, will do a separate pull request

httplib.h Outdated
// TODO: check if Content-Length is set
return false;
return (req.method == "POST" || req.method == "PUT" ||
Copy link
Owner

Choose a reason for hiding this comment

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

This is incorrect. I intentionally put the if statement before the TODO comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see. Something will come after the first check. I will revert this part.

httplib.h Outdated
@@ -868,15 +868,16 @@ class Server {
bool routing(Request &req, Response &res, Stream &strm);
bool handle_file_request(const Request &req, Response &res,
bool head = false);
bool dispatch_request(Request &req, Response &res, const Handlers &handlers);
bool
static bool dispatch_request(Request &req, Response &res,
Copy link
Owner

Choose a reason for hiding this comment

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

I don't like to put 'static'. It's less readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand your feeling, but having a static method means the this pointer is not passed as an automatic parameter. This will reduce the call overhead a little bit and ensure the calling instance won't affect the outcome or be affected by any side-effect.

httplib.h Outdated
@@ -8361,7 +8363,7 @@ inline SSLClient::SSLClient(const std::string &host, int port,
: ClientImpl(host, port, client_cert_path, client_key_path) {
ctx_ = SSL_CTX_new(TLS_client_method());

detail::split(&host_[0], &host_[host_.size()], '.',
detail::split(host_.data(), &host_[host_.size()], '.',
Copy link
Owner

@yhirose yhirose Nov 21, 2023

Choose a reason for hiding this comment

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

If we do host.data(), should we do the same to &host[host.size()] like host_data() + host.size()? This change actually creates inconsistency and made the code less readable...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I overlooked this case.

Copy link
Owner

Choose a reason for hiding this comment

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

I am ok with the notation like &a[0]. IMHO, most of C/C++ programmers know what it means, and it's a common notation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you, the meaning is very well-known. In this particular case, it even makes more sense to use this notation because of the begin/end parameters of detail::split() for iteration. In the other cases, the meaning really is to put data into a vector's buffer.

@yhirose
Copy link
Owner

yhirose commented Nov 21, 2023

@jfsimoneau I basically don't agree half of changes like adding static...

Did not fix readbility-qualified-auto, will do a separate pull request
@yhirose
Copy link
Owner

yhirose commented Nov 24, 2023

Could you leave only changes for adding missing const, removing unnecessary const, and adding missing curly braces? As for static`, it still make me confused when reading the class. I know what you mentioned, but I would like to keep the code as it is. Thanks for your understanding!

@jfsimoneau
Copy link
Contributor Author

Sure, on it!

@jfsimoneau
Copy link
Contributor Author

Replaced all static methods with const methods to emphasize the absence of side-effects. Also reverted the .data() accessors to leave &var[0] so it's consistent everywhere.

I did notice most static methods could also be hidden internal functions or helper functions instead of class methods, except some internal class member access like private classes. Worth noting, but I won't touch that; if it's not broken, don't fix it.

@yhirose yhirose merged commit 115a786 into yhirose:master Nov 24, 2023
4 checks passed
@jfsimoneau jfsimoneau deleted the fix-readability branch November 24, 2023 14:57
@yhirose
Copy link
Owner

yhirose commented Nov 24, 2023

Thanks for all the improvements.

I did notice most static methods could also be hidden internal functions or helper functions instead of class methods, except some internal class member access like private classes. Worth noting, but I won't touch that; if it's not broken, don't fix it.

When I have time, I'll take a look at the code and thing about what I can do. Thanks again for your fine contribution!

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.

2 participants