Years of muscle memory have made it hard to not use Objects all the time, so this was a helpful illustration of why I should use Map and Set more often. Thanks CJ.
One of the unfortunate things about the Set implementation in JS is that it can only match primitives and memory addresses to compute equality. So even if you have two objects with the exact same fields and values, they will still not be equal because each has a non-unique memory address. Just something to be aware of if you're coming from a language like Java where you can override the 'equals' method on any object to govern how equality is computed.
I recently tried to use sets and maps in one of my react projects, it was working just fine when i used those as local states in a react component. But later on due to increase in code complexity i moved the state to redux, it all of a sudden stopped working, that's when i got to know the serialization issue, and have seen some issues mentioned on react-redux github repo, where they mentioned not to use Set and Maps as states. Could you comment on that, like why it is not a good idea to use Set and Maps as state, and why haven't redux figured out a way to handle Set and Map data structures.
Hot take: The "problems" with using objects are not real problems and they never come up in real life scenarios so it's not worth sacrifising the nice syntax of object for the verbosity of using Map.
Listen to Syntax episode 689: syntax.fm/show/689/you-should-be-using-javascript-maps-and-sets
Are you using Maps and Sets in your code? Let us know! 👇
Years of muscle memory have made it hard to not use Objects all the time, so this was a helpful illustration of why I should use Map and Set more often. Thanks CJ.
precisely my thoughts
Must be daunting to join Syntax after such a long time of just Scot & Wes... you're doing a great job, CJ!
Thank you 🙏 - It's a big role to fill but the team is super collaborative, encouraging and allowing me to do some of my best work.
One of the unfortunate things about the Set implementation in JS is that it can only match primitives and memory addresses to compute equality. So even if you have two objects with the exact same fields and values, they will still not be equal because each has a non-unique memory address. Just something to be aware of if you're coming from a language like Java where you can override the 'equals' method on any object to govern how equality is computed.
Great vid, CJ! Welcome to The Syntax team! My literal 3 favorite devs now in one place! Couldn't ask for any meter trio!
This was awesome! Loving the deep dive and hoping for more videos like it
More coming 🔜
Hey CJ, please make a video on using different design patterns in JavaScript and where to use them 😊
This is a good topic! I'll put it on the list.
Great video CJ!
Node 22.x has great new utilities for Set. That version is LTS so no reason not to upgrade.
Yesss! This is what we want 🎉🎉
😄
It would be interesting to know scenarios where set/map doesn't actually make sense and objects might be better.
I recently tried to use sets and maps in one of my react projects, it was working just fine when i used those as local states in a react component. But later on due to increase in code complexity i moved the state to redux, it all of a sudden stopped working, that's when i got to know the serialization issue, and have seen some issues mentioned on react-redux github repo, where they mentioned not to use Set and Maps as states.
Could you comment on that, like why it is not a good idea to use Set and Maps as state, and why haven't redux figured out a way to handle Set and Map data structures.
Thank you for this video! Would you mind sharing how you're displaying logs and return values inline in your code editor please?
Quokka.js maybe?
Using quokka.js there is also an extension called TypeScript worksheet that I haven't tried yet.
CJ ❤
👍 CJ
Any of you guys know what extension is that that shows the result in the side?
It is called Quokkajs - quokkajs.com/
May I know what plugin does that automatic logging on the end of your `console.log()`? Thanks
It is called quokka.js
There is also a plugin called TypeScript Worksheet that is similar, but I have not tried it.
May I know what color theme you have on vs code?
You can see the theme I use here: github.com/codinggarden/vscode-settings?tab=readme-ov-file#themescolor
-CJ
@@syntaxfm ☺️thank you very much
Hot take: The "problems" with using objects are not real problems and they never come up in real life scenarios so it's not worth sacrifising the nice syntax of object for the verbosity of using Map.
It's one of those "use it when you have those problems " kinda thing. Not that they should replace objects in your day to day.
js is so quirky, it’s insane
the lesson is, use typescript