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

Establish convention for function naming and enforce it #363

Open
lhstrh opened this issue Feb 23, 2024 · 1 comment
Open

Establish convention for function naming and enforce it #363

lhstrh opened this issue Feb 23, 2024 · 1 comment

Comments

@lhstrh
Copy link
Member

lhstrh commented Feb 23, 2024

What is our convention for selecting the name for a function that "does something" between the following:

  1. do_something
  2. lf_do_something
  3. _lf_do_something

Good question. I think the original intent was that do_something should only be used for static functions, where the scope is limited to the file. lf_do_something should be used for user-facing functions, such as those used in reaction bodies. And _lf_do_something should be used for things that can't be static because they are used in multiple files, but they are functions that a user would never invoke.

The problem I ran into is that it's not always clear which functions a user might want to invoke, and this could change over time. For example, should it be lf_new_reactor or _lf_new_reactor? lf_allocate or _lf_allocate?

I've been opting for doing away with the leading underscore when there is any doubt, but I wonder whether we should do away with it completely? Whether something is user facing, I think, should be determined by which header file declares it. If it's declared in reactor.h, then it is user facing and is in scope for reactions. If it is declared in reactor_common.h, then it is not in scope for reactions. If we organize the Doxygen docs well, all of this could be made very clear.

An advantage of doing away with the underscores altogether is that we can change our minds later relatively easily. Right now, _lf_schedule_at_tag is not a user-facing function, but maybe we will want it to be later. If we remove the leading underscore now, then the change is painless: Just move its declaration to reactor.h.

So my proposal is:

  1. do_something for static functions (scope limited to the current file).
  2. lf_do_something for everything else.

This PR does not make this change, but maybe we can do is part of the formatting PR? Or as a separate PR in rapid succession?

Edward

Originally posted by @edwardalee in #354 (comment)

@petervdonovan
Copy link
Contributor

This seems like the sort of thing that can be automated, much like formatting. If we choose to care about such things then it would be nice if at least we do not have to expect human beings to care about them when they are doing manual code review.

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

No branches or pull requests

2 participants