1

Since I'm not a native English speaker I better make sure not to create an DSL that would sound awkward for others. A DI container emerged out of a project and I'm isolating it as a seperate project. I see other DI/IOC containers using syntax like bind(interface).to(class). I would use the following (pseudo-code):

given(interface).thenUse(class)
given(class).constructWith(id=5)
given(class).inject(observer).inMethod(addObserver)

Do these make sense or does it sound like a construction from someone who doesn't grasp the some finer semantics of these words?

1 Answer 1

2
+300

I think your approach makes just as much sense as the examples from other DI projects.

Few notes:

  1. bind/to is shorter to write than given/thenUse. This is not a problem in itself, but if you can achieve the same meaning with shorter names, there is not much reason to use the longer ones (in the given examples they both read the same)

  2. If there is an established name pattern for the same use then life will be easier (e.g. grasping the concept/meaning) for users who know the established pattern coming to your implementation, which will be a benefit.

    If you are after "converting" users of other similar libraries/tool to yours, using the smae naming convention lowers the barrier of entry for those users.

    If your implmentation is conceptually different is some ways, however, it might be better to use different names to emphasize the difference and reduce cognitive dissonance (between what is expected and what is happening).

    If you think (one of) the other naming patterns have a flaw in them that creates cognitive dissonance (between what the name implies and what it actually does), replacing it with a better naming scheme could mean more followers.

  3. While given(class).inject(param).inMethod(method) reads well in English, it has an order of objects that might be counterintuitive for someone (class/param/method as opposed to class/method/param, which is the natural order for OO languages: Class.method(param);); consider: given(class).and(method).useParam(param)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.