In the observer pattern, and similar, is there a meaningful difference between "subscribers" and "observers" in the wild, or in the lit? With RxJS and (functional) reactive programming, are the terms interchangeable?
3 Answers
Nearly all words used in programming are plain English terms that still retain all of their original semantics (or as much of it as applies to programming), since their purpose is to help English speakers explain technical concepts to other English speakers.
Example definitions of each term:
Subscriber (noun)
- "a person, company, etc., that subscribes, as to a publication or concert series."
- "a homeowner, apartment dweller, business, etc., that pays a monthly charge to be connected to a television cable service".
- "a person who promises to donate a sum of money, purchase stock, etc."
Observer (noun)
- "someone or something that observes."
- "a delegate to an assembly or gathering, who is sent to observe and report but not to take part officially in its activities."
The definition leading to Observe (verb) has the following example definitions:
- "to see, watch, perceive, or notice"
- "to regard with attention, especially so as to see or learn something"
- "to watch, view, or note for a scientific, official, or other special purpose"
The differences between the terms in English are that subscription tends to be either more deliberate, focused or proactive around a subject. Observation might involve less focus or be a more passive activity.
These terms clearly have overlapping semantics in English, with the term 'observe' being far more general and abstract. As Karl points out in his answer, they are often used interchangeably in contexts where any minor semantic differences between them aren't important, such as the example given in the question with ReactiveX.
In some specific contexts, there are more obvious reasons for choosing one term over the other, for example, the Publish-Subscribe messaging pattern uses 'subscriber' to convey the importance of each recipient needing to deliberately express an interest in receiving messages.
While a 'subscriber' could easily be described as an 'observer' in this pattern, the term has weaker connotations and intent. i.e. For a person described as an 'observer', it may simply not be important whether or not that person has actually expressed any particular interest in receiving some information. However, in the context of the messaging pattern, 'expression of interest' is an important, distinguishing feature.
As always, naming things is a hard thing to do - people who choose between names like Observer or Subscriber need to think long and hard about context. A word which is too general just risks losing the audience through lack of clarity or purpose. A word which is already loaded with specific connotations risks misleading the audience if those connotations don't match the technical concept.
- 12,133
The terms are mostly interchangeable, but there are subtle differences in specific implementations. For example, a Monix Subscriber is described as "an Observer with an attached Scheduler." I don't believe that's a universal distinction, though, just one of those difficult naming problems of programming where it's more convenient to use a synonym than an annoying compound name like ObserverWithScheduler.
- 148,830
In Rx speak an Observer is something that can get notifications from a data source and a Subscriber is an observer that can also unsubscribe from that source.
Subscriber - Implements the Observer interface and extends the Subscription class. While the Observer is the public API for consuming the values of an Observable, all Observers get converted to a Subscriber, in order to provide Subscription-like capabilities such as unsubscribe. Subscriber is a common type in RxJS, and crucial for implementing operators, but it is rarely used as a public API.
That's just Rx terminology - in a regular programmer discussion the terms are interchangeable even if they have slightly different but similar meanings a bit like arguments and parameters.
- 5,217