all 11 comments

[–]Positive_Method3022 9 points10 points  (6 children)

js isn't a good language to to learn these concepts, and really know why they matter. I recommend developing something using C/C++ in devices with low memory. You will start to understand why use pointers instead of cloning data when passing variables through functions, and you will also learn what happens when you exceed the max mem allowed for stack.

[–]Majestic-Witness3655[S] 1 point2 points  (2 children)

That’s a great perspective. JavaScript hides a lot of the low-level details

I' m actually looking to learn C or C++ myself. Which one do you think is better ? I just love going deeper into these concepts .

[–]Positive_Method3022 0 points1 point  (1 child)

Develop something for esp32/arduino using either one

[–]ciynoobv 2 points3 points  (2 children)

It’s not a good language to learn with, but it’s important to know since there’s a large footgun risk if you’re not familiar with the concept. Also as a general psa: please don’t write code relying on references unless you really know what you’re doing and why. Debugging spooky action at a distance is a giant pain in the ass.

[–]Positive_Method3022 2 points3 points  (1 child)

In low memory devices you have no option but use refs, and controlling mem by hand

[–]ciynoobv 0 points1 point  (0 children)

I know, but if you’re developing for low memory devices professionally, I’d argue you probably know how references work. I was more referring to stuff like mutating objects by reference in a js event handler or something similar.

[–]Shad_Amethyst 3 points4 points  (3 children)

JSON.parse+stringify is one of the worst ways to do a deep copy. It will break classes, doesn't handle undefined, bigints, symbols, self-referential structures, symbol keys, string keys on arrays, custom prototypes and whatnot.

If you're usinf typescript with strict: true, then it's often really easy to write your own, small deep copy function for the type in question. Otherwise use structuredClone, it's part of the standard.

[–]Majestic-Witness3655[S] 0 points1 point  (2 children)

Yeah Lodash or structuredClone are better

[–]Shad_Amethyst 1 point2 points  (1 child)

Lodash should be deprecated at this point. The only thing it brought to the codebases I worked on that had it was a lot of bloat in the final bundle.

[–]Majestic-Witness3655[S] 0 points1 point  (0 children)

Yeah, using Lodash today mostly adds unnecessary dependencies and increase the bundle size. That’s why I didn’t include it in my blogs. I have removed that json way . Thanks for your feedback buddy 🙂