-
Notifications
You must be signed in to change notification settings - Fork 29.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
Util(.is*) Deprecations #1301
Util(.is*) Deprecations #1301
Conversation
+1 If it can't be fixed, then kill it. |
-1. that is going too far. |
Deprecating is surely less painful. Removal would be.. eventually. Besides, most of these things aren't even used by core, and most of them are better done verbosely anyways. |
function isPrimitive(arg) { | ||
return arg === null || | ||
typeof arg !== 'object' && typeof arg !== 'function'; | ||
} | ||
exports.isPrimitive = isPrimitive; | ||
|
||
// still used in buffer and child_process |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be replaced in those files with Buffer.isBuffer()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, will do.
+1 Maybe we should consider moving the rest of the functions to the new |
I'm +1 on this. @isaacs |
+1 to this approach. If fixing is impossible, move users away from these functions gently. |
|
||
// note: the isRegExp function is still used here in util | ||
function isRegExp(re) { | ||
return re !== null && typeof re === 'object' && | ||
objectToString(re) === '[object RegExp]'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the objectToString
be sufficient here? Why do we need the other two checks?
@Fishrock123 could you possibly find the TC meeting where util.is was discussed and reference it here for us perhaps? It may alleviate concerns by the |
Only TC meeting reference I can find is here: TC 2015-02-18 Maybe you are referring to comments here? #822 (comment) |
@@ -504,49 +505,60 @@ const isArray = exports.isArray = Array.isArray; | |||
function isBoolean(arg) { | |||
return typeof arg === 'boolean'; | |||
} | |||
exports.isBoolean = isBoolean; | |||
exports.isBoolean = deprecate(isBoolean | |||
, 'util.is* functions are deprecated, please use a user-land alternative.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better for these to write it out for each, e.g., util.isBoolean is deprecated, please use a user-land alternative.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, I just copy-pasta'd these.
Also though, it may be worth messaging that all of these have been deprecated? I'm not so sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its better to be explicit. If someone is using additional is*, it'll bubble up somewhere else.
I also think We should consider better migration path. For example, we maintain We also discuss officail userland module in here #1019 |
I propose that this is voted on in the next TC meeting because:
|
6b6ff46
to
50ad0cc
Compare
Noticed some tests also rely on the logging functions that are deprecated. Should probably run a find/replace on all js files. Edit: Disregard me, these were already deprecated before. |
@@ -573,7 +585,8 @@ exports.isPrimitive = isPrimitive; | |||
function isBuffer(arg) { | |||
return arg instanceof Buffer; | |||
} | |||
exports.isBuffer = isBuffer; | |||
exports.isBuffer = deprecate(isBuffer, | |||
'util.isBuffer is deprecated, please use a user-land alternative.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should recommend using Buffer.isBuffer
, not a user-land alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops. Honestly, I don't even know why we use Buffer.isBuffer
either... it's just instannceof Buffer
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why Buffer.isBuffer
was added initially. That'd be interesting to find out.
That said, Buffer.isBuffer
has been incredibly useful to me in writing buffer
for browserify. The Buffer
constructor actually returns a Uint8Array
for performance reasons, but with all the buffer methods attached as properties. Works great, except for one edge case – instanceof Buffer
doesn't work anymore. So, I've been recommending that people use Buffer.isBuffer
and that's worked well. :-)
Eventually, I can just return a proper Buffer
that's a subclass of Uint8Array
(arrays are finally subclassable!) and instanceof Buffer
will start working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @trevnorris?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why Buffer.isBuffer was added initially. That'd be interesting to find out.
Once upon a time there existed the SlowBuffer class. It didn't inherit from Buffer so instances were buffers but not instanceof Buffer
.
SlowBuffer still exists but it's more or less obsolete. It inherits from Buffer now so instanceof
checks work.
As to why it didn't before, I don't exactly remember but it was probably accidental. SlowBuffer was an implementation detail - it was the backing store for normal buffers - and not something users normally interacted with directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bnoordhuis. That was before my time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, should I use instanceof Buffer
or better Buffer.isBuffer(...)
instead of util.isBuffer
in Node 0.12.7
and above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use Buffer.isBuffer which is not deprecated.
On Thu, Nov 12, 2015 at 3:55 AM hellboy81 notifications@github.com wrote:
In lib/util.js
#1301 (comment):@@ -573,7 +585,8 @@ exports.isPrimitive = isPrimitive;
function isBuffer(arg) {
return arg instanceof Buffer;
}
-exports.isBuffer = isBuffer;
+exports.isBuffer = deprecate(isBuffer,
- 'util.isBuffer is deprecated, please use a user-land alternative.');
OK, should I use instanceof Buffer instead of util.isBuffer in Node 0.12.7
and above?—
Reply to this email directly or view it on GitHub
https://github.com/nodejs/node/pull/1301/files#r44648758.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And isBuffer
is better than instanceof Buffer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are exactly the same.
On Thu, Nov 12, 2015 at 4:38 AM hellboy81 notifications@github.com wrote:
In lib/util.js
#1301 (comment):@@ -573,7 +585,8 @@ exports.isPrimitive = isPrimitive;
function isBuffer(arg) {
return arg instanceof Buffer;
}
-exports.isBuffer = isBuffer;
+exports.isBuffer = deprecate(isBuffer,
- 'util.isBuffer is deprecated, please use a user-land alternative.');
And isBuffer is better than instanceof Buffer ?
—
Reply to this email directly or view it on GitHub
https://github.com/nodejs/node/pull/1301/files#r44651882.
Instead of suggesting a user-land alternative for some of these, can we just suggest the actual code required? It's more helpful than sending the user off to search npm. Like this: util.isNull(arg) // "util.isNull is deprecated, please use `arg === null` instead"
util.isBoolean(arg) // "util.isBoolean is deprecated, please use `typeof arg === 'boolean'` instead" |
I agree. |
I like this too. Who wants to bake the patch? :) |
Yes, my concern is the deprecation message like util.isNull(arg) // "util.isNull is deprecated, please use `arg === null` instead"
util.isBoolean(arg) // "util.isBoolean is deprecated, please use `typeof arg === 'boolean'` instead" YES. This message is nice. Developers could understand the migration path. |
They are already deprecated in the docs though https://nodejs.org/dist/latest-v5.x/docs/api/util.html#util_util_iserror_object |
@evanlucas ... oh. Then yes this should happen in v6 I think? |
@Fishrock123 yes. Yay :) |
Changing to major so it can land anytime now. |
please use a user-land alternative - |
Not a fan of that, too. The term user-land is probably not immediately clear, and if I wouldn't know better, I'd associate it with stuff running outside the kernel. I'd also be in favor of dropping I'd suggest |
@silverwind Agree. To improve further, what about suggesting the actual code: util.isNull(arg) // "util.isNull is deprecated, use `arg === null` instead."
util.isBoolean(arg) // "util.isBoolean is deprecated, use `typeof arg === 'boolean'` instead" |
@feross What about |
@Fishrock123 ... is this still something that should land before v6 is cut? |
I'm a little confused about the deprecations, it seems like with some of the |
I have to say, the checks that have been moved to C++ are likely helpful to userland. When we originally called to deprecate them, they were still done in JS. Perhaps we should reconsider at least those ones. I still don't see a need for something like |
It already exists in userland though https://github.com/evanlucas/v8is |
It already exists in core too. And people are already using it. Just my opinion though. |
@evanlucas IMHO any time you can avoid having to do compilation the better. I would like to see the methods that can reliably check the type at the C++ layer get undeprecated, with a possible explanation in the docs as to why they exist and/or were undeprecated. |
Yea, both of you make fair points. It would be nice to have those without a compile... |
Right, so this existed at a time when we were not doing c++ checks... I think we should keep at least the ones only able to be properly checked natively. I'm not sure about the others. Untagging from the milestone. If we are going to keep these we should then un-deprecate them in the docs. As a note, the combined |
This util module is for the core, unless the core needs them let's remove them. |
Grep for Note that this is partial, as it doesn't include |
moving to #6235 |
Extension of #743 / #822 / #1295
Deprecates any util.is* function that are not used in core.
Also adds some cleanup for in-util deprecations.
WIP and pending much discussion I'm sure. Might as well just add other util deprecations here also.
cc @iojs/tc - @iojs/collaborators - @ceejbot - (everyone really..)