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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better naming of implementations #13

Open
mecha opened this issue Nov 24, 2022 · 1 comment
Open

Better naming of implementations #13

mecha opened this issue Nov 24, 2022 · 1 comment
Labels
question Further information is requested

Comments

@mecha
Copy link
Member

mecha commented Nov 24, 2022

Even as the original author of most of the classes in this package, I've often found myself annoyed at how they are named 馃槄 We could easily improve this using class aliases.

The proposal that I outline below stems from this viewpoint: the names should reflect what the services are. For instance:

[
    // message IS a value
	'message' => new Value('Hello'),

    // greeting IS an alias
    'greeting' => new Alias('message'),

    // username IS a global var
    'username' => new GlobalVar('username'),

    // BUT ...

    // logger is ... a constructor??
    'logger' => new Constructor(Logger::class),

    // alert_text is a ... string service??
    'alert_text' => new StringService("{0}, {1}!", [
        'message',
        'username',
    ]),

    // render_fn is a funky what??
    'render_fn' => new FuncService(['message'], function (string $message) {
        return $message;
    }),
]

It would be great if all the classes had more sensible names that better outlined what the services are, rather than what the service definitions are.

I've prepared a list of which classes I think could use a better name, along with my proposed alias names:

Current name New Alias name
Constructor Instance
FuncService Callback
StringService TemplatedString

These proposed names will help to make service definitions look more natural and declarative.

[
    // logger IS an instance
    'logger' => new Instance(Logger::class),

    // alert_text IS a templated string
    'alert_text' => new TemplatedString("{0}, {1}!", [
        'message',
        'username',
    ]),

    // render_fn IS a callback
    'render_fn' => new Callback(['message'], function (string $message) {
        return $message;
    }),
]

While we're at it, we could also alias the ArrayExtension class to ArrayPushExtension, in preparation for the new ArrayMergeExtension to create a clearer distinction between the two.

Thoughts?

@mecha mecha added the question Further information is requested label Nov 24, 2022
@XedinUnknown
Copy link
Member

Sounds great! I'd be happy to review and merge that.

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

No branches or pull requests

2 participants