microdiff icon indicating copy to clipboard operation
microdiff copied to clipboard

Guard functions

Open LyubomirT opened this issue 1 year ago • 2 comments

Implemented type guards to improve readability and type safety in the diff function. Specifically, added helper functions isObject, isArray, and isRichType to encapsulate type checks. It pretty much fixes redundancy and improves clarity, feel free to make any changes if needed. I hope this helps!

LyubomirT avatar Jun 18 '24 15:06 LyubomirT

Thanks! I can see some of the benefits, but I am not sure if this is necessary given the increased code size, performance cost, and complexity brought by it, especially for isArray, as that is essentially just an alias for Array.isArray. However, I am still open to this if you have any other thoughts.

AsyncBanana avatar Jun 20 '24 01:06 AsyncBanana

I understand the code size concern, guess it really is a problem in this situation. isArray indeed can be removed to conserve space.

As for the main concept, I just thought that it's a good idea to create simple, reusable functions for guard checks (mostly for cases where the same things need to be put in multiple places).

However, if the performance/size cost is too high, then the PR probably should be closed.

LyubomirT avatar Jun 20 '24 06:06 LyubomirT

I am closing this for the aforementioned reasons

AsyncBanana avatar Nov 28 '24 13:11 AsyncBanana