question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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 like values().
  • fooOnce() for Rx types that return a single value and complete (usually Single<>).
  • fooStream() for Rx types that are expected to not complete while the application is in a normal state. fooOnceAndStream()` for Rx types that return a single value (the latest?) ASAP and then continue to stream updates 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:open
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
scolsencommented, Nov 17, 2019

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?

1reaction
gino-mcommented, May 10, 2019

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; or
  • BehaviorSubject<User> userSubject;

This also makes it clear that values can be emitted via those fields by calling userSubject.onNext().

Completable, Maybe, and Single will rarely be used as fields, but I assume we would follow the same convention as for method names (method getUser() returns field user).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found