-
-
Notifications
You must be signed in to change notification settings - Fork 405
Description
I've been thinking a lot this week about the existence utils in @ember/utils (e.g. isEmpty, isBlank, isPresent, isNone), and I'm thinking it might be a good idea to deprecate them. There's a lot of confusion around what they do, and as a result any implementation that uses them is tied heavily to specific behavior that is non-intuitive and adds unnecessary cognitive load for developers trying to understand code using these utils. Additionally, libraries like lodash already have methods like isEmpty, isObject, isObjectLike, isNull, and isUndefined that cover a similar surface area, and we could add to a project like that if there was a specific utility we find somewhat valuable to keep as a community.
A few colleagues I spoke with about this already had some thoughts which I'm including in full below:
isEmpty({})returning false is non-intuitive (and IMO wrong). An “empty” object would be one that has no entries like an “empty” array has no elements or an “empty” string has no characters.- using
isEmptyorisBlankshould be sugar for checking things likestr === undefined || str === null || str === '', but where that fails is that javascript is not statically typed. Exported functions can be called in any context, so they have to account for all different types and their definitions of empty/blank/etc. Other languages don’t have these problems becauseString.isEmptyis different thanArray.isEmptyand callingString.isEmpty([])is a compiler error. - In general I think I’d avoid using the ember existence utilities since you have to know what they do and know what you are doing and the person coming after you needs that same knowledge. just doing
thing && Object.keys(thing).length >0or something similar is immediately “grokable” even by someone without ember experience. although slightly more verbose, I feel using the ember utils are always more confusing than just using vanilla as much as possible.
A few questions for people to ponder and respond to:
- Do you use these utils heavily, or have you moved away from them?
- What value, if any, do you see these utils having over using vanilla JS checks?
- What issues, if any, have you seen arise from using these utils?
- What barriers do you foresee in deprecating these utils? How heavily are they used in Ember internal code?