-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Sensor emits null argument too much #553
Comments
@boneskull Wow, you weren't kidding about err being |
The "error-first callback" is pretty much the standard in Node. I agree that our |
Patch welcome I guess. |
Said patch needs to update all tests and examples. |
I'm sure no one will like this, but I think the "error-first [cargo cult] convention" is a bad programming pattern. I started off doing that and overtime it was clear that there was nothing interesting to pass there, and abandoned it. For the sake of not breaking code, I left the old cases alone and just didn't follow the pattern in new APIs. I don't really care either way, someone's code will be broken but it needs to be addressed for the sake of consistency. |
I'm rather ambivalent about it as a programming pattern, so I wouldn't say that I don't like your opinion. Consistency within the project is more important than consistency with other Node projects IMO. If given my druthers, however, I tend to prefer consistency with the idioms of the environment, if only to play well with others. "Error-first" lets us interop with thunks and promises when we want to (I realize that thunks and promises don't always make sense in J5, but sometimes they do). They make our APIs more accessible to new developers, etc. I do care enough to make it consistent. In my recent contributions, I had to make the seemingly arbitrary choice and a clear choice would have felt cleaner.. I'd be happy to make a consistency pass as long as we define what the consistent approach is. :) |
Events != async callbacks. I'd prefer error-first for callbacks, for consistency (and interoperability with libs like But I've never seen a pattern in any library where all events emit an (Note that if you do emit an |
I agree, basically. But my real beef is with callbacks in general. I'm no NodeJS history buff, but Promises seemed to become popular because of the overuse of callbacks in NodeJS code. In my experience, most asynchronous tasks can be handled more cleanly and elegantly with Promises (and the proper library). As @rwaldron mentioned in another ticket, the pattern has limitations, but generally I've found if you write code "Promise-first" you don't have many problems. But unfortunately, converting a callback-based codebase to a Promise-based is daunting and won't result in a clean mapping. I'm not advocating that, mind you--just offering an opinion. |
Right.
Yeah, that is right too. Two great points. And the dos for |
Let's...
|
Sounds like a plan. @boneskull, were you planning on tackling this? If not, I'd be happy to, but I'm not likely to think about it for a couple of weeks. (still have lots to do for my NodeBots event on 1/6) |
@BrianGenisio Unlikely. I have a billion projects and time for none of them. |
Question since I've not dealt with error-first pattern much. In some cases, like in Led, we typically don't pass anything back in the callback. But instead of just calling |
Also, should examples like that in Led use |
@rwaldron preferred name for callback functions? Looks like we have at least |
Do y'all feel that callbacks and listeners are the same thing? This thread doesn't seem to make a distinction between the two. I've always considered them to be different (listeners being bound to event emitters, callbacks being... well... callbacks that aren't listeners). Aside: Even the node.js event emitter docs use both labels. err first on callbacks is an established practice but it is not an established practice on event listeners. I think that's why err first feels so wrong here. Instead, event emitters should emit an "error" when appropriate and we should have listeners for that. |
@dtex: @boneskull pointed this out earlier in the thread and I think we all agree that there is a distinction, and that "error-first" doesn't make sense for events, only for async callbacks. Per @rwaldron's request, someone (possibly me when time permits) will go through the code and fix |
Ah, thank you. I overlooked that. |
Sorry for being inconsistent over the years and thank you all for helping identify these things so we can clean them up :) Also, @boneskull: keep up the great deep digging! |
@rwaldron As action was taken and 2 new issues raised from this thread, I assume this issue can be closed. |
Yeah, that's fine. I'm maintaining the patch until we commit to 0.9.0 |
For most/all events emitted in
Sensor
, the first argument is the variableerr
, which seems to always benull
. Remove it?The text was updated successfully, but these errors were encountered: