Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite function that take Stream pointer to take a reference to Stream instead #3

Open
sofian opened this issue Jan 25, 2023 · 0 comments

Comments

@sofian
Copy link
Contributor

sofian commented Jan 25, 2023

I suggest we change function:

bool parseStream(Stream*, callbackFunction)

to:

bool parseStream(Stream&, callbackFunction)

Same for functions such as streamPacket(Stream*) and others.

We could keep the old functions for backwards compatibility but the reference version would be preferred.

There is a discussion here on when to use references vs pointers, I believe it applies to our case:
https://stackoverflow.com/questions/7058339/when-to-use-references-vs-pointers

There are several reasons but the two main ones are:

  1. It would be more digestible for newbies to have to understand that they need to use a pointer ie. they would not need to call parseStream(&Serial) but simply parseStream(Serial).
  2. It prevents sending erroneous addresses including parseStream(0) which is syntactically valid but will result in a runtime error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant