1
\$\begingroup\$

I am writing an open-source application for real-time messaging in web. In my application clients from browser can subscribe on channels. But every channel belongs to a certain namespace which determines channel's settings:

client.subscribe('/football/news', function(message) {
    // message from channel received
});

where football is namespace name and news is channel name. football can be a default namespace for project and in this case we can write in this way:

client.subscribe('/news', function(message) {
    // message from channel received
});

i.e. without namespace name. This is how it works right now.

But my question is about / path separator. Is it ok? We need the way do separate namespace name and channel name. / usage was influenced by Bayeux protocol spec. But maybe it would be more simple and correct to write in such manner:

client.subscribe('football', 'news', function(message) {
    // message from channel received
});

or with default namespace:

client.subscribe(null, 'news', function(message) {
    // message from channel received
});

or even:

client.subscribe('news', function(message) {
    // message from channel received
});

I personally feel that the second way is better. But before refactoring I decided to ask for your opinion.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

An opinion question, always tough to answer.

I like the first way better, 1 less parameter and it is easier to grok for me.

Incidentally, ABAP uses forward slashes for namespaces as well.

\$\endgroup\$
3
  • \$\begingroup\$ btw, I think using '\' makes creating full path harder for end user - we must properly concatenate strings - namespace and channel. \$\endgroup\$ Commented Sep 12, 2013 at 21:36
  • \$\begingroup\$ How about '/sports/football/news' ( 2 levels ), how would you do that with approach 2? \$\endgroup\$
    – konijn
    Commented Sep 12, 2013 at 21:57
  • \$\begingroup\$ in my app only 1 level is allowed. I don't see any serious advantages in using hierarchy channels. Wildcards maybe? But are they really necessary? \$\endgroup\$ Commented Sep 13, 2013 at 5:39
1
\$\begingroup\$

If you always have two levels, then passing two parameters has its advantages.

If the channels form an arbitrarily deep hierarchy, then a /path/to/the/channel makes more sense.

\$\endgroup\$

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.