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

Function prefixes #63

Closed
kroggen opened this issue Jun 4, 2019 · 1 comment
Closed

Function prefixes #63

kroggen opened this issue Jun 4, 2019 · 1 comment

Comments

@kroggen
Copy link

kroggen commented Jun 4, 2019

First, congratulations for the work!

I was seeing the example usage:

// Listen to HTTP requests and start facil.io
int main(int argc, char const **argv) {
  // allocating values we use often
  HTTP_X_DATA = fiobj_str_new("X-Data", 6);
  // listen on port 3000 and any available network binding (NULL == 0.0.0.0)
  http_listen("3000", NULL, .on_request = on_request, .log = 1);
  // start the server
  facil_run(.threads = 1);
  // deallocating the common values
  fiobj_free(HTTP_X_DATA);
}

And, at least for me, using 3 different prefixes (http, fiobj, facil) appear a bit unintuitive.

What about all prefixes being just http_?

In this way we don't need to remember each functions should use this or that prefix. The learning curve is smaller, and hence the adoption can be bigger.

Just an idea.

Another thing is this line:

FIOBJ HTTP_X_DATA;

Generally in C we use uppercase letters for constants, but this is a variable.

The typedef is also in uppercase. A bit unusual for me.

But this can be less important.

Cheers,

@boazsegev
Copy link
Owner

Hi @kroggen ,

Thank you for opening this issue.

This appears to be an issue related to the 0.6.x API if I am correct.

In 0.7.x versions you will find more consistency. All facil.io core functions where moved to the fio_ namespace (prefix).

As for merging all namespaces to a single namespace, I believe this would be a mistake.

The facil.io library is a modular library. The facil.io core isn't limited to HTTP services, and can be easily compiled without the HTTP services extension.

Also, facil.io and it's extensions provide quite a large number of functions. When using an IDE, the different namespaces / prefixes empower the auto-complete feature to make meaningful suggestions in less time.

As for going forwards and suggesting further improvements towards the upcoming 0.8.0 API, please feel free to join the discussion in issue #60. It would be great to read your opinion on these issues.

Kindly,
Bo.

P.S.

In this specific case, the HTTP_X_DATA is a constant, it's just not a compile-time constant and has to be initialized (and eventually destroyed) during runtime.

The FIOBJ type name started as a macro and I've kept it this way because I want to be able to change the implementation easily (without changing the name or breaking existing code).

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

No branches or pull requests

2 participants