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

Better option for options (pun intended) #1

Open
leha-bot opened this issue Dec 8, 2021 · 3 comments
Open

Better option for options (pun intended) #1

leha-bot opened this issue Dec 8, 2021 · 3 comments
Labels
library design idea question Further information is requested

Comments

@leha-bot
Copy link
Member

leha-bot commented Dec 8, 2021

In private conversation @nenomius suggests that instead of this options initializing:

options.option(option{}, option{}, option{});

it's better to use:

auto options = libname::options{option, option, option, option}

hey, guys, @shiz01 , @oficsu , what do you think about this design idea?

@leha-bot leha-bot added question Further information is requested library design idea labels Dec 8, 2021
@oficsu
Copy link
Collaborator

oficsu commented Dec 8, 2021

As I can see, there has been already implemented pipe syntax like this:

auto options = libname::options{ argc, argv }
    | libname::option( /* ... */ )
    | libname::option( /* ... */ );

With ADL, we can remove redundant libname mentions and improve readability:

auto options = libname::options{ argc, argv }
    | option( /* ... */ )
    | option( /* ... */ );

But I'm not sure if this is a reliable tool. And I think, it's also possible to improve the first example and make it similar to the previous one:

auto options = libname::options{ argc, argv }
    .option( /* ... */ )
    .option( /* ... */ );

Isn't this the best from both worlds?

If in a future we want to have option groups, your second example might be changed to:

auto options = libname::options {
    libname::option( /* ... */ ), 
    libname::group("groupname"
        libname::option( /* ... */ ), 
        libname::option( /* ... */ ))
    libname::option( /* ... */ ),
};

And with my proposal to:

auto options = libname::options { argc, argv }
    .option( /* ... */ )
    .group("groupname")
        .option( /* ... */ )
        .option( /* ... */ )
    .close()
    .option( /* ... */ );

And I think it's more expressive syntax. But there may also be some drawbacks that I'm not seeing and these are only theoretical thoughts at now

@shiz01
Copy link
Collaborator

shiz01 commented Dec 13, 2021

Yes, it is planned to make builder-like syntax. But there’s no time yet :(

@shiz01
Copy link
Collaborator

shiz01 commented Dec 13, 2021

You can also add a constructor overload, with a variadic of options. Easy.
For:

auto options = libname::options{option, option, option, option};

But there is no free time at the moment :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library design idea question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants