moll / node-mitm

Intercept and mock outgoing Node.js network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Super useful when testing code that hits remote servers.
Other
636 stars 48 forks source link

Confusing naming #21

Closed goloroden closed 8 years ago

goloroden commented 9 years ago

According to the documentation, the main entry point is Mitm. In JavaScript, things that start with an upper-case character are usually meant to be used as a constructor function.

Hence I ran

let mitm = new Mitm();

only to find out that it doesn't work. After a while I discovered that the documentation says that one should use it as a normal function, not as a constructor:

let mitm = Mitm();

This seems confusing, because developers may think (like me ;-)) that it is a constructor.

What do you think about either changing the name in the documentation to something with a lowercase character?

moll commented 9 years ago

Hey,

Thanks for the report and sorry about the confusion. Technically, it is a constructor. :smile_cat: And a factory function at the same time. One option would be to name the factory form of it as intercept, to make it a verb, leaving the lowercase mitm to correctly refer to an instance of Mitm. I don't really know. What's your opinion?

goloroden commented 9 years ago

Well, I just imported as getMime, so that the questionable lines were:

const getMime = require('mime');
let mime = getMime();

What do you think about this for the documentation?

moll commented 9 years ago

I presume you meant "mitm" where you used "mime" above? ^_^ get is probably not the best prefix — get would refer to a getter and side effects in getters are surprising. ;-) Mitm as a factory function however does have a side effect — it intercepts all connections (short for new Mitm().enable(). Something named after its behavior might be more intuitive...

moll commented 8 years ago

I'll close this until we come up with something actionable. Further conversation welcome however. :)