-
Notifications
You must be signed in to change notification settings - Fork 492
Refactor Firebase class, improve api, change style #41
Comments
The rational behind this was to make it easy to get the response content from the method call, without having to exposing to much types to the user. I noticed that Arduino library tend to be simpler than other C++ codebase and not push OO in the face of the user. I'd love to hear from you if you share similar observations. I go a little bit further that road in #43, where we only return the data when the user explicitly ask for it:
http://man7.org/linux/man-pages/man3/errno.3.html also come to mind.
My goal was actually the opposite: to make it really easy to check for error whatever the context: just test
Do you think that's a concern for arduino devices? So far I only encountered single core MCUs. I was not too concerned by maintaining the
I will post comments on the codereview, I'd like use to converge on a way that make error checking more obvious while keeping the API simple.
+1 for this and enforcing it with travis (see #39), something else we need to take into account is having an API surface close to the Arduino style as well (i.e: user of the code shouldn't have to deal with inheritance, usually no exception handling and libraries tend to expose native type instead of introducing new types). Maybe this deserve a separate pull request, but it's also interesting to discuss the API change in the context of readability. |
A few more elements from an offline discussion with @ed7coyne and @mimming. We could have one result type by API method w/ specific results member and common methods for
The first implementation could consume the result payload so that the main http client could be reused right away. Later a lazy flag could be exposed to have more concurrent behavior with ephemeral http clients. The stream implementation could use it's own http client once the backend url redirection is fully negociated. |
Like @mimming pointed out that would also allow bi-directional I/O with push() and stream() with only 1 |
Fixed with #42 |
Problem still exit is stream and push or set together Error screenshot: http://cloud.tabvn.com/b2ldqi.png #include <ESP8266WiFi.h> // Set these to run example. FirebaseArduino FirebaseStream; void setup() { // connect to wifi. FirebaseStream.begin(FIREBASE_HOST, FIREBASE_AUTH); } int n; Serial.println("loop"); if (FirebaseStream.failed()) { if (FirebaseStream.available()) {
} } |
I think we should refactor the Firebase class, while it is young and small seems the best time to do it.
I am personally against to the current paradigm of "do an action" then "explicitly check for error()". While this is exposed in professional apis (win32 comes to mind) it is usually not well regarded as those interfaces age. It is error prone as it is very easy to not explicitly check for the error than use the result as if it succeeded. It also has thread safety implications.
I propose that instead we return a FirebaseResult class that contains the status code and an optional result body and exposes helpers like is_error().
I also think we should take this time to standardize style guidelines for this class. Personally I propose using the Google C Style guide (https://google.github.io/styleguide/cppguide.html) as much as they apply to wirinig in its c-likeness. I think there is value in uniformity of the code as it develops, I am open to other styles as well but I think we should try to standardize on one if we can.
I will put together a pull request reflecting this change if no one has any objections.
The text was updated successfully, but these errors were encountered: