[Code health] Consistent naming of Rx streams
See original GitHub issue@scolsen listened to this podcast after our chat. I agree with most of the suggestions there. Key takeaways (mixed with my own observations):
- There’s no single convention used by everyone, but there are some prevailing trends.
- The
getFoo()
pattern is dated, a relic of JavaBeans naming conventions. - Consistent naming >> relying on return types as documentation:
- Doesn’t require developers to look at declaration to understand semantics.
- Prevents signatures from collide if we add an override that returns a different Rx type.
Some ideas/suggestions:
- Use
foo()
for immutable synchronous accessors (e.g.User user()
)… There’s also precedent for this in JDK methods likevalues()
. fooOnce()
for Rx types that return a single value and complete (usuallySingle<>
).fooStream()
for Rx types that are expected to not complete while the application is in a normal state.
A similar approach is also described here.
Wdyt? No need to change existing uses now, but new code could use the convention, and we can update existing code once V0 is ready.
@navinsivakumar FYI.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Introduction to Medical Terminologies and RxNorm
Introduction to Medical Terminologies and RxNorm ... medical terminologies and provide an introduction to RxNorm - a standardized naming system for clinical ...
Read more >Using National Drug Codes and Drug Knowledge Bases to ...
There is no accepted name for the universe of codes we are describing. Many refer to them casually as NDC codes.
Read more >Circuit breakers statistics - Cluster manager - Envoy Proxy
Number of health checks that attempted cluster name verification. healthy ... If HTTP is used, dynamic HTTP response code statistics are also available....
Read more >HETS 270/271 Companion Guide - 5010 - CMS
Health Care Eligibility Benefit Inquiry and Response. (270/271). 5010 Companion Guide ... Envelope Processing Status and Error Codes .
Read more >Interoperability in Healthcare | HIMSS
It enables the consistent, processable representation of clinical content in electronic health records (EHRs). These codes often represent the “answer” for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah! Great point to raise! Definitely something we should address. I think the right approach is actually to just fix all the function bodies so that we don’t mix eager/lazy eval rather than use a naming convention. Generally speaking I’m also a fan of eliminating as much of the imperative code that we can (right now we do have quite the amalgam of functional/imperative style). wdyt?
One other thing; we should also take care when naming fields referencing
Subjects
backing these streams. It may be tempting (as I did in my previous deleted comment) to name them according to the method convention:PublishSubject<User> userStream;
BehaviorSubject<User> userOnceAndStream;
But recall that the “Once” part is a function of the streams’ behavior, not their underlying type. The first stream could easily be set up to emit a value immediately when the method is called. For that reason, it might be better to just name them for the fact that they’re subjects:
PublishSubject<User> userSubject;
orBehaviorSubject<User> userSubject;
This also makes it clear that values can be emitted via those fields by calling
userSubject.onNext()
.Completable
,Maybe
, andSingle
will rarely be used as fields, but I assume we would follow the same convention as for method names (methodgetUser()
returns fielduser
).