FairRoot icon indicating copy to clipboard operation
FairRoot copied to clipboard

Create `FairBaseTypes.h`

Open karabowi opened this issue 1 year ago • 6 comments

Created namespace FairRoot with struct EntryID {size_t fId;}.

Should replace PR #1405.


Checklist:

karabowi avatar Jun 13 '23 10:06 karabowi

Soooo, what are the benefits of going full type here?

What do we loose with a simpler:

namespace fairroot
{
using EntryID = size_t;
}

rbx avatar Jun 20 '23 11:06 rbx

Soooo, what are the benefits of going full type here?

I guess, the idea would be to have safer-to-use and better-self-documenting function signatures (and call sites), e.g.

void RunReco(EntryID start, EntryID stop); // range [start, stop]
void RunReco(EntryID start, int n);        // range [start, start + n]
void RunReco(EntryID id);                  // single entry
void RunReco(int n);                       // n entries (starting from some implicit cursor)

With an alias it would be less clear what is meant and the compiler couldn't help you, if you misuse one of the signatures. (some overloads wouldn't even be possible). Now imagine argument lists with even more int args, where some are timeouts in seconds, different ids etc, easy to mess up the order when calling.

dennisklein avatar Jun 20 '23 12:06 dennisklein

@rbx But I am not 100% convinced myself, if this is the best use case for a "strong alias". Especially, as there is already existing code using all kinds of int, uint, size_t etc for the same thing including serialized root files that need to be read back etc. Not sure, how much will break for the good or the worse^^

dennisklein avatar Jun 20 '23 12:06 dennisklein

If we see a potential for more "strong aliases" like this one in the near future, we could adopt the templates proposed here: https://www.foonathan.net/2016/10/strong-typedefs/

dennisklein avatar Jun 20 '23 13:06 dennisklein

Soooo, what are the benefits of going full type here?

I guess, the idea would be to have safer-to-use and better-self-documenting function signatures (and call sites), e.g.

void RunReco(EntryID start, EntryID stop); // range [start, stop]
void RunReco(EntryID start, int n);        // range [start, start + n]
void RunReco(EntryID id);                  // single entry
void RunReco(int n);                       // n entries (starting from some implicit cursor)

With an alias it would be less clear what is meant and the compiler couldn't help you, if you misuse one of the signatures. (some overloads wouldn't even be possible). Now imagine argument lists with even more int args, where some are timeouts in seconds, different ids etc, easy to mess up the order when calling.

Are you also proposing to ultimately replace the Run() functions with RunReco()?

karabowi avatar Jun 20 '23 13:06 karabowi

Soooo, what are the benefits of going full type here?

I guess, the idea would be to have safer-to-use and better-self-documenting function signatures (and call sites), e.g.

void RunReco(EntryID start, EntryID stop); // range [start, stop]
void RunReco(EntryID start, int n);        // range [start, start + n]
void RunReco(EntryID id);                  // single entry
void RunReco(int n);                       // n entries (starting from some implicit cursor)

With an alias it would be less clear what is meant and the compiler couldn't help you, if you misuse one of the signatures. (some overloads wouldn't even be possible). Now imagine argument lists with even more int args, where some are timeouts in seconds, different ids etc, easy to mess up the order when calling.

Are you also proposing to ultimately replace the Run() functions with RunReco()?

? I cannot follow

dennisklein avatar Jun 20 '23 14:06 dennisklein